diff --git a/.vscode/launch.json b/.vscode/launch.json index f18772ba75f5f25e46ecd92fd277e404fc600110..8add34982dc6870e6fe686dd0f8de91bb29a3468 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,28 +9,27 @@ "type": "go", "request": "launch", "mode": "debug", - "remotePath": "", - "port": 2345, - "host": "127.0.0.1", "program": "${workspaceFolder}/main.go", "env": { + "HOSTNAME": "localhost", + "ADMIN_ROLE" : "ADMINS", + "DEBUG_MODE": "true", + "MOCK_OAUTH2": "true", + "HTTPS_PORT": "1443", + "IMAGE_FOLDER": "image-lib", + "REDIRECT_URL": "http://localhost:1443/OAuth2Callback", "CLIENT_ID": "foo", "CLIENT_SECRET": "bar", "AUTH_URL": "http://localhost:8090/auth", "TOKEN_URL": "http://localhost:8090/token", "USERINFO_URL": "http://localhost:8090/admininfo", - "LOGOUT_URL": "/", - "HOSTNAME": "localhost", - "ADMIN_ROLE" : "ADMINS", - "INMEMORY_TOKEN_LIFE_DAYS": "2", - "DEBUG_MODE": "true", - "HTTPS_PORT": "1443", + "DATABASE_USER": "", "DATABASE_PASSWORD": "password", "DATABASE_NAME": "backoffice", "DATABASE_HOST": "127.0.0.1", - "MOCK_OAUTH2": "true" + "LOGOUT_URL": "/", }, "showLog": true }, @@ -39,9 +38,6 @@ "type": "go", "request": "launch", "mode": "debug", - "remotePath": "", - "port": 2345, - "host": "127.0.0.1", "program": "${workspaceFolder}/main.go", "env": { "REDIRECT_URL": "https://localhost:1443/OAuth2Callback", @@ -57,14 +53,6 @@ "HTTPS_PORT": "1443" }, "showLog": true - }, - { - "name": "Debug back office client", - "type": "firefox", - "request": "launch", - "reAttach": true, - "url": "https://ecolyobackoffice.127.0.0.1.nip.io:1443", - "webRoot": "${workspaceFolder}/web" } ] } diff --git a/backup-build/Dockerfile.db-backup b/backup-build/Dockerfile.db-backup new file mode 100644 index 0000000000000000000000000000000000000000..a478bbc3717418937f13ef1763b21166be5db862 --- /dev/null +++ b/backup-build/Dockerfile.db-backup @@ -0,0 +1,30 @@ +FROM alpine:3.14.0 + +RUN apk add apk-cron mysql-client findutils + +# Copy cron job file to the cron.d directory +COPY backup-cron-job /etc/cron.d/backup-cron-job + +# Give execution rights on the cron job +RUN chmod 0644 /etc/cron.d/backup-cron-job + +# Copy backup script +COPY backup.sh /etc/cron.d/backup.sh + +# Give execution rights on backup script +RUN chmod 0644 /etc/cron.d/backup.sh + +# Copy restore script +COPY restore.sh /etc/cron.d/restore.sh + +# Give execution rights on restore script +RUN chmod 0644 /etc/cron.d/restore.sh + +# Apply cron job +RUN crontab /etc/cron.d/backup-cron-job + +# Create the log file to be able to run tail +RUN touch /var/log/cron.log + +# Run the command on container startup +CMD crond && tail -f /var/log/cron.log \ No newline at end of file diff --git a/backup-build/backup-cron-job b/backup-build/backup-cron-job new file mode 100644 index 0000000000000000000000000000000000000000..35dace2d5e8d16239ad6e7277df1815b04e52903 --- /dev/null +++ b/backup-build/backup-cron-job @@ -0,0 +1,2 @@ +# Run the backup script every day at 12:00AM +0 0 * * * sh /etc/cron.d/backup.sh \ No newline at end of file diff --git a/backup-build/backup.sh b/backup-build/backup.sh new file mode 100644 index 0000000000000000000000000000000000000000..63d1904b16f8903f4a91a4736b05c9f9e025e39b --- /dev/null +++ b/backup-build/backup.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +DATE=$(date +"%Y-%m-%d-%H-%M-%S") +BACKUP_DIRECTORY="/backup" +DIRECTORIES_NAME_PATTERN='ecolyo-agent-20*' +NUMBER_TO_KEEP=14 +BACKUP="${BACKUP_DIRECTORY}/ecolyo-agent-${DATE}" + +# Create a new directory into backup directory location for this date +mkdir -p $BACKUP + +# Dumb the database +mysqldump --host=database-agent --port=3306 -u root -p$MYSQL_ROOT_PASSWORD $MYSQL_DATABASE >"$BACKUP/$MYSQL_DATABASE.sql" + +# Remove all but last n saves +find $BACKUP_DIR/* -maxdepth 1 -type d -name $DIRECTORIES_NAME_PATTERN -printf '%T@\t%p\n' | + sort -t $'\t' -g | + head -n -$NUMBER_TO_KEEP | + cut -d $'\t' -f 2- | + xargs rm -Rf diff --git a/backup-build/restore.sh b/backup-build/restore.sh new file mode 100644 index 0000000000000000000000000000000000000000..2e135e4a6fa9800d382af6838df462555acf464d --- /dev/null +++ b/backup-build/restore.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +BACKUP_DIR="/backup" + +mysql --host=database-agent --port=3306 -u root -p$MYSQL_ROOT_PASSWORD $MYSQL_DATABASE <"$BACKUP_DIR/$1/$MYSQL_DATABASE.sql" diff --git a/docker-compose.deploy.yml b/docker-compose.deploy.yml new file mode 100644 index 0000000000000000000000000000000000000000..52ad5b30dc8f96a6ce81910cf4350cd1085dae46 --- /dev/null +++ b/docker-compose.deploy.yml @@ -0,0 +1,72 @@ +version: '3.7' +services: + database-agent: + image: mysql:5 + networks: + backoffice: + restart: always + volumes: + - /mnt/local/data/ecolyo_agent_mysql_data:/var/lib/mysql + - ./dbinit:/dbinit + environment: + MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD} + MYSQL_DATABASE: ${DATABASE_NAME} + healthcheck: + test: mysqladmin ping -h 127.0.0.1 -u root --password=$$MYSQL_ROOT_PASSWORD + interval: 5s + timeout: 10s + retries: 60 + + database-backup: + image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server:db-backup + networks: + backoffice: + environment: + MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD} + MYSQL_DATABASE: ${DATABASE_NAME} + volumes: + - /mnt/local/data/backup:/backup + restart: unless-stopped + depends_on: + database-agent: + condition: service_healthy + + backend: + image: registry.forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server:dev + networks: + backoffice: + nginx-network: + depends_on: + database-agent: + condition: service_healthy + restart: unless-stopped + volumes: + - /etc/localtime:/etc/localtime:ro + - ./configs:/app/configs + - ./letsencrypt_cache:/app/letsencrypt_cache + - ./data:/app/data + - ./${IMAGE_FOLDER}:/app/${IMAGE_FOLDER} + expose: + - ${HTTPS_PORT} + environment: + - HOSTNAME=${HOSTNAME} + - HTTPS_PORT=${HTTPS_PORT} + - ADMIN_ROLE=${ADMIN_ROLE} + - REDIRECT_URL=${REDIRECT_URL} + - CLIENT_ID=${CLIENT_ID} + - CLIENT_SECRET=${CLIENT_SECRET} + - AUTH_URL=${AUTH_URL} + - IMAGE_FOLDER=${IMAGE_FOLDER} + - MOCK_OAUTH2=${MOCK_OAUTH2} + - TOKEN_URL=${TOKEN_URL} + - USERINFO_URL=${USERINFO_URL} + - DEBUG_MODE=${DEBUG_MODE} + - DATABASE_USER=${DATABASE_USER} + - DATABASE_NAME=${DATABASE_NAME} + - DATABASE_PASSWORD=${DATABASE_PASSWORD} + - DATABASE_HOST=database-agent + +networks: + backoffice: + nginx-network: + external: true \ No newline at end of file