Skip to content

Commit

Permalink
dc: use extends instead of composition
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Verhoog committed Oct 31, 2020
1 parent 56fb108 commit 588da5d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 57 deletions.
26 changes: 6 additions & 20 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
run: docker login -u publisher -p ${{ secrets.GHCR_TOKEN }} ghcr.io

- name: build images
run: docker-compose -f docker-compose.yml -f prod.yml build
run: docker-compose -f prod.yml build

- name: publish to registry
run: docker-compose -f docker-compose.yml -f prod.yml push
run: docker-compose -f prod.yml push

- name: deploy to swarm
run: |
Expand All @@ -27,21 +27,7 @@ jobs:
eval $(ssh-agent)
ssh-add "$HOME/.ssh/docker"
echo "crossroadsajax.church $SSH_KNOWN_HOST" >> ~/.ssh/known_hosts
docker --log-level debug --host "ssh://[email protected]" stack deploy -c docker-compose.yml -c prod.yml --with-registry-auth prod
shell: bash
env:
SSH_PRIV_KEY: ${{ secrets.DOCKER_SSH_PRIVATE_KEY }}
SSH_KNOWN_HOST: ${{ secrets.DOCKER_SSH_PUBLIC_KEY }}

- name: deploy to swarm
run: |
mkdir -p "$HOME/.ssh"
echo "$SSH_PRIV_KEY" > "$HOME/.ssh/docker"
chmod 600 "$HOME/.ssh/docker"
eval $(ssh-agent)
ssh-add "$HOME/.ssh/docker"
echo "crossroadsajax.church $SSH_KNOWN_HOST" >> ~/.ssh/known_hosts
docker --log-level debug --host "ssh://[email protected]" stack deploy -c docker-compose.yml -c prod.yml --with-registry-auth prod
docker --host "ssh://[email protected]" stack deploy -c prod.yml --with-registry-auth prod
shell: bash
env:
SSH_PRIV_KEY: ${{ secrets.DOCKER_SSH_PRIVATE_KEY }}
Expand All @@ -58,10 +44,10 @@ jobs:
run: docker login -u publisher -p ${{ secrets.GHCR_TOKEN }} ghcr.io

- name: build images
run: docker-compose -f docker-compose.yml -f staging.yml build
run: docker-compose -f staging.yml build

- name: publish to registry
run: docker-compose -f docker-compose.yml -f staging.yml push
run: docker-compose -f staging.yml push

- name: deploy to swarm
run: |
Expand All @@ -71,7 +57,7 @@ jobs:
eval $(ssh-agent)
ssh-add "$HOME/.ssh/docker"
echo "crossroadsajax.church $SSH_KNOWN_HOST" >> ~/.ssh/known_hosts
docker --log-level debug --host "ssh://[email protected]" stack deploy -c docker-compose.yml -c staging.yml --with-registry-auth staging
docker --host "ssh://[email protected]" stack deploy -c staging.yml --with-registry-auth staging
shell: bash
env:
SSH_PRIV_KEY: ${{ secrets.DOCKER_SSH_PRIVATE_KEY }}
Expand Down
36 changes: 36 additions & 0 deletions common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.7'

services:
app:
build:
context: ./
dockerfile: ./docker/server/Dockerfile
environment:
- DATADOG_TRACE_AGENT_HOSTNAME=datadog
- DD_ENV=dev
- DD_SERVICE=crossroads-web
- DD_LOGS_INJECTION=true
- DD_TRACE_ANALYTICS_ENABLED=true
- DD_TRACE_ASYNCIO_ENABLED=true
- DD_DJANGO_CACHE_SERVICE_NAME=crossroads-cache
- DD_DJANGO_DATABASE_SERVICE_NAME=crossroads-web
- DD_DJANGO_USE_HANDLER_RESOURCE_FORMAT=true
- DD_SQLITE_SERVICE=crossroads-db
- DD_PROFILING_ENABLED=true

nginx:
restart: always

datadog:
environment:
- DD_CONTAINER_EXCLUDE="name:datadog"
- DD_APM_ENABLED=true
- DD_LOGS_ENABLED=true
- DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true
build:
context: ./docker/datadog
dockerfile: ./Dockerfile
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /proc/:/host/proc/:ro
- /sys/fs/cgroup:/host/sys/fs/cgroup:ro
7 changes: 0 additions & 7 deletions docker-compose.override.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@ version: '3.7'
# Override the default docker-compose.yml with dev settings
services:
app:
command: ddtrace-run python manage.py runserver 0.0.0.0:8000
environment:
- DD_ENV=dev
- POSTMARK_API_KEY=
volumes:
- .:/app

nginx:
build:
context: ./docker/nginx_dev
dockerfile: ./Dockerfile
# Edit 8000 to your desired port
ports:
- 8000:80
Expand Down
43 changes: 15 additions & 28 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,27 @@ version: '3.7'

services:
app:
build:
context: ./
dockerfile: ./docker/server/Dockerfile
extends:
file: common.yml
service: app
environment:
- DATADOG_TRACE_AGENT_HOSTNAME=datadog
- DD_ENV=dev
- DD_SERVICE=crossroads-web
- DD_LOGS_INJECTION=true
- DD_TRACE_ANALYTICS_ENABLED=true
- DD_TRACE_ASYNCIO_ENABLED=true
- DD_DJANGO_CACHE_SERVICE_NAME=crossroads-cache
- DD_DJANGO_DATABASE_SERVICE_NAME=crossroads-web
- DD_DJANGO_USE_HANDLER_RESOURCE_FORMAT=true
- DD_SQLITE_SERVICE=crossroads-db
- DD_PROFILING_ENABLED=true
restart: always
command: ddtrace-run python manage.py runserver 0.0.0.0:8000
volumes:
- .:/app

nginx:
extends:
file: common.yml
service: nginx
build:
context: ./docker/nginx_dev
dockerfile: ./Dockerfile
restart: always
depends_on:
- app

datadog:
extends:
file: common.yml
service: datadog
environment:
- DD_CONTAINER_EXCLUDE="name:datadog"
- DD_APM_ENABLED=true
- DD_LOGS_ENABLED=true
- DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true
- DD_LOG_LEVEL=INFO
image: ghcr.io/crossroadsinajax/datadog-agent:prod
build:
context: ./docker/datadog
dockerfile: ./Dockerfile
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /proc/:/host/proc/:ro
- /sys/fs/cgroup:/host/sys/fs/cgroup:ro
10 changes: 9 additions & 1 deletion prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ version: '3.7'

services:
app:
extends:
file: common.yml
service: app
image: ghcr.io/crossroadsinajax/app:${GIT_TAG}
environment:
- DD_ENV=prod
command: >
sh -c "python manage.py migrate &&
python manage.py loaddata groups &&
ddtrace-run daphne -b 0.0.0.0 -p 8000 crossroads.asgi:application"
restart: always
secrets:
- django_secret
- postmark_api_key
Expand All @@ -21,6 +23,9 @@ services:
- /home/kyle/prod/media:/app/media

nginx:
extends:
file: common.yml
service: nginx
image: ghcr.io/crossroadsinajax/nginx:${GIT_TAG}
build:
context: ./docker/nginx_prod
Expand All @@ -31,6 +36,9 @@ services:
- staticfiles:/static

datadog:
extends:
file: common.yml
service: datadog
image: ghcr.io/crossroadsinajax/datadog-agent:${GIT_TAG}
environment:
- DD_LOG_LEVEL=WARNING
Expand Down
10 changes: 9 additions & 1 deletion staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ version: '3.7'

services:
app:
extends:
file: common.yml
service: app
image: ghcr.io/crossroadsinajax/app:latest
environment:
- DD_ENV=staging
command: >
sh -c "python manage.py migrate &&
python manage.py loaddata groups &&
ddtrace-run daphne -b 0.0.0.0 -p 8000 crossroads.asgi:application"
restart: always
secrets:
- django_secret
- postmark_api_key
Expand All @@ -23,6 +25,9 @@ services:
- /home/kyle/staging/media:/app/media

nginx:
extends:
file: common.yml
service: nginx
image: ghcr.io/crossroadsinajax/nginx:latest
build:
context: ./docker/nginx_prod
Expand All @@ -33,6 +38,9 @@ services:
- staticfiles:/static

datadog:
extends:
file: common.yml
service: datadog
image: ghcr.io/crossroadsinajax/datadog-agent:latest
environment:
- DD_LOG_LEVEL=WARNING
Expand Down

0 comments on commit 588da5d

Please sign in to comment.