Skip to content

Resolve "adapter le code pour s'exécuter dans le docker compose"

Closes #2 (closed)

Tests

  1. Export data de la table events de production: docker compose exec mobilizon-db psql -U mobilizon -d postgres_mobilizon -c "COPY (SELECT * FROM events) TO stdout DELIMITER ',' CSV HEADER" > events-export.csv
  2. Export du schema docker compose exec mobilizon-db pg_dump -U mobilizon --schema-only postgres_mobilizon > schema.sql
  3. Import local avec un setup identique à la prod
for fichier in Dockerfile compose.yml crontab
do
echo "== $fichier ==" 
cat $fichier
done

== Dockerfile ==
FROM alpine:3.14
RUN apk add --no-cache postgresql-client
RUN apk add --no-cache bash
RUN apk add --no-cache curl
RUN apk add --no-cache jq
RUN apk add --no-cache tzdata
RUN apk add --no-cache coreutils


# Latest releases available at https://github.com/aptible/supercronic/releases
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.29/supercronic-linux-amd64 \
    SUPERCRONIC=supercronic-linux-amd64 \
    SUPERCRONIC_SHA1SUM=cd48d45c4b10f3f0bfdd3a57d054cd05ac96812b

RUN curl -fsSLO "$SUPERCRONIC_URL" \
 && echo "${SUPERCRONIC_SHA1SUM}  ${SUPERCRONIC}" | sha1sum -c - \
 && chmod +x "$SUPERCRONIC" \
 && mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
 && ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic

COPY ./crontab /crontab
COPY . /app
== compose.yml ==
# inspired from https://framagit.org/framasoft/joinmobilizon/docker/-/blob/f658b1224270e0a52c7174bec923d048ed9ab21f/docker-compose.yml

version: "3.7"

networks:
    mobilizon:
        name: "mobilizon"

volumes:
    mobilizon-db:
        name: mobilizon-db
    mobilizon-cron:
        name: mobilizon-cron

services:
    mobilizon-db:
        image: postgis/postgis:12-3.1-alpine
        container_name: mobilizon-db
        volumes:
            - mobilizon-db:/var/lib/postgresql/data
            - /etc/localtime:/etc/localtime:ro
        env_file:
            - ./secrets/mobilizon-db.secrets
        networks:
            - mobilizon
        restart: unless-stopped

    mobilizon-cron:
        build: .
        command: /usr/local/bin/supercronic /crontab
        container_name: mobilizon-cron
        environment:
            - MOBILIZON_DATABASE_HOST=mobilizon-db
        env_file:
            - ./secrets/mobilizon-db.secrets
            - ./secrets/mobilizon-cron.secrets
        networks:
            - mobilizon
        restart: unless-stopped
        volumes:
            - mobilizon-cron:/export-cron
            - /etc/localtime:/etc/localtime:ro
== crontab ==
# Run 10 seconds
*/10 * * * * * * cd /app && bash ./main.sh
Edited by Gregory Loncle

Merge request reports

Loading