Skip to content

Commit ff4ee38

Browse files
committed
Add description of railway deploy, update docker compose to better align with swarm config
1 parent 299699f commit ff4ee38

4 files changed

Lines changed: 65 additions & 8 deletions

File tree

‎12-deploying-containers/README.md‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
# Deploying containers
22

3-
So many options!
3+
One of the major benefits of containerization is that it provides a standard interface that others can use to design their systems. Because of this, TONS of different options are available for deploying containers to the cloud.
44

5-
- Railway
6-
- Docker Swarm
7-
- Kubernetes
5+
Within AWS alone, Corey Quinn (from the Duckbill Group) noted there are 17 unique ways to run containers (https://www.lastweekinaws.com/blog/the-17-ways-to-run-containers-on-aws/). That was in 2021... the number has probably gone up by now!
6+
7+
We will be deploying in 3 different ways:
8+
9+
## Railway.app
10+
11+
Railway is a relatively new infrastructure company focused on making it as easy as possible for users to deploy applications. They offer automated deployments from GitHub, an intuitive user interface, and even created a technology called Nixpacks (https://nixpacks.com/) which enable you to create a container image automagically (without the need for a Dockerfile). For some situations the nixpacks work seamlessly (for the golang api it worked), for others it can be necessary to specify your own Dockerfile so that you have full control.
12+
13+
Unfortunately there is no way (in Feb 2023) to specify a Docker build context other than the location of the Dockerfile. Also, their build environment didn't support using `--mount=type=cache`. Because of this I created a `Dockerfile.railway` in the `06-building-container-images` directory. To prevent this cluttering the repo, I only included this on the `railway` git branch.
14+
15+
```
16+
git fetch && git checkout railway # fetch and checkout the railway branch
17+
```
18+
19+
The deployment configuration is specified via `railway.toml` files, also included on the `railway` git branch.
20+
21+
A specific `nginx-railway.conf` is also used in order to specify public domains of the apis. Within docker compose we use Docker's internal DNS on our bridge network, but Railway doesn't (yet) support private networking so we use the public domains.
22+
23+
The only other consideration is setting the `PORT` environment variable for each service (80 for nginx, 3000 for node, and 8080 for golang).
24+
25+
When we provision a PostgresDB within the project, Railway automatically sets the necessary `DATABASE_URL` environment variable for the other services.
26+
27+
## Docker swarm
28+
29+
30+
31+
## Kubernetes

12-deploying-containers/Makefile renamed to 12-deploying-containers/docker-swarm/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
### DOCKER COMPOSE
2+
13
.PHONY: compose-up
24
compose-up:
35
docker compose -f docker-compose-prod.yml up
@@ -7,7 +9,11 @@ compose-up:
79
compose-up-d:
810
docker compose -f docker-compose-prod.yml up -d
911

10-
###
12+
.PHONY: compose-down
13+
compose-down:
14+
docker compose -f docker-compose-prod.yml down
15+
16+
### DOCKER SWARM
1117

1218
CIVO_SSH:="ssh://ubuntu@212.2.244.220"
1319

12-deploying-containers/docker-compose-prod.yml renamed to 12-deploying-containers/docker-swarm/docker-compose-prod.yml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ version: '3.7'
33
services:
44
client-react-nginx:
55
image: sidpalas/devops-directive-docker-course-client-react-nginx:5
6+
deploy:
7+
mode: replicated
8+
replicas: 1
9+
update_config:
10+
order: start-first
611
networks:
712
- frontend
8-
init: true
913
ports:
1014
- 80:80
1115
restart: unless-stopped
@@ -17,23 +21,37 @@ services:
1721
start_period: 10s
1822
api-node:
1923
image: sidpalas/devops-directive-docker-course-api-node:8
24+
read_only: true
25+
deploy:
26+
mode: replicated
27+
replicas: 1
28+
update_config:
29+
order: start-first
2030
networks:
2131
- frontend
2232
- backend
33+
ports:
34+
- 3000:3000
2335
init: true
2436
depends_on:
2537
- db
2638
environment:
2739
- DATABASE_URL=postgres://postgres:foobarbaz@db:5432/postgres
2840
restart: unless-stopped
2941
healthcheck:
30-
test: ["CMD", "node", "src/healthcheck.js"]
42+
test: ["CMD", "node", "/usr/src/app/healthcheck.js"]
3143
interval: 30s
3244
timeout: 5s
3345
retries: 3
3446
start_period: 10s
3547
api-golang:
3648
image: sidpalas/devops-directive-docker-course-api-golang:7
49+
read_only: true
50+
deploy:
51+
mode: replicated
52+
replicas: 1
53+
update_config:
54+
order: start-first
3755
networks:
3856
- frontend
3957
- backend
@@ -43,6 +61,8 @@ services:
4361
environment:
4462
- DATABASE_URL=postgres://postgres:foobarbaz@db:5432/postgres
4563
restart: unless-stopped
64+
ports:
65+
- 8080:8080
4666
healthcheck:
4767
test: ["CMD", "/healthcheck"]
4868
interval: 30s
@@ -53,9 +73,12 @@ services:
5373
image: postgres:15.1-alpine
5474
networks:
5575
- backend
76+
ports:
77+
- 5432:5432
5678
volumes:
5779
- pgdata:/var/lib/postgresql/data
5880
environment:
81+
- PGUSER=postgres
5982
- POSTGRES_PASSWORD=foobarbaz
6083
healthcheck:
6184
test: ["CMD-SHELL", "pg_isready"]

12-deploying-containers/docker-swarm.yml renamed to 12-deploying-containers/docker-swarm/docker-swarm.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.7'
22

33
services:
4-
client-react:
4+
client-react-nginx:
55
image: sidpalas/devops-directive-docker-course-client-react-nginx:5
66
deploy:
77
mode: replicated
@@ -20,6 +20,7 @@ services:
2020
start_period: 10s
2121
api-node:
2222
image: sidpalas/devops-directive-docker-course-api-node:8
23+
read_only: true
2324
deploy:
2425
mode: replicated
2526
replicas: 1
@@ -42,6 +43,7 @@ services:
4243
start_period: 10s
4344
api-golang:
4445
image: sidpalas/devops-directive-docker-course-api-golang:7
46+
read_only: true
4547
deploy:
4648
mode: replicated
4749
replicas: 2
@@ -50,6 +52,7 @@ services:
5052
networks:
5153
- frontend
5254
- backend
55+
init: true
5356
environment:
5457
- DATABASE_URL_FILE=/run/secrets/database-url
5558
secrets:
@@ -71,6 +74,7 @@ services:
7174
volumes:
7275
- pgdata:/var/lib/postgresql/data
7376
environment:
77+
- PGUSER=postgres
7478
- POSTGRES_PASSWORD_FILE=/run/secrets/postgres-passwd
7579
secrets:
7680
- postgres-passwd

0 commit comments

Comments
 (0)