Skip to content

Commit b53ddb3

Browse files
Merge pull request #1983 from openaustralia/chore/update_development_setup_and_doc
Chore/update development setup and doc
2 parents 324eace + 8f33c29 commit b53ddb3

2 files changed

Lines changed: 76 additions & 5 deletions

File tree

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,33 @@ git clone https://github.com/openaustralia/planningalerts.git
2424
cd planningalerts
2525
```
2626

27+
### Resetting Your Environment
28+
29+
To force a rebuild from scratch, stopping and removing containers and volumes (including the databases):
30+
31+
```sh
32+
docker compose down -v --rmi all
33+
# Check if this volume is "still in use"
34+
docker volume rm planningalerts_gem_cache
35+
```
36+
37+
If you get a `volume is in use` error, remove the container using the given id and then retry, for example:
38+
39+
```sh
40+
> Error response from daemon: remove planningalerts_gem_cache: volume is in use - [98ba717d944d01976ac9074e6a1119e70d3aebd53f5d5449957324926f0bbb4b]
41+
42+
docker rm 98ba717d944d01976ac9074e6a1119e70d3aebd53f5d5449957324926f0bbb4b
43+
> 98ba717d944d01976ac9074e6a1119e70d3aebd53f5d5449957324926f0bbb4b
44+
45+
docker volume rm planningalerts_gem_cache
46+
```
47+
2748
### Setup The Database
2849

2950
Set up the databases - `docker compose run web bin/rake db:setup`
3051

52+
This will trigger a build if needed. You can manually trigger a build by first running - `docker compose build`
53+
3154
### Start the application
3255

3356
* `docker compose up`
@@ -70,6 +93,16 @@ bin/tapioca dsl --environment=test
7093

7194
We use Shopify's [tapioca](https://github.com/Shopify/tapioca) gem to manage all our rbi files. We **don't** use `bundle exec srb rbi ...`.
7295

96+
### Other useful docker commands
97+
98+
* `docker compose ps` - View running containers and their status
99+
* `docker compose logs [-f] [service]` - View logs for all or a specific service, add `-f` to continue watching (the up command also does this)
100+
* `docker compose restart web` - Restart the web container (eg when you make a change to the code)
101+
* `docker compose down` - Stop and remove containers (keeps volumes and images intact for quick restart)
102+
* `docker compose exec web bash` - Run a shell in the running container
103+
* `docker compose run web bin/rails console` - Run a once-off command in new container
104+
* `docker system prune --all` - Remove all stopped containers, orphaned images / networks, build cache etc. (Remove the -v if you want to keep your databases and gem cache)
105+
73106
## Deployment
74107

75108
The code is deployed using Capistrano. To deploy to production run:

docker-compose.yml

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@ services:
1313
ports:
1414
- "3000:3000"
1515
depends_on:
16-
- postgres
17-
- redis
18-
- mailcatcher
19-
- elasticsearch
16+
# Required for nearly everything
17+
postgres:
18+
condition: service_healthy
19+
# Required for rack stack and flipper initialisation abd caching
20+
redis:
21+
condition: service_healthy
22+
# Required for logging api calls etc
23+
elasticsearch:
24+
condition: service_healthy
25+
# Required for jobs sending email
26+
mailcatcher:
27+
condition: service_healthy
2028
command: "bin/dev"
2129
tty: true
2230

@@ -30,9 +38,11 @@ services:
3038
ports:
3139
- "2525:25"
3240
depends_on:
33-
- postgres
41+
postgres:
42+
condition: service_healthy
3443
user: root
3544
command: postfix start-fg
45+
3646

3747
postgres:
3848
# Same version as used in production
@@ -51,6 +61,13 @@ services:
5161
environment:
5262
# The values below need to be the same in config/database.yml
5363
POSTGRES_PASSWORD: password
64+
healthcheck:
65+
test: ["CMD-SHELL", "pg_isready -U postgres || exit 1"]
66+
interval: 5s
67+
timeout: 10s
68+
retries: 5
69+
start_period: 30s
70+
# start_interval: 1s # TODO: Uncomment after 2028 when Docker Compose 2.21+ should be widespread (introduced Dec 2023)
5471

5572
redis:
5673
# TODO: Try switching to alpine variant for slimmer images
@@ -60,13 +77,27 @@ services:
6077
- "6379"
6178
volumes:
6279
- redis_data:/data
80+
healthcheck:
81+
test: ["CMD-SHELL", "redis-cli ping || exit 1"]
82+
interval: 5s
83+
timeout: 5s
84+
retries: 5
85+
start_period: 30s
86+
# start_interval: 1s # TODO: Uncomment after 2028 when Docker Compose 2.21+ should be widespread (introduced Dec 2023)
6387

6488
mailcatcher:
6589
build:
6690
context: .
6791
dockerfile: Dockerfile.mailcatcher
6892
ports:
6993
- "1080:1080"
94+
healthcheck:
95+
test: ["CMD-SHELL", "curl -f http://localhost:1080 || exit 1"]
96+
interval: 5s
97+
timeout: 5s
98+
retries: 5
99+
start_period: 30s
100+
# start_interval: 1s # TODO: Uncomment after 2028 when Docker Compose 2.21+ should be widespread (introduced Dec 2023)
70101

71102
elasticsearch:
72103
# Using version 7.17.7 in production. So matching here
@@ -79,6 +110,13 @@ services:
79110
- "discovery.type=single-node"
80111
volumes:
81112
- elasticsearch_data:/usr/share/elasticsearch/data
113+
healthcheck:
114+
test: ["CMD-SHELL", "curl -f http://localhost:9200/_cluster/health || exit 1"]
115+
interval: 5s
116+
timeout: 10s
117+
retries: 5
118+
start_period: 30s
119+
# start_interval: 1s # TODO: Uncomment after 2028 when Docker Compose 2.21+ should be widespread (introduced Dec 2023)
82120

83121
volumes:
84122
gem_cache:

0 commit comments

Comments
 (0)