Skip to content

Commit

Permalink
1.1.0 - parametric docker containers name (solves multiple php-crud-a…
Browse files Browse the repository at this point in the history
…pi-qs instances deploys)
  • Loading branch information
nik2208 committed Dec 16, 2024
1 parent cbe061b commit b0d0fac
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
6 changes: 5 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ PHP_CRUD_API_DEBUG=1

###########################################
#DB ADMIN TOOL ("adminer" OR "phpmyadmin")
DB_ADMIN_TOOL=phpmyadmin
DB_ADMIN_TOOL=phpmyadmin

###########################################
#CONTAINERS' NAME SUFFIX
CONTAINERS_NAME_SUFFIX=php-quick-start
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!🎉🚀
Expand Down
31 changes: 16 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -10,21 +10,21 @@ services:
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
volumes:
- ./mysql:/var/lib/mysql
#ports:
# - "3306:3306"
ports:
- "3306:3306"
networks:
- php-api-network

php:
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}
Expand All @@ -36,51 +36,52 @@ 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
profiles:
- 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
profiles:
- phpmyadmin

swagger:
container_name: swagger_treeqlqs
container_name: swagger_treeqlqs-${CONTAINERS_NAME_SUFFIX}
image: swaggerapi/swagger-ui
restart: always
environment:
Expand Down
6 changes: 3 additions & 3 deletions nginx/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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}/;
}
}

0 comments on commit b0d0fac

Please sign in to comment.