-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose.yml
149 lines (122 loc) · 4.13 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
version: '3.8'
#
# x-** are dummy mapping directives.
# only used for yaml anchors to
# DRY out the compose file
x-app-volumes: &volumes
volumes:
# This mounts the current working directory into the docker container
- .:/app
# These are things that change a lot and have to be synced with the host fs
# If you're running Linux, this is a non-issue. Docker for Mac has significant
# performance issues with file IO between host (docker) and the system.
# adding volumes for problem areas is one way to work around the situation
- gem_cache:/bundle/vendor
- node_modules:/app/node_modules
- packs:/app/public/packs
- packs_test:/app/public/packs-test
services:
#
# External Services
#
db:
# At the time of this writing Postgres 13 is the latest.
image: postgres:13
restart: on-failure
volumes:
- pg_data:/var/lib/postgresql/data
# allows us to dump the database somewhere e.g.:
# pg_dump -U $POSTGRES_USER -F t $POSTGRES_DB > /backups/$POSTGRES_DB-$(date +%Y-%m-%d).tar'
- ./db/dumps:/backups
environment:
# Postres docker containers are configured via env vars.
- POSTGRES_PASSWORD=letmein
- POSTGRES_USER=myuser
- POSTGRES_DB=appdb
networks:
# The "backend" network are supporting services that are not the app server, or not part of the HTTP layer.
- backend
ports:
# I like to expose "system" services on a different port, in case there is already an instance of pgsql running
# on the host machine. By doing this, postgres can be reached from localhost at port 5433.
- '5433:5432'
#
# App services
#
web:
# this command starts a rails server and listens on all interfaces (0.0.0.0)
command: bash -c "rm -f /app/tmp/pids/server.pid && rails s -p 3000 -b '0.0.0.0'"
restart: on-failure
# We have the option of adding an `environment:` yaml key here as well, but I prefer using an env file
# to keep things cleaner.
env_file: .env.docker.development
# This builds the image as "appimage" so that we can refer to it later in this file.
image: appimage
build:
context: ./
dockerfile: Dockerfile
<<: *volumes
networks:
- frontend
- backend
ports:
- '3000:3000'
# These declarations allow a pry session to be attatched if desired.
tty: true
stdin_open: true
webpacker:
command: ./bin/webpack-dev-server
restart: on-failure
env_file: .env.docker.development
# This is the app image we built in 'web'
image: appimage
# It's allowed to have both an .env file AND environment defined.
# when in doubt, refer to this: https://docs.docker.com/compose/environment-variables/
# This bit of configuration is critical
# to the proper operation of webpack-dev-server, so I like to define it here.
environment:
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0
<<: *volumes
# We don't need to connect to the DB at all here, so we just add the frontend network
networks:
- frontend
# allows webpack-dev-server to be accessed at localhost:3035
ports:
- '3035:3035'
#
# Testing
# To use: docker-compose exec rspec '/path/to/spec'
#
test:
image: appimage
env_file: .env.docker.test
# This does two things... Allows our test container to be persistent, and loads the test boilerplate
# for faster test runs. You need the "spring-commands-rspec" installed in order to make this work (assuming you're using rspec)
command: bin/spring server
environment:
- SELENIUM_REMOTE_HOST=selenium
# This is a different env file, for testing only.
env_file: .env.docker.test
# We don't need to allow access to the app at all during testing, so it's a backend service
networks:
- backend
<<: *volumes
selenium:
image: selenium/standalone-chrome:4.0.0-rc-1-prerelease-20210804
environment:
- VNC_NO_PASSWORD=1
networks:
- backend
ports:
- '4444:4444'
- '5900:5900'
# Our network declarations, used in
networks:
frontend:
backend:
volumes:
pg_data:
gem_cache:
node_modules:
packs:
packs_test: