Skip to content

Commit c7fa60f

Browse files
authored
Fixed docker compose profiles (#23171)
no refs These two commits (bec0b97 & 55f2e42) used the `extends` feature of Docker Compose to share the list of volumes and environment variables, to avoid duplicating the long list of `node_modules` volumes. However, this didn't work as expected, because the `tinybird` and `browser-tests` services also inherit the `profiles` key. This means that the `tinybird` and `browser-tests` services _also_ implicitly have the `ghost` service, so they were running when using `yarn docker:dev`, which we don't want. This change refactors to use a common base template service using YAML anchors and aliases, rather than using Docker Compose `extends`. This allows these services to share just the volumes and environment, without also sharing profiles and other settings from the base service. One caveat that I haven't solved yet: this pattern doesn't allow you to add additional volumes and environment variables to particular services, so we can't i.e. use all the shared volumes, plus declare additional volumes on a service-by-service basis. This isn't ideal, but it'll do for now.
1 parent 9f2bed2 commit c7fa60f

File tree

1 file changed

+61
-64
lines changed

1 file changed

+61
-64
lines changed

compose.yml

+61-64
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,62 @@
11
name: ghost
2+
3+
# Template to share volumes and environment variable between all services running the same base image
4+
x-service-template: &service-template
5+
volumes:
6+
- .:/home/ghost
7+
- ${SSH_AUTH_SOCK}:/ssh-agent
8+
- ${HOME}/.gitconfig:/root/.gitconfig:ro
9+
- node_modules_ghost_root:/home/ghost/node_modules:delegated
10+
- node_modules_ghost_admin:/home/ghost/ghost/admin/node_modules:delegated
11+
- node_modules_ghost_api-framework:/home/ghost/ghost/api-framework/node_modules:delegated
12+
- node_modules_ghost_constants:/home/ghost/ghost/constants/node_modules:delegated
13+
- node_modules_ghost_core:/home/ghost/ghost/core/node_modules:delegated
14+
- node_modules_ghost_custom-fonts:/home/ghost/ghost/custom-fonts/node_modules:delegated
15+
- node_modules_ghost_domain-events:/home/ghost/ghost/domain-events/node_modules:delegated
16+
- node_modules_ghost_donations:/home/ghost/ghost/donations/node_modules:delegated
17+
- node_modules_ghost_email-addresses:/home/ghost/ghost/email-addresses/node_modules:delegated
18+
- node_modules_ghost_email-service:/home/ghost/ghost/email-service/node_modules:delegated
19+
- node_modules_ghost_html-to-plaintext:/home/ghost/ghost/html-to-plaintext/node_modules:delegated
20+
- node_modules_ghost_i18n:/home/ghost/ghost/i18n/node_modules:delegated
21+
- node_modules_ghost_job-manager:/home/ghost/ghost/job-manager/node_modules:delegated
22+
- node_modules_ghost_link-replacer:/home/ghost/ghost/link-replacer/node_modules:delegated
23+
- node_modules_ghost_member-attribution:/home/ghost/ghost/member-attribution/node_modules:delegated
24+
- node_modules_ghost_members-csv:/home/ghost/ghost/members-csv/node_modules:delegated
25+
- node_modules_ghost_mw-error-handler:/home/ghost/ghost/mw-error-handler/node_modules:delegated
26+
- node_modules_ghost_mw-vhost:/home/ghost/ghost/mw-vhost/node_modules:delegated
27+
- node_modules_ghost_offers:/home/ghost/ghost/offers/node_modules:delegated
28+
- node_modules_ghost_post-events:/home/ghost/ghost/post-events/node_modules:delegated
29+
- node_modules_ghost_post-revisions:/home/ghost/ghost/post-revisions/node_modules:delegated
30+
- node_modules_ghost_prometheus-metrics:/home/ghost/ghost/prometheus-metrics/node_modules:delegated
31+
- node_modules_ghost_security:/home/ghost/ghost/security/node_modules:delegated
32+
- node_modules_ghost_tiers:/home/ghost/ghost/tiers/node_modules:delegated
33+
- node_modules_ghost_webmentions:/home/ghost/ghost/webmentions/node_modules:delegated
34+
- node_modules_apps_admin-x-activitypub:/home/ghost/apps/admin-x-activitypub/node_modules:delegated
35+
- node_modules_apps_admin-x-design-system:/home/ghost/apps/admin-x-design-system/node_modules:delegated
36+
- node_modules_apps_admin-x-framework:/home/ghost/apps/admin-x-framework/node_modules:delegated
37+
- node_modules_apps_admin-x-settings:/home/ghost/apps/admin-x-settings/node_modules:delegated
38+
- node_modules_apps_announcement-bar:/home/ghost/apps/announcement-bar/node_modules:delegated
39+
- node_modules_apps_comments-ui:/home/ghost/apps/comments-ui/node_modules:delegated
40+
- node_modules_apps_portal:/home/ghost/apps/portal/node_modules:delegated
41+
- node_modules_apps_posts:/home/ghost/apps/posts/node_modules:delegated
42+
- node_modules_apps_shade:/home/ghost/apps/shade/node_modules:delegated
43+
- node_modules_apps_signup-form:/home/ghost/apps/signup-form/node_modules:delegated
44+
- node_modules_apps_sodo-search:/home/ghost/apps/sodo-search/node_modules:delegated
45+
- node_modules_apps_stats:/home/ghost/apps/stats/node_modules:delegated
46+
environment:
47+
- DEBUG=${DEBUG:-}
48+
- SSH_AUTH_SOCK=/ssh-agent
49+
- NX_DAEMON=${NX_DAEMON:-true}
50+
- GHOST_DEV_IS_DOCKER=true
51+
- GHOST_DEV_APP_FLAGS=${GHOST_DEV_APP_FLAGS:-}
52+
- GHOST_UPSTREAM=${GHOST_UPSTREAM:-}
53+
- STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY:-}
54+
- STRIPE_PUBLISHABLE_KEY=${STRIPE_PUBLISHABLE_KEY:-}
55+
- STRIPE_ACCOUNT_ID=${STRIPE_ACCOUNT_ID:-}
56+
257
services:
358
ghost:
59+
<<: *service-template
460
build:
561
context: .
662
dockerfile: ./.docker/Dockerfile
@@ -19,91 +75,32 @@ services:
1975
- "7173:7173" # Comments
2076
- "7174:7174" # Comments HTTPS
2177
profiles: [ ghost ]
22-
volumes:
23-
# Mount the source code
24-
- .:/home/ghost
25-
26-
## SSH Agent forwarding
27-
- ${SSH_AUTH_SOCK}:/ssh-agent
28-
29-
## Git config
30-
- ${HOME}/.gitconfig:/root/.gitconfig:ro
31-
32-
# Volume exclusions:
33-
## Prevent collisions between host and container node_modules
34-
- node_modules_ghost_root:/home/ghost/node_modules:delegated
35-
- node_modules_ghost_admin:/home/ghost/ghost/admin/node_modules:delegated
36-
- node_modules_ghost_api-framework:/home/ghost/ghost/api-framework/node_modules:delegated
37-
- node_modules_ghost_constants:/home/ghost/ghost/constants/node_modules:delegated
38-
- node_modules_ghost_core:/home/ghost/ghost/core/node_modules:delegated
39-
- node_modules_ghost_custom-fonts:/home/ghost/ghost/custom-fonts/node_modules:delegated
40-
- node_modules_ghost_domain-events:/home/ghost/ghost/domain-events/node_modules:delegated
41-
- node_modules_ghost_donations:/home/ghost/ghost/donations/node_modules:delegated
42-
- node_modules_ghost_email-addresses:/home/ghost/ghost/email-addresses/node_modules:delegated
43-
- node_modules_ghost_email-service:/home/ghost/ghost/email-service/node_modules:delegated
44-
- node_modules_ghost_html-to-plaintext:/home/ghost/ghost/html-to-plaintext/node_modules:delegated
45-
- node_modules_ghost_i18n:/home/ghost/ghost/i18n/node_modules:delegated
46-
- node_modules_ghost_job-manager:/home/ghost/ghost/job-manager/node_modules:delegated
47-
- node_modules_ghost_link-replacer:/home/ghost/ghost/link-replacer/node_modules:delegated
48-
- node_modules_ghost_member-attribution:/home/ghost/ghost/member-attribution/node_modules:delegated
49-
- node_modules_ghost_members-csv:/home/ghost/ghost/members-csv/node_modules:delegated
50-
- node_modules_ghost_mw-error-handler:/home/ghost/ghost/mw-error-handler/node_modules:delegated
51-
- node_modules_ghost_mw-vhost:/home/ghost/ghost/mw-vhost/node_modules:delegated
52-
- node_modules_ghost_offers:/home/ghost/ghost/offers/node_modules:delegated
53-
- node_modules_ghost_post-events:/home/ghost/ghost/post-events/node_modules:delegated
54-
- node_modules_ghost_post-revisions:/home/ghost/ghost/post-revisions/node_modules:delegated
55-
- node_modules_ghost_prometheus-metrics:/home/ghost/ghost/prometheus-metrics/node_modules:delegated
56-
- node_modules_ghost_security:/home/ghost/ghost/security/node_modules:delegated
57-
- node_modules_ghost_tiers:/home/ghost/ghost/tiers/node_modules:delegated
58-
- node_modules_ghost_webmentions:/home/ghost/ghost/webmentions/node_modules:delegated
59-
- node_modules_apps_admin-x-activitypub:/home/ghost/apps/admin-x-activitypub/node_modules:delegated
60-
- node_modules_apps_admin-x-design-system:/home/ghost/apps/admin-x-design-system/node_modules:delegated
61-
- node_modules_apps_admin-x-framework:/home/ghost/apps/admin-x-framework/node_modules:delegated
62-
- node_modules_apps_admin-x-settings:/home/ghost/apps/admin-x-settings/node_modules:delegated
63-
- node_modules_apps_announcement-bar:/home/ghost/apps/announcement-bar/node_modules:delegated
64-
- node_modules_apps_comments-ui:/home/ghost/apps/comments-ui/node_modules:delegated
65-
- node_modules_apps_portal:/home/ghost/apps/portal/node_modules:delegated
66-
- node_modules_apps_posts:/home/ghost/apps/posts/node_modules:delegated
67-
- node_modules_apps_shade:/home/ghost/apps/shade/node_modules:delegated
68-
- node_modules_apps_signup-form:/home/ghost/apps/signup-form/node_modules:delegated
69-
- node_modules_apps_sodo-search:/home/ghost/apps/sodo-search/node_modules:delegated
70-
- node_modules_apps_stats:/home/ghost/apps/stats/node_modules:delegated
7178
tty: true
7279
depends_on:
7380
mysql:
7481
condition: service_healthy
7582
redis:
7683
condition: service_healthy
77-
environment:
78-
- DEBUG=${DEBUG:-}
79-
- SSH_AUTH_SOCK=/ssh-agent
80-
- NX_DAEMON=${NX_DAEMON:-true}
81-
- GHOST_DEV_IS_DOCKER=true
82-
- GHOST_DEV_APP_FLAGS=${GHOST_DEV_APP_FLAGS:-}
83-
- GHOST_UPSTREAM=${GHOST_UPSTREAM:-}
84-
- STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY:-}
85-
- STRIPE_PUBLISHABLE_KEY=${STRIPE_PUBLISHABLE_KEY:-}
86-
- STRIPE_ACCOUNT_ID=${STRIPE_ACCOUNT_ID:-}
84+
8785
tinybird:
88-
extends:
89-
service: ghost
86+
<<: *service-template
9087
build:
9188
context: .
9289
dockerfile: ./.docker/Dockerfile
9390
target: tinybird
9491
working_dir: /home/ghost/ghost/web-analytics
95-
profiles: [ tinybird]
92+
profiles: [ tinybird ]
9693
tty: true
9794

9895
browser-tests:
99-
extends:
100-
service: ghost
96+
<<: *service-template
10197
build:
10298
context: .
10399
dockerfile: ./.docker/Dockerfile
104100
target: browser-tests
105101
command: [ "yarn", "test:browser" ]
106102
profiles: [ browser-tests ]
103+
tty: true
107104

108105
mysql:
109106
image: mysql:8.4.5

0 commit comments

Comments
 (0)