Skip to content

Commit

Permalink
Merge common parts of compose configs into a single file, then overri…
Browse files Browse the repository at this point in the history
…de as needed.
  • Loading branch information
grigorescu committed Apr 23, 2024
1 parent 5a527ca commit 34ca489
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Cache Docker images.
uses: ScribeMD/[email protected]
with:
key: docker-${{ runner.os }}-${{ hashFiles('docker-compose.yaml') }}
key: docker-${{ runner.os }}-${{ hashFiles('compose*yml') }}

- name: "[pytest]: before"
run: "./.ci-scripts/pytest_before.sh"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ scram/media/
.ipython/
.envs/*
!.envs/.local/
docker-compose.yaml
compose.override.yml

coverage.coverage
coverage.xml
52 changes: 26 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@
## toggle-prod: configure make to use the production stack
.Phony: toggle-prod
toggle-prod:
@ln -sf production.yml docker-compose.yaml
@ln -sf compose.override.production.yml compose.override.yml

## toggle-local: configure make to use the local stack
.Phony: toggle-local
toggle-local:
@ln -sf local.yml docker-compose.yaml
@ln -sf compose.override.local.yml compose.override.yml

# Since toggle-(local|prod) are phony targets, this file is not tracked
# to compare if its "newer" so running another target with this as a prereq
# will not run this target again. That would overwrite docker-compose.yaml back to local.yml
# will not run this target again. That would overwrite compose.yml back to local.yml
# no matter what, which is bad. Phony targets prevents this
## docker-compose.yaml: creates file docker-compose.yaml on first run (as a prereq)
docker-compose.yaml:
@ln -sf local.yml docker-compose.yaml
## compose.yml: creates file compose.yml on first run (as a prereq)
compose.yml:
@ln -sf local.yml compose.yml

## behave-all: runs behave inside the containers against all of your features
.Phony: behave-all
behave-all: docker-compose.yaml
behave-all: compose.yml
@docker compose run django coverage run -a manage.py behave --no-input --simple

## behave: runs behave inside the containers against a specific feature (append FEATURE=feature_name_here)
.Phony: behave
behave: docker-compose.yaml
behave: compose.yml
@docker compose run django python manage.py behave --no-input --simple -i $(FEATURE)

## behave-translator
.Phony: behave-translator
behave-translator: docker-compose.yaml
behave-translator: compose.yml
@docker compose exec -T translator /usr/local/bin/behave /app/acceptance/features

## build: rebuilds all your containers or a single one if CONTAINER is specified
.Phony: build
build: docker-compose.yaml
build: compose.yml
@docker compose up -d --no-deps --build $(CONTAINER)
@docker compose restart $(CONTAINER)

Expand All @@ -50,38 +50,38 @@ ci-test: | toggle-local build migrate run coverage.xml

## clean: remove local containers and volumes
.Phony: clean
clean: docker-compose.yaml
clean: compose.yml
@docker compose rm -f -s
@docker volume prune -f

## collect-static: run collect static admin command
.Phony: collectstatic
collectstatic: docker-compose.yaml
collectstatic: compose.yml
@docker compose run django python manage.py collectstatic

## django-addr: get the IP and ephemeral port assigned to docker:8000
.Phony: django-addr
django-addr: docker-compose.yaml
django-addr: compose.yml
@docker compose port django 8000

## django-url: get the URL based on http://$(make django-addr)
.Phony: django-url
django-url: docker-compose.yaml
django-url: compose.yml
@echo http://$$(make django-addr)

## django-open: open a browser for http://$(make django-addr)
.Phony: django-open
django-open: docker-compose.yaml
django-open: compose.yml
@open http://$$(make django-addr)

## down: turn down docker compose stack
.Phony: down
down: docker-compose.yaml
down: compose.yml
@docker compose down

## exec: executes a given command on a given container (append CONTAINER=container_name_here and COMMAND=command_here)
.Phony: exec
exec: docker-compose.yaml
exec: compose.yml
@docker compose exec $(CONTAINER) $(COMMAND)

# This automatically builds the help target based on commands prepended with a double hashbang
Expand All @@ -93,42 +93,42 @@ help: Makefile
# TODO: When we move to flowspec this -a flag with change
## list-routes: list gobgp routes
.Phony: list-routes
list-routes: docker-compose.yaml
list-routes: compose.yml
@docker compose exec gobgp gobgp global rib -a ipv4
@docker compose exec gobgp gobgp global rib -a ipv6

## migrate: makemigrations and then migrate
.Phony: migrate
migrate: docker-compose.yaml
migrate: compose.yml
@docker compose run django python manage.py makemigrations
@docker compose run django python manage.py migrate

## pass-reset: change admin's password
.Phony: pass-reset
pass-reset: docker-compose.yaml
pass-reset: compose.yml
@docker compose run django python manage.py changepassword admin

## pytest: runs pytest inside the containers
.Phony: pytest
pytest: docker-compose.yaml
pytest: compose.yml
@docker compose run django coverage run -m pytest

## run: brings up the containers as described in docker-compose.yaml
## run: brings up the containers as described in compose.yml
.Phony: run
run: docker-compose.yaml
run: compose.yml
@docker compose up -d

## stop: turns off running containers
.Phony: stop
stop: docker-compose.yaml
stop: compose.yml
@docker compose stop

## tail-log: tail a docker container's logs (append CONTAINER=container_name_here)
.Phony: tail-log
tail-log: docker-compose.yaml
tail-log: compose.yml
@docker compose logs -f $(CONTAINER)

## type-check: static type checking
.Phony: type-check
type-check: docker-compose.yaml
type-check: compose.yml
@docker compose run django mypy scram
55 changes: 55 additions & 0 deletions compose.override.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
version: '3.4'

volumes:
local_postgres_data: {}
local_postgres_data_backups: {}

services:
django:
build:
dockerfile: ./compose/local/django/Dockerfile
image: scram_local_django
volumes:
- $CI_PROJECT_DIR:/app:z
- /tmp/profile_data:/tmp/profile_data
env_file:
- ./.envs/.local/.django
- ./.envs/.local/.postgres
ports:
- "8000"

postgres:
volumes:
- local_postgres_data:/var/lib/postgresql/data:Z
- local_postgres_data_backups:/backups:z
env_file:
- ./.envs/.local/.postgres

docs:
image: scram_local_docs
build:
context: .
dockerfile: ./compose/local/docs/Dockerfile
env_file:
- ./.envs/.local/.django
networks:
default: {}
volumes:
- $CI_PROJECT_DIR/docs:/docs:z
- $CI_PROJECT_DIR/config:/app/config:z
- $CI_PROJECT_DIR/scram:/app/scram:z
ports:
- "7000"
command: /start-docs

redis:
ports:
- "6379"

gobgp:
volumes:
- $CI_PROJECT_DIR/gobgp_config:/config:z
ports:
- "179"
- "50051"
48 changes: 1 addition & 47 deletions production.yml → compose.override.production.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.4'
---

volumes:
production_postgres_data: {}
Expand All @@ -9,39 +9,14 @@ volumes:
services:
django:
build:
context: .
dockerfile: ./compose/production/django/Dockerfile
image: scram_production_django
depends_on:
- postgres
- redis
networks:
default: {}
sysctls:
- net.ipv6.conf.all.disable_ipv6=0
volumes:
- ./staticfiles:/staticfiles
env_file:
- ./.envs/.production/.django
- ./.envs/.production/.postgres
- /etc/vault.d/secrets/kv_root_security.env
command: /start
healthcheck:
test: ["CMD", "curl", "-f", "http://django:5000/process_expired/"]
interval: 30s
timeout: 30s
start_period: 30s
retries: 5

postgres:
build:
context: .
dockerfile: ./compose/production/postgres/Dockerfile
image: scram_production_postgres
networks:
default: {}
sysctls:
- net.ipv6.conf.all.disable_ipv6=0
volumes:
- production_postgres_data:/var/lib/postgresql/data:Z
- production_postgres_data_backups:/backups:z
Expand All @@ -68,19 +43,12 @@ services:

redis:
image: redis:5.0
networks:
default: {}
sysctls:
- net.ipv6.conf.all.disable_ipv6=0
volumes:
- production_redis_data:/var/lib/redis:Z

gobgp:
image: jauderho/gobgp:v2.32.0
volumes:
- ./gobgp_config:/config:z
sysctls:
- net.ipv6.conf.all.disable_ipv6=0
networks:
default: {}
peering:
Expand All @@ -91,26 +59,12 @@ services:
- "50051"

translator:
build:
context: .
dockerfile: ./compose/local/translator/Dockerfile
depends_on:
- redis
- gobgp
networks:
default: {}
sysctls:
- net.ipv6.conf.all.disable_ipv6=0
env_file:
- ./.envs/.production/.translator

networks:
default:
enable_ipv6: true
ipam:
driver: default
config:
- subnet: 0200:c0:ff:ee::/48
peering:
enable_ipv6: true
driver: macvlan
Expand Down
Loading

0 comments on commit 34ca489

Please sign in to comment.