Skip to content

Commit

Permalink
Ensure that Docker Compose within projects work as expected
Browse files Browse the repository at this point in the history
When setting up projects configure Dapple-specific COMPOSE_PROJECT_NAME 
values in the project .env files. This will ensure that containers will
not conflict with default project checkouts using defaults and that 
subsequent docker commands will work on the Dapple-initiated containers.

We use variables instead of environment variables as they are easier to
work with. Their actual values are shown when running commands.

Update our test to ensure that it works as expected.
  • Loading branch information
kasperg committed Dec 5, 2023
1 parent 947b8ec commit e9bf012
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ jobs:
# The demo modal test is simple and quick to execute.
spec: src/apps/demo-modal/demo-modal.test.ts
- name: Test CMS after linking
working-directory: cms
# A single request to see that the frontpage can be retrieved should be
# sufficient to ensure that Drupal can bootstrap and return a page.
# COMPOSE_PROJECT_NAME must match the value from Dapple Taskfile.yml.
run: "curl --fail http://localhost:$(COMPOSE_PROJECT_NAME=dapple docker compose port varnish 8080 | cut -d: -f2)"
# If we can get ports for running containers in the CMS directory after
# initializing then docker commands within the subdirectory will work
# with the Dapple-initiated containers as expected.
run: "curl --fail http://localhost:$(docker compose port varnish 8080 | cut -d: -f2)"
# Test that changes to design system results in changes in React component dependencies
- name: Store current build of Design system in React components
run: |
Expand Down
13 changes: 8 additions & 5 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ version: '3'

output: prefixed

env:
# Set project name to avoid conflicts with single checkouts.
COMPOSE_PROJECT_NAME: dapple
vars:
COMPOSE_PREFIX: dapple
CMS_COMPOSE_PROJECT_NAME: "{{.COMPOSE_PREFIX}}-cms"
REACT_COMPOSE_PROJECT_NAME: "{{.COMPOSE_PREFIX}}-react"

tasks:
init:
Expand Down Expand Up @@ -77,8 +78,9 @@ tasks:
react:clone:
cmds:
- git clone https://github.com/danskernesdigitalebibliotek/dpl-react react
# Set project name to avoid conflicts with single checkouts.
- cp react/.env.example react/.env
- echo "COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}-react" >> react/.env
- echo "COMPOSE_PROJECT_NAME={{.REACT_COMPOSE_PROJECT_NAME}}" >> react/.env

react:link:
dir: react
Expand Down Expand Up @@ -117,7 +119,8 @@ tasks:
cms:clone:
cmds:
- git clone https://github.com/danskernesdigitalebibliotek/dpl-cms cms
- sed "s|COMPOSE_PROJECT_NAME=dpl-cms|COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}-cms|g" <cms/.env.example >cms/.env
# Set project name to avoid conflicts with single checkouts.
- sed "s|COMPOSE_PROJECT_NAME=dpl-cms|COMPOSE_PROJECT_NAME={{.CMS_COMPOSE_PROJECT_NAME}}|g" <cms/.env.example >cms/.env

cms:link:
dir: cms
Expand Down

0 comments on commit e9bf012

Please sign in to comment.