Add description of railway deploy, update docker compose to better align with swarm config

This commit is contained in:
sid palas
2023-02-13 10:44:23 -05:00
parent 299699ffcb
commit ff4ee381c1
4 changed files with 65 additions and 8 deletions

View File

@ -1,7 +1,31 @@
# Deploying containers
So many options!
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.
- Railway
- Docker Swarm
- Kubernetes
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!
We will be deploying in 3 different ways:
## Railway.app
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.
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.
```
git fetch && git checkout railway # fetch and checkout the railway branch
```
The deployment configuration is specified via `railway.toml` files, also included on the `railway` git branch.
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.
The only other consideration is setting the `PORT` environment variable for each service (80 for nginx, 3000 for node, and 8080 for golang).
When we provision a PostgresDB within the project, Railway automatically sets the necessary `DATABASE_URL` environment variable for the other services.
## Docker swarm
## Kubernetes

View File

@ -1,3 +1,5 @@
### DOCKER COMPOSE
.PHONY: compose-up
compose-up:
docker compose -f docker-compose-prod.yml up
@ -7,7 +9,11 @@ compose-up:
compose-up-d:
docker compose -f docker-compose-prod.yml up -d
###
.PHONY: compose-down
compose-down:
docker compose -f docker-compose-prod.yml down
### DOCKER SWARM
CIVO_SSH:="ssh://ubuntu@212.2.244.220"

View File

@ -3,9 +3,13 @@ version: '3.7'
services:
client-react-nginx:
image: sidpalas/devops-directive-docker-course-client-react-nginx:5
deploy:
mode: replicated
replicas: 1
update_config:
order: start-first
networks:
- frontend
init: true
ports:
- 80:80
restart: unless-stopped
@ -17,9 +21,17 @@ services:
start_period: 10s
api-node:
image: sidpalas/devops-directive-docker-course-api-node:8
read_only: true
deploy:
mode: replicated
replicas: 1
update_config:
order: start-first
networks:
- frontend
- backend
ports:
- 3000:3000
init: true
depends_on:
- db
@ -27,13 +39,19 @@ services:
- DATABASE_URL=postgres://postgres:foobarbaz@db:5432/postgres
restart: unless-stopped
healthcheck:
test: ["CMD", "node", "src/healthcheck.js"]
test: ["CMD", "node", "/usr/src/app/healthcheck.js"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
api-golang:
image: sidpalas/devops-directive-docker-course-api-golang:7
read_only: true
deploy:
mode: replicated
replicas: 1
update_config:
order: start-first
networks:
- frontend
- backend
@ -43,6 +61,8 @@ services:
environment:
- DATABASE_URL=postgres://postgres:foobarbaz@db:5432/postgres
restart: unless-stopped
ports:
- 8080:8080
healthcheck:
test: ["CMD", "/healthcheck"]
interval: 30s
@ -53,9 +73,12 @@ services:
image: postgres:15.1-alpine
networks:
- backend
ports:
- 5432:5432
volumes:
- pgdata:/var/lib/postgresql/data
environment:
- PGUSER=postgres
- POSTGRES_PASSWORD=foobarbaz
healthcheck:
test: ["CMD-SHELL", "pg_isready"]

View File

@ -1,7 +1,7 @@
version: '3.7'
services:
client-react:
client-react-nginx:
image: sidpalas/devops-directive-docker-course-client-react-nginx:5
deploy:
mode: replicated
@ -20,6 +20,7 @@ services:
start_period: 10s
api-node:
image: sidpalas/devops-directive-docker-course-api-node:8
read_only: true
deploy:
mode: replicated
replicas: 1
@ -42,6 +43,7 @@ services:
start_period: 10s
api-golang:
image: sidpalas/devops-directive-docker-course-api-golang:7
read_only: true
deploy:
mode: replicated
replicas: 2
@ -50,6 +52,7 @@ services:
networks:
- frontend
- backend
init: true
environment:
- DATABASE_URL_FILE=/run/secrets/database-url
secrets:
@ -71,6 +74,7 @@ services:
volumes:
- pgdata:/var/lib/postgresql/data
environment:
- PGUSER=postgres
- POSTGRES_PASSWORD_FILE=/run/secrets/postgres-passwd
secrets:
- postgres-passwd