From ff4ee381c134d7a0f56c53e3806c30990386b5db Mon Sep 17 00:00:00 2001 From: sid palas Date: Mon, 13 Feb 2023 10:44:23 -0500 Subject: [PATCH] Add description of railway deploy, update docker compose to better align with swarm config --- 12-deploying-containers/README.md | 32 ++++++++++++++++--- .../{ => docker-swarm}/Makefile | 8 ++++- .../docker-compose-prod.yml | 27 ++++++++++++++-- .../{ => docker-swarm}/docker-swarm.yml | 6 +++- 4 files changed, 65 insertions(+), 8 deletions(-) rename 12-deploying-containers/{ => docker-swarm}/Makefile (86%) rename 12-deploying-containers/{ => docker-swarm}/docker-compose-prod.yml (74%) rename 12-deploying-containers/{ => docker-swarm}/docker-swarm.yml (95%) diff --git a/12-deploying-containers/README.md b/12-deploying-containers/README.md index 1e55f6e..6e48c45 100644 --- a/12-deploying-containers/README.md +++ b/12-deploying-containers/README.md @@ -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 diff --git a/12-deploying-containers/Makefile b/12-deploying-containers/docker-swarm/Makefile similarity index 86% rename from 12-deploying-containers/Makefile rename to 12-deploying-containers/docker-swarm/Makefile index f0d59d9..85c9b22 100644 --- a/12-deploying-containers/Makefile +++ b/12-deploying-containers/docker-swarm/Makefile @@ -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" diff --git a/12-deploying-containers/docker-compose-prod.yml b/12-deploying-containers/docker-swarm/docker-compose-prod.yml similarity index 74% rename from 12-deploying-containers/docker-compose-prod.yml rename to 12-deploying-containers/docker-swarm/docker-compose-prod.yml index 039a003..85d6563 100644 --- a/12-deploying-containers/docker-compose-prod.yml +++ b/12-deploying-containers/docker-swarm/docker-compose-prod.yml @@ -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"] diff --git a/12-deploying-containers/docker-swarm.yml b/12-deploying-containers/docker-swarm/docker-swarm.yml similarity index 95% rename from 12-deploying-containers/docker-swarm.yml rename to 12-deploying-containers/docker-swarm/docker-swarm.yml index 6598727..f7c1719 100644 --- a/12-deploying-containers/docker-swarm.yml +++ b/12-deploying-containers/docker-swarm/docker-swarm.yml @@ -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