From a14ca16f1860ca2a24d6360864215fa5449bc52f Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Tue, 27 Jan 2026 14:10:19 +0100 Subject: [PATCH 1/5] add old docker folder --- docker-compose.yml | 86 ++++++++++++++++++++++++++++++++++++ docker/backup/Dockerfile | 14 ++++++ docker/backup/backup_db.sh | 15 +++++++ docker/backup/entrypoint2.sh | 2 + docker/nginx/default.conf | 20 +++++++++ docker/php/Dockerfile | 15 +++++++ entrypoint.sh | 17 +++++++ 7 files changed, 169 insertions(+) create mode 100644 docker-compose.yml create mode 100644 docker/backup/Dockerfile create mode 100755 docker/backup/backup_db.sh create mode 100755 docker/backup/entrypoint2.sh create mode 100644 docker/nginx/default.conf create mode 100644 docker/php/Dockerfile create mode 100644 entrypoint.sh diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0d6ea45 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,86 @@ +version: "3.8" + +services: + php: + build: + context: docker + dockerfile: docker/php/Dockerfile + container_name: app-php + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: + - ../:/var/www/app + environment: + - GIT_TOKEN=${GIT_TOKEN} + - GIT_REPO=${GIT_REPO} + depends_on: + - mariadb + + + nginx: + image: nginx + container_name: app-nginx + volumes: + - ../:/var/www/app + - ./nginx/default.conf:/etc/nginx/conf.d/default.conf + ports: + - "80:80" + depends_on: + - php + + mariadb: + image: mariadb:latest + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: laravel + ports: + - "3306:3306" + volumes: + - dbdata:/var/lib/mysql + + + typesense: + image: typesense/typesense:29.0 + restart: on-failure + ports: + - "8108:8108" + volumes: + - typesense-data:/data + command: '--data-dir /data --api-key=xyz --enable-cors' + + backup: + build: + context: docker + dockerfile: docker/backup/Dockerfile + container_name: app-backup + volumes: + - ./backups:/backups + depends_on: + - mariadb + restart: unless-stopped + + reverb: + build: + context: docker + dockerfile: docker/php/Dockerfile + container_name: app-reverb + entrypoint: /usr/local/bin/entrypoint.sh + command: php artisan reverb:start --host=0.0.0.0 --port=8080 + volumes: + - ../:/var/www/app + ports: + - "8080:8080" + depends_on: + - php + - mariadb + + +volumes: + dbdata: + typesense-data: + +networks: + default: + ipam: + config: + - subnet: 192.168.200.0/24 diff --git a/docker/backup/Dockerfile b/docker/backup/Dockerfile new file mode 100644 index 0000000..85c300c --- /dev/null +++ b/docker/backup/Dockerfile @@ -0,0 +1,14 @@ +FROM alpine:latest + +RUN apk add --no-cache mariadb-client bash dcron + +RUN mkdir -p /backups +RUN mkdir -p /etc/periodic/15min + +COPY backup/backup_db.sh /etc/periodic/15min/backup_db +COPY backup/entrypoint2.sh /entrypoint.sh + +RUN chmod +x /etc/periodic/15min/backup_db +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/backup/backup_db.sh b/docker/backup/backup_db.sh new file mode 100755 index 0000000..8536db9 --- /dev/null +++ b/docker/backup/backup_db.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +DB_USER="root" +DB_PASS="root" +DB_NAME="laravel" +BACKUP_DIR="/backups" + +mkdir -p "$BACKUP_DIR" + +DAY=$(date +%d) +FILE="$BACKUP_DIR/$DAY.sql" + +mysqldump -h mariadb -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" > "$FILE" + +echo "[$(date)] Backup $DB_NAME sauvegardé dans $FILE" >> "$BACKUP_DIR/backup.log" \ No newline at end of file diff --git a/docker/backup/entrypoint2.sh b/docker/backup/entrypoint2.sh new file mode 100755 index 0000000..fa52e5b --- /dev/null +++ b/docker/backup/entrypoint2.sh @@ -0,0 +1,2 @@ +#!/bin/sh +crond -f -l 2 diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf new file mode 100644 index 0000000..a63bf51 --- /dev/null +++ b/docker/nginx/default.conf @@ -0,0 +1,20 @@ +server { + listen 80; + server_name 127.0.0.1; + + root /var/www/app/public; + index index.php index.html; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + include fastcgi_params; + fastcgi_pass php:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SERVER_NAME 127.0.0.1; + fastcgi_param HTTPS off; + } +} diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile new file mode 100644 index 0000000..2ad886d --- /dev/null +++ b/docker/php/Dockerfile @@ -0,0 +1,15 @@ +FROM php:8.4-fpm + +RUN apt-get update && apt-get install -y \ + git unzip libzip-dev libpng-dev libonig-dev \ + && docker-php-ext-install pdo_mysql zip pcntl + +COPY --from=composer:2 /usr/bin/composer /usr/bin/composer + +COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +WORKDIR /var/www/app + +ENTRYPOINT ["entrypoint.sh"] +CMD ["php-fpm"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..ef82b90 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/sh +set -e + +APP_DIR=/var/www/app +cd $APP_DIR + +git config --global --add safe.directory $APP_DIR || true + +if [ ! -d "vendor" ]; then + composer install --no-interaction --prefer-dist +fi + +mkdir -p storage bootstrap/cache +chown -R www-data:www-data storage bootstrap/cache +chmod -R 775 storage bootstrap/cache + +exec "$@" From 14e8aa80a99f7f015adf2d142b2cdd9ce0392f5a Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Tue, 27 Jan 2026 14:33:04 +0100 Subject: [PATCH 2/5] change software architecture --- .env.example | 4 + .gitignore | 3 +- README.md | 95 +------------------ docker-compose.yml | 11 ++- docker/backup/Dockerfile | 2 +- .../backup/{entrypoint2.sh => entrypoint.sh} | 0 docker/php/entrypoint.sh | 23 +++++ entrypoint.sh | 17 ---- 8 files changed, 39 insertions(+), 116 deletions(-) create mode 100644 .env.example rename docker/backup/{entrypoint2.sh => entrypoint.sh} (100%) create mode 100644 docker/php/entrypoint.sh delete mode 100644 entrypoint.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..908f69a --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +GIT_REPO= +GIT_TOKEN= +GIT_BRANCH= +TYPESENSE_API_KEY= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 723ef36..3bf780b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea \ No newline at end of file +.idea +.env \ No newline at end of file diff --git a/README.md b/README.md index d23b294..7d73a99 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,2 @@ -# Docker - - - -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -* [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -* [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://iutbg-gitlab.iutbourg.univ-lyon1.fr/sae-but2/2025-26/gestion-benevoles-association/docker.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -* [Set up project integrations](https://iutbg-gitlab.iutbourg.univ-lyon1.fr/sae-but2/2025-26/gestion-benevoles-association/docker/-/settings/integrations) - -## Collaborate with your team - -* [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -* [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -* [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -* [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -* [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -* [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/) -* [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -* [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -* [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -* [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +Aller chercher/générer son token sur gitlab : +Préférences/User settings/Personal access tokens diff --git a/docker-compose.yml b/docker-compose.yml index 0d6ea45..61e70c4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: extra_hosts: - "host.docker.internal:host-gateway" volumes: - - ../:/var/www/app + - app-code:/var/www/app environment: - GIT_TOKEN=${GIT_TOKEN} - GIT_REPO=${GIT_REPO} @@ -21,7 +21,7 @@ services: image: nginx container_name: app-nginx volumes: - - ../:/var/www/app + - app-code:/var/www/app - ./nginx/default.conf:/etc/nginx/conf.d/default.conf ports: - "80:80" @@ -46,7 +46,9 @@ services: - "8108:8108" volumes: - typesense-data:/data - command: '--data-dir /data --api-key=xyz --enable-cors' + environment: + - TYPESENSE_API_KEY=${TYPESENSE_API_KEY} + command: '--data-dir /data --api-key=${TYPESENSE_API_KEY} --enable-cors' backup: build: @@ -67,7 +69,7 @@ services: entrypoint: /usr/local/bin/entrypoint.sh command: php artisan reverb:start --host=0.0.0.0 --port=8080 volumes: - - ../:/var/www/app + - app-code:/var/www/app ports: - "8080:8080" depends_on: @@ -76,6 +78,7 @@ services: volumes: + app-code: dbdata: typesense-data: diff --git a/docker/backup/Dockerfile b/docker/backup/Dockerfile index 85c300c..6be7fb2 100644 --- a/docker/backup/Dockerfile +++ b/docker/backup/Dockerfile @@ -6,7 +6,7 @@ RUN mkdir -p /backups RUN mkdir -p /etc/periodic/15min COPY backup/backup_db.sh /etc/periodic/15min/backup_db -COPY backup/entrypoint2.sh /entrypoint.sh +COPY backup/entrypoint.sh /entrypoint.sh RUN chmod +x /etc/periodic/15min/backup_db RUN chmod +x /entrypoint.sh diff --git a/docker/backup/entrypoint2.sh b/docker/backup/entrypoint.sh similarity index 100% rename from docker/backup/entrypoint2.sh rename to docker/backup/entrypoint.sh diff --git a/docker/php/entrypoint.sh b/docker/php/entrypoint.sh new file mode 100644 index 0000000..4547005 --- /dev/null +++ b/docker/php/entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/sh +set -e + +APP_DIR=/var/www/app + +if [ ! -d "$APP_DIR/.git" ]; then + git clone -b "${GIT_BRANCH:-main}" "$GIT_REPO" "$APP_DIR" +else + cd "$APP_DIR" + git pull origin "${GIT_BRANCH:-main}" +fi + +cd "$APP_DIR" + +if [ -f composer.json ]; then + composer install --no-interaction --prefer-dist --optimize-autoloader +fi + +if [ -d storage ] && [ -d bootstrap/cache ]; then + chown -R www-data:www-data storage bootstrap/cache +fi + +exec "$@" diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index ef82b90..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -set -e - -APP_DIR=/var/www/app -cd $APP_DIR - -git config --global --add safe.directory $APP_DIR || true - -if [ ! -d "vendor" ]; then - composer install --no-interaction --prefer-dist -fi - -mkdir -p storage bootstrap/cache -chown -R www-data:www-data storage bootstrap/cache -chmod -R 775 storage bootstrap/cache - -exec "$@" From 6d45c131c70df15bd60763c325ec3926d1a9d6dc Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Tue, 27 Jan 2026 15:52:56 +0100 Subject: [PATCH 3/5] add a frontend container --- .env.example | 10 ++++++-- docker-compose.yml | 43 +++++++++++++++++++++++------------ docker/backup/Dockerfile | 4 ++-- docker/frontend/Dockerfile | 11 +++++++++ docker/frontend/entrypoint.sh | 34 +++++++++++++++++++++++++++ docker/php/Dockerfile | 2 +- docker/php/entrypoint.sh | 11 +++++++-- 7 files changed, 94 insertions(+), 21 deletions(-) create mode 100644 docker/frontend/Dockerfile create mode 100644 docker/frontend/entrypoint.sh diff --git a/.env.example b/.env.example index 908f69a..931c944 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,10 @@ -GIT_REPO= +BACKEND_GIT_REPO= +FRONTEND_GIT_REPO= +BACKEND_GIT_BRANCH= +FRONTEND_GIT_BRANCH= GIT_TOKEN= -GIT_BRANCH= + +MYSQL_ROOT_PASSWORD= +MYSQL_DATABASE= + TYPESENSE_API_KEY= \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 61e70c4..39fa2be 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,28 +1,43 @@ -version: "3.8" - services: php: build: - context: docker - dockerfile: docker/php/Dockerfile + context: ./docker/php + dockerfile: Dockerfile container_name: app-php extra_hosts: - "host.docker.internal:host-gateway" volumes: - app-code:/var/www/app + - frontend-public:/var/www/app/public environment: - GIT_TOKEN=${GIT_TOKEN} - - GIT_REPO=${GIT_REPO} + - BACKEND_GIT_REPO=${BACKEND_GIT_REPO} + - BACKEND_GIT_BRANCH=${BACKEND_GIT_BRANCH} depends_on: - mariadb + frontend: + build: + context: ./docker/frontend + dockerfile: Dockerfile + container_name: app-frontend + environment: + - GIT_TOKEN=${GIT_TOKEN} + - FRONTEND_GIT_REPO=${FRONTEND_GIT_REPO} + - FRONTEND_GIT_BRANCH=${FRONTEND_GIT_BRANCH} + volumes: + - frontend-public:/public + depends_on: + - php + command: [ "build" ] + nginx: image: nginx container_name: app-nginx volumes: - app-code:/var/www/app - - ./nginx/default.conf:/etc/nginx/conf.d/default.conf + - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf ports: - "80:80" depends_on: @@ -31,14 +46,13 @@ services: mariadb: image: mariadb:latest environment: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: laravel + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} + - MYSQL_DATABASE=${MYSQL_DATABASE} ports: - "3306:3306" volumes: - dbdata:/var/lib/mysql - typesense: image: typesense/typesense:29.0 restart: on-failure @@ -52,8 +66,8 @@ services: backup: build: - context: docker - dockerfile: docker/backup/Dockerfile + context: ./docker/backup + dockerfile: Dockerfile container_name: app-backup volumes: - ./backups:/backups @@ -63,8 +77,8 @@ services: reverb: build: - context: docker - dockerfile: docker/php/Dockerfile + context: ./docker/php + dockerfile: Dockerfile container_name: app-reverb entrypoint: /usr/local/bin/entrypoint.sh command: php artisan reverb:start --host=0.0.0.0 --port=8080 @@ -79,6 +93,7 @@ services: volumes: app-code: + frontend-public: dbdata: typesense-data: @@ -86,4 +101,4 @@ networks: default: ipam: config: - - subnet: 192.168.200.0/24 + - subnet: 192.168.200.0/24 \ No newline at end of file diff --git a/docker/backup/Dockerfile b/docker/backup/Dockerfile index 6be7fb2..f1eb474 100644 --- a/docker/backup/Dockerfile +++ b/docker/backup/Dockerfile @@ -5,8 +5,8 @@ RUN apk add --no-cache mariadb-client bash dcron RUN mkdir -p /backups RUN mkdir -p /etc/periodic/15min -COPY backup/backup_db.sh /etc/periodic/15min/backup_db -COPY backup/entrypoint.sh /entrypoint.sh +COPY backup_db.sh /etc/periodic/15min/backup_db +COPY entrypoint.sh /entrypoint.sh RUN chmod +x /etc/periodic/15min/backup_db RUN chmod +x /entrypoint.sh diff --git a/docker/frontend/Dockerfile b/docker/frontend/Dockerfile new file mode 100644 index 0000000..94f40ac --- /dev/null +++ b/docker/frontend/Dockerfile @@ -0,0 +1,11 @@ +FROM node:20-alpine + +WORKDIR /app + +RUN apk add --no-cache git bash + +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +CMD ["build"] diff --git a/docker/frontend/entrypoint.sh b/docker/frontend/entrypoint.sh new file mode 100644 index 0000000..1c33033 --- /dev/null +++ b/docker/frontend/entrypoint.sh @@ -0,0 +1,34 @@ +#!/bin/sh +set -e + +FRONTEND_DIR=/app +PUBLIC_DIR=/public +APP_DIR=/var/www/app + +GIT_URL="https://${GIT_TOKEN}@${FRONTEND_GIT_REPO}" + + +while [ ! -f "$APP_DIR/composer.json" ]; do + sleep 2 +done + + +if [ ! -d "$FRONTEND_DIR/.git" ]; then + git clone -b "${FRONTEND_GIT_BRANCH:-main}" "$GIT_URL" "$FRONTEND_DIR" +else + cd "$FRONTEND_DIR" + git pull "$GIT_URL" "${FRONTEND_GIT_BRANCH:-main}" +fi + +cd "$FRONTEND_DIR" + +if [ -f package.json ]; then + npm ci +fi + +npm run build + +rm -rf "$PUBLIC_DIR/*" +cp -r dist/* "$PUBLIC_DIR/" + +exec "$@" diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 2ad886d..8e52f19 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -6,7 +6,7 @@ RUN apt-get update && apt-get install -y \ COPY --from=composer:2 /usr/bin/composer /usr/bin/composer -COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh +COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh WORKDIR /var/www/app diff --git a/docker/php/entrypoint.sh b/docker/php/entrypoint.sh index 4547005..31dce9d 100644 --- a/docker/php/entrypoint.sh +++ b/docker/php/entrypoint.sh @@ -2,12 +2,13 @@ set -e APP_DIR=/var/www/app +GIT_URL="https://${GIT_TOKEN}@${BACKEND_GIT_REPO}" if [ ! -d "$APP_DIR/.git" ]; then - git clone -b "${GIT_BRANCH:-main}" "$GIT_REPO" "$APP_DIR" + GIT_URL="https://${GIT_TOKEN}@${BACKEND_GIT_REPO}" else cd "$APP_DIR" - git pull origin "${GIT_BRANCH:-main}" + git pull "$GIT_URL" "${BACKEND_GIT_BRANCH:-main}" fi cd "$APP_DIR" @@ -20,4 +21,10 @@ if [ -d storage ] && [ -d bootstrap/cache ]; then chown -R www-data:www-data storage bootstrap/cache fi +if [ -f .env ]; then + php artisan key:generate --no-interaction +fi + +php artisan migrate --force + exec "$@" From 7d2af43af486beb3f96d01244d329ea42a005f52 Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Wed, 28 Jan 2026 15:16:07 +0100 Subject: [PATCH 4/5] functional docker project --- .gitignore | 3 +- docker-compose.yml | 60 ++++++++++++++++++++++------------- docker/backup/Dockerfile | 4 +-- docker/backup/backup_db.sh | 10 ++++-- docker/frontend/entrypoint.sh | 29 +++++++++++------ docker/php/Dockerfile | 4 +-- docker/php/entrypoint.sh | 25 +++++++++------ 7 files changed, 86 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index 3bf780b..fecc461 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -.env \ No newline at end of file +.env +backups/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 39fa2be..7f689a5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,16 @@ services: + mariadb: + image: mariadb:latest + container_name: app-mariadb + environment: + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} + - MYSQL_DATABASE=${MYSQL_DATABASE} + ports: + - "3306:3306" + volumes: + - dbdata:/var/lib/mysql + restart: unless-stopped + php: build: context: ./docker/php @@ -8,13 +20,19 @@ services: - "host.docker.internal:host-gateway" volumes: - app-code:/var/www/app - - frontend-public:/var/www/app/public environment: - GIT_TOKEN=${GIT_TOKEN} - BACKEND_GIT_REPO=${BACKEND_GIT_REPO} - BACKEND_GIT_BRANCH=${BACKEND_GIT_BRANCH} depends_on: - mariadb + restart: unless-stopped + healthcheck: + test: [ "CMD-SHELL", "test -d /var/www/app/vendor && pidof php-fpm || exit 1" ] + interval: 5s + timeout: 3s + retries: 20 + start_period: 120s frontend: build: @@ -26,14 +44,13 @@ services: - FRONTEND_GIT_REPO=${FRONTEND_GIT_REPO} - FRONTEND_GIT_BRANCH=${FRONTEND_GIT_BRANCH} volumes: - - frontend-public:/public + - app-code:/var/www/app depends_on: - php - command: [ "build" ] - + restart: "no" nginx: - image: nginx + image: nginx:alpine container_name: app-nginx volumes: - app-code:/var/www/app @@ -41,21 +58,16 @@ services: ports: - "80:80" depends_on: - - php - - mariadb: - image: mariadb:latest - environment: - - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} - - MYSQL_DATABASE=${MYSQL_DATABASE} - ports: - - "3306:3306" - volumes: - - dbdata:/var/lib/mysql + php: + condition: service_healthy + frontend: + condition: service_completed_successfully + restart: unless-stopped typesense: image: typesense/typesense:29.0 - restart: on-failure + container_name: app-typesense + restart: unless-stopped ports: - "8108:8108" volumes: @@ -69,10 +81,11 @@ services: context: ./docker/backup dockerfile: Dockerfile container_name: app-backup + environment: + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} + - MYSQL_DATABASE=${MYSQL_DATABASE} volumes: - ./backups:/backups - depends_on: - - mariadb restart: unless-stopped reverb: @@ -80,7 +93,11 @@ services: context: ./docker/php dockerfile: Dockerfile container_name: app-reverb - entrypoint: /usr/local/bin/entrypoint.sh + environment: + - GIT_TOKEN=${GIT_TOKEN} + - BACKEND_GIT_REPO=${BACKEND_GIT_REPO} + - BACKEND_GIT_BRANCH=${BACKEND_GIT_BRANCH} + entrypoint: [] command: php artisan reverb:start --host=0.0.0.0 --port=8080 volumes: - app-code:/var/www/app @@ -89,11 +106,10 @@ services: depends_on: - php - mariadb - + restart: unless-stopped volumes: app-code: - frontend-public: dbdata: typesense-data: diff --git a/docker/backup/Dockerfile b/docker/backup/Dockerfile index f1eb474..3567702 100644 --- a/docker/backup/Dockerfile +++ b/docker/backup/Dockerfile @@ -5,10 +5,10 @@ RUN apk add --no-cache mariadb-client bash dcron RUN mkdir -p /backups RUN mkdir -p /etc/periodic/15min -COPY backup_db.sh /etc/periodic/15min/backup_db +COPY backup_db.sh /etc/periodic/daily/backup_db COPY entrypoint.sh /entrypoint.sh -RUN chmod +x /etc/periodic/15min/backup_db +RUN chmod +x /etc/periodic/daily/backup_db RUN chmod +x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker/backup/backup_db.sh b/docker/backup/backup_db.sh index 8536db9..793c35d 100755 --- a/docker/backup/backup_db.sh +++ b/docker/backup/backup_db.sh @@ -7,9 +7,13 @@ BACKUP_DIR="/backups" mkdir -p "$BACKUP_DIR" -DAY=$(date +%d) +DAY=$(date +%d) FILE="$BACKUP_DIR/$DAY.sql" -mysqldump -h mariadb -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" > "$FILE" +mysqldump -h mariadb -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" > "$FILE" 2>/dev/null -echo "[$(date)] Backup $DB_NAME sauvegardé dans $FILE" >> "$BACKUP_DIR/backup.log" \ No newline at end of file +if [ $? -eq 0 ]; then + echo "[$(date)] Backup $DB_NAME sauvegardé dans $FILE" >> "$BACKUP_DIR/backup.log" +else + echo "[$(date)] ERREUR lors du backup de $DB_NAME" >> "$BACKUP_DIR/backup.log" +fi \ No newline at end of file diff --git a/docker/frontend/entrypoint.sh b/docker/frontend/entrypoint.sh index 1c33033..1efd768 100644 --- a/docker/frontend/entrypoint.sh +++ b/docker/frontend/entrypoint.sh @@ -2,14 +2,18 @@ set -e FRONTEND_DIR=/app -PUBLIC_DIR=/public APP_DIR=/var/www/app +PUBLIC_DIR="$APP_DIR/public" +GIT_URL="https://oauth2:${GIT_TOKEN}@${FRONTEND_GIT_REPO}" -GIT_URL="https://${GIT_TOKEN}@${FRONTEND_GIT_REPO}" - - -while [ ! -f "$APP_DIR/composer.json" ]; do - sleep 2 +MAX_WAIT=300 +WAITED=0 +while [ ! -f "$APP_DIR/composer.json" ] || [ ! -d "$APP_DIR/vendor" ] || [ ! -d "$APP_DIR/public" ]; do + if [ $WAITED -ge $MAX_WAIT ]; then + exit 1 + fi + sleep 3 + WAITED=$((WAITED + 3)) done @@ -17,18 +21,23 @@ if [ ! -d "$FRONTEND_DIR/.git" ]; then git clone -b "${FRONTEND_GIT_BRANCH:-main}" "$GIT_URL" "$FRONTEND_DIR" else cd "$FRONTEND_DIR" - git pull "$GIT_URL" "${FRONTEND_GIT_BRANCH:-main}" + git fetch origin + git reset --hard origin/"${FRONTEND_GIT_BRANCH:-main}" fi cd "$FRONTEND_DIR" if [ -f package.json ]; then - npm ci + npm ci --prefer-offline --no-audit fi npm run build -rm -rf "$PUBLIC_DIR/*" +if [ ! -d "dist" ]; then + exit 1 +fi + +find "$PUBLIC_DIR" -mindepth 1 ! -name '.gitkeep' ! -name 'index.php' ! -name '.htaccess' -delete cp -r dist/* "$PUBLIC_DIR/" -exec "$@" +exit 0 \ No newline at end of file diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 8e52f19..9d8f13a 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -11,5 +11,5 @@ RUN chmod +x /usr/local/bin/entrypoint.sh WORKDIR /var/www/app -ENTRYPOINT ["entrypoint.sh"] -CMD ["php-fpm"] +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +CMD ["php-fpm"] \ No newline at end of file diff --git a/docker/php/entrypoint.sh b/docker/php/entrypoint.sh index 31dce9d..eb3c64c 100644 --- a/docker/php/entrypoint.sh +++ b/docker/php/entrypoint.sh @@ -2,29 +2,36 @@ set -e APP_DIR=/var/www/app -GIT_URL="https://${GIT_TOKEN}@${BACKEND_GIT_REPO}" +GIT_URL="https://oauth2:${GIT_TOKEN}@${BACKEND_GIT_REPO}" if [ ! -d "$APP_DIR/.git" ]; then - GIT_URL="https://${GIT_TOKEN}@${BACKEND_GIT_REPO}" + git clone -b "${BACKEND_GIT_BRANCH:-main}" "$GIT_URL" "$APP_DIR" else cd "$APP_DIR" - git pull "$GIT_URL" "${BACKEND_GIT_BRANCH:-main}" + git fetch origin + git reset --hard origin/"${BACKEND_GIT_BRANCH:-main}" fi cd "$APP_DIR" if [ -f composer.json ]; then - composer install --no-interaction --prefer-dist --optimize-autoloader + composer update --no-interaction --prefer-dist --optimize-autoloader fi -if [ -d storage ] && [ -d bootstrap/cache ]; then - chown -R www-data:www-data storage bootstrap/cache +if [ ! -f .env ] && [ -f .env.example ]; then + cp .env.example .env fi -if [ -f .env ]; then - php artisan key:generate --no-interaction +if [ -f artisan ]; then + if ! grep -q "APP_KEY=base64:" .env 2>/dev/null; then + php artisan key:generate --ansi --force + fi fi php artisan migrate --force -exec "$@" +chown -R www-data:www-data storage bootstrap/cache public +chmod -R 775 storage bootstrap/cache +chmod -R 755 public + +exec "$@" \ No newline at end of file From 488fcd273b5442d042be296d3dc91864d2d49579 Mon Sep 17 00:00:00 2001 From: Giovanni-Josserand Date: Thu, 29 Jan 2026 20:09:16 +0100 Subject: [PATCH 5/5] add .env.example to frontend and php container and update README.md --- README.md | 21 +++++++++- docker-compose.yml | 5 ++- docker/backup/Dockerfile | 2 +- docker/frontend/.env.example | 11 +++++ docker/frontend/entrypoint.sh | 12 ++---- docker/php/.env.example | 79 +++++++++++++++++++++++++++++++++++ docker/php/entrypoint.sh | 15 +++---- 7 files changed, 124 insertions(+), 21 deletions(-) create mode 100644 docker/frontend/.env.example create mode 100644 docker/php/.env.example diff --git a/README.md b/README.md index 7d73a99..128b7c0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,19 @@ -Aller chercher/générer son token sur gitlab : -Préférences/User settings/Personal access tokens +# Gestion des bénévoles d'une association + +## Initialisation + +Afin d'initialiser le projet il est requis de : +- Créer un fichier ``.env`` à la racine +- Copier coller le contenu du fichier ``.env.example`` +- Remplir les variables du fichier .env +- Pour la variable ``GIT_TOKEN`` il est nécessaire de chercher/générer son token sur gitlab dans l'onglet : ``Préférences/User settings/Personal access tokens`` +- Répéter l'opération pour le ``docker/php/.env`` et le ``docker/frontend/.env`` + +## Installation +Il suffit ensuite d'ouvrir un terminal, de ce placer à la racine de ce projet et d'exécuter les commandes suivantes : +```bash +docker compose down -v +``` +```bash +docker compose up --build -d +``` diff --git a/docker-compose.yml b/docker-compose.yml index 7f689a5..589633d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,6 +20,7 @@ services: - "host.docker.internal:host-gateway" volumes: - app-code:/var/www/app + - ./docker/php/.env:/tmp/app.env:ro environment: - GIT_TOKEN=${GIT_TOKEN} - BACKEND_GIT_REPO=${BACKEND_GIT_REPO} @@ -45,8 +46,10 @@ services: - FRONTEND_GIT_BRANCH=${FRONTEND_GIT_BRANCH} volumes: - app-code:/var/www/app + - ./docker/frontend/.env:/tmp/app.env:ro depends_on: - - php + php: + condition: service_healthy restart: "no" nginx: diff --git a/docker/backup/Dockerfile b/docker/backup/Dockerfile index 3567702..8354443 100644 --- a/docker/backup/Dockerfile +++ b/docker/backup/Dockerfile @@ -3,7 +3,7 @@ FROM alpine:latest RUN apk add --no-cache mariadb-client bash dcron RUN mkdir -p /backups -RUN mkdir -p /etc/periodic/15min +RUN mkdir -p /etc/periodic/daily COPY backup_db.sh /etc/periodic/daily/backup_db COPY entrypoint.sh /entrypoint.sh diff --git a/docker/frontend/.env.example b/docker/frontend/.env.example new file mode 100644 index 0000000..8989751 --- /dev/null +++ b/docker/frontend/.env.example @@ -0,0 +1,11 @@ +VITE_API_URL= + +VITE_BROADCASTER=reverb +VITE_REVERB_KEY=local +VITE_REVERB_HOST=127.0.0.1 +VITE_REVERB_PORT=8080 +VITE_FORCE_TLS=false +VITE_DISABLE_STATS=true +VITE_ENCRYPTED=false +VITE_CLUSTER=mt1 +VITE_ENABLED_TRANSPORTS=['ws', 'wss'] \ No newline at end of file diff --git a/docker/frontend/entrypoint.sh b/docker/frontend/entrypoint.sh index 1efd768..8fc7a7b 100644 --- a/docker/frontend/entrypoint.sh +++ b/docker/frontend/entrypoint.sh @@ -27,17 +27,13 @@ fi cd "$FRONTEND_DIR" -if [ -f package.json ]; then - npm ci --prefer-offline --no-audit -fi +cp /tmp/app.env .env + +npm ci --prefer-offline --no-audit npm run build -if [ ! -d "dist" ]; then - exit 1 -fi - -find "$PUBLIC_DIR" -mindepth 1 ! -name '.gitkeep' ! -name 'index.php' ! -name '.htaccess' -delete +find "$PUBLIC_DIR" -mindepth 1 ! -name 'index.php' ! -name '.htaccess' -delete cp -r dist/* "$PUBLIC_DIR/" exit 0 \ No newline at end of file diff --git a/docker/php/.env.example b/docker/php/.env.example new file mode 100644 index 0000000..2a27d34 --- /dev/null +++ b/docker/php/.env.example @@ -0,0 +1,79 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY= +APP_DEBUG=true +APP_URL=http://localhost:8000 + +APP_LOCALE=en +APP_FALLBACK_LOCALE=en +APP_FAKER_LOCALE=en_US + +APP_MAINTENANCE_DRIVER=file +# APP_MAINTENANCE_STORE=database + +PHP_CLI_SERVER_WORKERS=4 + +BCRYPT_ROUNDS=12 + +LOG_CHANNEL=stack +LOG_STACK=single +LOG_DEPRECATIONS_CHANNEL=null +LOG_LEVEL=debug + +DB_CONNECTION=mysql +DB_HOST=mariadb +DB_PORT=3306 +DB_DATABASE=laravel +DB_USERNAME=root +DB_PASSWORD=root + +SESSION_DRIVER=database +SESSION_LIFETIME=120 +SESSION_ENCRYPT=false +SESSION_PATH=/ +SESSION_DOMAIN=localhost +SESSION_SECURE_COOKIE=false + +BROADCAST_CONNECTION=reverb +REVERB_APP_ID=local +REVERB_APP_KEY=local +REVERB_APP_SECRET=local +REVERB_HOST=reverb +REVERB_PORT=8080 +REVERB_SCHEME=http +PUSHER_APP_CLUSTER="mt1" + +CACHE_STORE=file +QUEUE_CONNECTION=sync + +FILESYSTEM_DISK=local +# CACHE_PREFIX= + +MEMCACHED_HOST=127.0.0.1 + +REDIS_CLIENT=phpredis +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=log +MAIL_SCHEME=null +MAIL_HOST=127.0.0.1 +MAIL_PORT=2525 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_FROM_ADDRESS="hello@example.com" +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= +AWS_USE_PATH_STYLE_ENDPOINT=false + +VITE_APP_NAME="${APP_NAME}" + +SANCTUM_STATEFUL_DOMAINS=localhost,127.0.0.1,localhost:8000 + +TYPESENSE_CONNECTION=typesense +TYPESENSE_API_KEY=xyz diff --git a/docker/php/entrypoint.sh b/docker/php/entrypoint.sh index eb3c64c..fc08e43 100644 --- a/docker/php/entrypoint.sh +++ b/docker/php/entrypoint.sh @@ -18,19 +18,16 @@ if [ -f composer.json ]; then composer update --no-interaction --prefer-dist --optimize-autoloader fi -if [ ! -f .env ] && [ -f .env.example ]; then - cp .env.example .env -fi +cp /tmp/app.env .env -if [ -f artisan ]; then - if ! grep -q "APP_KEY=base64:" .env 2>/dev/null; then - php artisan key:generate --ansi --force - fi -fi +php artisan key:generate --force + +php artisan config:clear +php artisan cache:clear php artisan migrate --force -chown -R www-data:www-data storage bootstrap/cache public +chown -R www-data:www-data public/ storage bootstrap/cache public vendor chmod -R 775 storage bootstrap/cache chmod -R 755 public