From b0d0fac03b4c7569045cce4f825adc7ffd8f2770 Mon Sep 17 00:00:00 2001 From: nik2208 Date: Mon, 16 Dec 2024 14:37:59 +0100 Subject: [PATCH] 1.1.0 - parametric docker containers name (solves multiple php-crud-api-qs instances deploys) --- .env.sample | 6 +++++- README.md | 4 ++++ docker-compose.yml | 31 ++++++++++++++++--------------- nginx/default.conf.template | 6 +++--- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/.env.sample b/.env.sample index ba29821..25dbac5 100644 --- a/.env.sample +++ b/.env.sample @@ -22,4 +22,8 @@ PHP_CRUD_API_DEBUG=1 ########################################### #DB ADMIN TOOL ("adminer" OR "phpmyadmin") -DB_ADMIN_TOOL=phpmyadmin \ No newline at end of file +DB_ADMIN_TOOL=phpmyadmin + +########################################### +#CONTAINERS' NAME SUFFIX +CONTAINERS_NAME_SUFFIX=php-quick-start diff --git a/README.md b/README.md index 277cde2..8e164c9 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,10 @@ PHP_CRUD_API_DEBUG=1 ########################################### #DB ADMIN TOOL ("adminer" OR "phpmyadmin") DB_ADMIN_TOOL=phpmyadmin + +########################################### +#CONTAINERS' NAME SUFFIX +CONTAINERS_NAME_SUFFIX=php-quick-start ``` Then run `start.sh`. Enjoy!🎉🚀 diff --git a/docker-compose.yml b/docker-compose.yml index e77b23a..53d6917 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ services: mysql: image: mysql:latest - container_name: mysql_treeqlqs + container_name: mysql_treeqlqs-${CONTAINERS_NAME_SUFFIX} restart: always environment: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} @@ -10,8 +10,8 @@ services: MYSQL_PASSWORD: ${MYSQL_PASSWORD} volumes: - ./mysql:/var/lib/mysql - #ports: - # - "3306:3306" + ports: + - "3306:3306" networks: - php-api-network @@ -19,12 +19,12 @@ services: build: context: . dockerfile: Dockerfile - container_name: php-fpm_treeqlqs + container_name: php-fpm_treeqlqs-${CONTAINERS_NAME_SUFFIX} volumes: - ./php:/var/www/html environment: PHP_CRUD_API_PORT: 3306 #${PORT} - PHP_CRUD_API_ADDRESS: mysql_treeqlqs #${SERVER_NAME} + PHP_CRUD_API_ADDRESS: mysql_treeqlqs-${CONTAINERS_NAME_SUFFIX} #${SERVER_NAME} PHP_CRUD_API_DATABASE: ${MYSQL_DATABASE} PHP_CRUD_API_USERNAME: ${MYSQL_USER} PHP_CRUD_API_PASSWORD: ${MYSQL_PASSWORD} @@ -36,29 +36,30 @@ services: web: image: nginx:latest - container_name: nginx_treeqlqs + container_name: nginx_treeqlqs-${CONTAINERS_NAME_SUFFIX} restart: always environment: - SERVER_NAME=${SERVER_NAME} - DB_ADMIN_PORT=${DB_ADMIN_PORT} + - CONTAINERS_NAME_SUFFIX=${CONTAINERS_NAME_SUFFIX} volumes: - ./nginx/default.conf.template:/etc/nginx/conf.d/default.conf.template - ./php:/var/www/html ports: - "${PORT}:80" - command: /bin/bash -c "envsubst '$$SERVER_NAME $$DB_ADMIN_PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" + command: /bin/bash -c "envsubst '$$SERVER_NAME $$DB_ADMIN_PORT $$CONTAINERS_NAME_SUFFIX' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" depends_on: - php - networks: + networks: - php-api-network adminer: - container_name: dbadmin_treeqlqs + container_name: dbadmin_treeqlqs-${CONTAINERS_NAME_SUFFIX} image: adminer restart: always environment: - ADMINER_DEFAULT_SERVER: mysql_treeqlqs - networks: + ADMINER_DEFAULT_SERVER: mysql_treeqlqs-${CONTAINERS_NAME_SUFFIX} + networks: - php-api-network depends_on: - web @@ -66,13 +67,13 @@ services: - adminer phpmyadmin: - container_name: dbadmin_treeqlqs + container_name: dbadmin_treeqlqs-${CONTAINERS_NAME_SUFFIX} image: phpmyadmin/phpmyadmin restart: always environment: - PMA_HOST: mysql_treeqlqs + PMA_HOST: mysql_treeqlqs-${CONTAINERS_NAME_SUFFIX} PMA_ABSOLUTE_URI: ${SERVER_NAME}dbadmin/ - networks: + networks: - php-api-network depends_on: - web @@ -80,7 +81,7 @@ services: - phpmyadmin swagger: - container_name: swagger_treeqlqs + container_name: swagger_treeqlqs-${CONTAINERS_NAME_SUFFIX} image: swaggerapi/swagger-ui restart: always environment: diff --git a/nginx/default.conf.template b/nginx/default.conf.template index 95988a5..55ec5bf 100644 --- a/nginx/default.conf.template +++ b/nginx/default.conf.template @@ -10,7 +10,7 @@ server { } location ~ \.php$ { - fastcgi_pass php-fpm_treeqlqs:9000; + fastcgi_pass php-fpm_treeqlqs-${CONTAINERS_NAME_SUFFIX}:9000; fastcgi_index api.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; @@ -19,7 +19,7 @@ server { location /swagger { rewrite ^/swagger$ /swagger/ permanent; - proxy_pass http://swagger_treeqlqs:8080/; + proxy_pass http://swagger_treeqlqs-${CONTAINERS_NAME_SUFFIX}:8080/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -29,6 +29,6 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; - proxy_pass http://dbadmin_treeqlqs:${DB_ADMIN_PORT}/; + proxy_pass http://dbadmin_treeqlqs-${CONTAINERS_NAME_SUFFIX}:${DB_ADMIN_PORT}/; } } \ No newline at end of file