Skip to content

Commit

Permalink
Merge pull request #3 from WildCodeSchool/feat/dockerComposeProd
Browse files Browse the repository at this point in the history
Feat/docker compose prod
  • Loading branch information
jfm-wcs authored Oct 20, 2023
2 parents afafd38 + 9fa4f04 commit 2afb693
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-traefik.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ main ]
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
Expand All @@ -15,4 +15,4 @@ jobs:
username: ${{ secrets.SSH_USER }}
host: ${{ secrets.SSH_HOST }}
password: ${{ secrets.SSH_PASSWORD }}
script: 'cd && cd traefik/deploy && bash ./php-projects.sh ${{ github.event.repository.name }} ${{ vars.PROJECT_NAME }}'
script: cd && cd traefik/deploy && bash ./php-project.sh ${{ github.actor }} ${{ github.event.repository.name }} ${{ vars.PROJECT_NAME }} '${{ toJSON(vars) }}'
2 changes: 2 additions & 0 deletions database-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mysql -u root -p$MYSQL_ROOT_PASSWORD --execute \
"GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%';"
37 changes: 37 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3.4'

services:
web:
ports:
- "127.0.0.1:8000:80"
environment:
DB_USER: user
DB_PASSWORD: password
DB_HOST: database
DB_NAME: simplemvc
depends_on:
database:
condition: service_healthy
database:
image: mysql/mysql-server:8.0
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "-uroot", "-prootpassword"] # Command to check health.
interval: 5s # Interval between health checks.
timeout: 5s # Timeout for each health checking.
retries: 20 # Hou many times retries.
start_period: 10s
# container_name: database
volumes:
- ./database-setup.sh:/docker-entrypoint-initdb.d/setup.sh
- db-data:/var/lib/mysql
environment:
MYSQL_USER: user
MYSQL_PASSWORD: password
# Password for root access
MYSQL_ROOT_PASSWORD: rootpassword
ports:
- "3306:3306"

volumes:
db-data:
name: database
25 changes: 25 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.4'

services:
web:
build: .
container_name: ${PROJECT_NAME:-project}-web
volumes:
- ./:/var/www
restart: always
networks:
- proxy
environment:
DB_USER: ${USER_NAME}
DB_PASSWORD: ${USER_PASSWORD}
DB_HOST: ${DATABASE_SUBDOMAIN_NAME}-db
DB_NAME: ${DB_NAME}
labels:
- "traefik.enable=true"
- "traefik.docker.network=proxy"
- "traefik.http.routers.${PROJECT_NAME:-project}-secure.entrypoints=websecure"
- "traefik.http.routers.${PROJECT_NAME:-project}-secure.rule=Host(`${PROJECT_NAME:-project}.${HOST:-localhost}`)"

networks:
proxy:
external: true
26 changes: 4 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
version: '3.4'

services:
web:
build: .
container_name: ${PROJECT_NAME:-project}-web
volumes:
- ./:/var/www
restart: always
networks:
- proxy
environment:
DB_USER: ${USER_NAME}
DB_PASSWORD: ${USER_PASSWORD}
DB_HOST: ${DATABASE_SUBDOMAIN_NAME}-db
DB_NAME: ${DB_NAME}
labels:
- "traefik.enable=true"
- "traefik.docker.network=proxy"
- "traefik.http.routers.${PROJECT_NAME:-project}-secure.entrypoints=websecure"
- "traefik.http.routers.${PROJECT_NAME:-project}-secure.rule=Host(`${PROJECT_NAME:-project}.${HOST:-localhost}`)"

networks:
proxy:
external: true
web:
build: .
volumes:
- ./:/var/www

0 comments on commit 2afb693

Please sign in to comment.