From e2ba9a087477cc14a61bfd2d1a6bedc3fb9e0749 Mon Sep 17 00:00:00 2001 From: anteqkois Date: Sat, 4 May 2024 19:47:17 +0200 Subject: [PATCH] ci(ci): chore --- .dockerignore | 2 + apps/api-gateway/Dockerfile | 2 +- apps/api-gateway/deploy-docker.sh | 12 ++++++ apps/api-gateway/docker-compose.local.yml | 2 +- apps/api-gateway/docker-compose.prod.yml | 27 +++++-------- apps/api-gateway/project.json | 3 +- apps/web/Dockerfile | 7 +++- apps/web/Dockerfile-test | 2 - apps/web/deploy-docker.sh | 12 ++++++ apps/web/docker-compose.local.yml | 2 +- apps/web/docker-compose.prod.yml | 31 +++++---------- apps/web/html/hello.html | 9 ----- apps/web/project.json | 5 +-- docs/devops/ci-manual-steps.md | 46 +++++++++++++++++++++++ docs/devops/ci.md | 2 +- env.d.ts | 2 - package.json | 2 +- 17 files changed, 103 insertions(+), 65 deletions(-) create mode 100644 apps/api-gateway/deploy-docker.sh delete mode 100644 apps/web/Dockerfile-test create mode 100644 apps/web/deploy-docker.sh delete mode 100644 apps/web/html/hello.html create mode 100644 docs/devops/ci-manual-steps.md diff --git a/.dockerignore b/.dockerignore index f0ce8d3c..b135c713 100644 --- a/.dockerignore +++ b/.dockerignore @@ -13,6 +13,7 @@ tools .editorconfig .dockerignore .env +.env.* .eslintignore .gitignore .prettierignore @@ -29,3 +30,4 @@ apps/web-e2e .git *.log *.md +.next diff --git a/apps/api-gateway/Dockerfile b/apps/api-gateway/Dockerfile index 9a19a074..f42023b6 100644 --- a/apps/api-gateway/Dockerfile +++ b/apps/api-gateway/Dockerfile @@ -1,4 +1,4 @@ -FROM linkerry-base:latest AS builder +FROM linkerry/base:latest AS builder ARG NODE_ENV ARG BUILD_FLAG diff --git a/apps/api-gateway/deploy-docker.sh b/apps/api-gateway/deploy-docker.sh new file mode 100644 index 00000000..4efd21b4 --- /dev/null +++ b/apps/api-gateway/deploy-docker.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +# Build images +docker build -t linkerry/api -f ./apps/api-gateway/Dockerfile . --platform=linux/amd64 + +# Push docker image to container registry +docker login -u "$CONTAINER_REGISTRY_USERNAME" -p "$CONTAINER_REGISTRY_PASSWORD" "$CONTAINER_REGISTRY_ADDRESS" + +docker tag linkerry/api registry.digitalocean.com/linkerry/api:"$ENV" +docker push registry.digitalocean.com/linkerry/api:"$ENV" diff --git a/apps/api-gateway/docker-compose.local.yml b/apps/api-gateway/docker-compose.local.yml index 5348f87b..31226b6d 100644 --- a/apps/api-gateway/docker-compose.local.yml +++ b/apps/api-gateway/docker-compose.local.yml @@ -6,7 +6,7 @@ services: build: context: ./ cache_from: - - linkerry-base:latest + - linkerry/base:latest dockerfile: ./Dockerfile args: NODE_ENV: 'production' diff --git a/apps/api-gateway/docker-compose.prod.yml b/apps/api-gateway/docker-compose.prod.yml index 33f23e4c..cf2a3933 100644 --- a/apps/api-gateway/docker-compose.prod.yml +++ b/apps/api-gateway/docker-compose.prod.yml @@ -2,29 +2,22 @@ version: '3.8' services: api-gateway: - container_name: api-gateway - build: - context: ./ - cache_from: - - linkerry-base:latest - dockerfile: ./Dockerfile - args: - NODE_ENV: 'production' - BUILD_FLAG: '' - image: api-gateway:latest - env_file: - - ../../.env + image: registry.digitalocean.com/linkerry/api:dev ports: - - 3001:3001 + - ${VIRTUAL_PORT}:${VIRTUAL_PORT} + env_file: + - .env environment: - NODE_ENV: 'production' - PORT: 3001 - restart: on-failure + - VIRTUAL_HOST=${VIRTUAL_HOST} + - LETSENCRYPT_HOST=${LETSENCRYPT_HOST} + - LETSENCRYPT_EMAIL=anteqkois@gmail.com + - VIRTUAL_PORT=${VIRTUAL_PORT} + restart: unless-stopped redis: image: redis:alpine container_name: redis env_file: - - ../../.env + - .env command: redis-server --appendonly yes --replica-read-only no --requirepass "$${REDIS_PASSWORD:?REDIS_PASSWORD variable is not set}" restart: always ports: diff --git a/apps/api-gateway/project.json b/apps/api-gateway/project.json index 3c0dca3a..e2d1a30e 100644 --- a/apps/api-gateway/project.json +++ b/apps/api-gateway/project.json @@ -6,8 +6,7 @@ "tags": [], "targets": { "docker-compose": { - "command": " echo \"api-gateway\" was changed" - // "command": "docker compose -f ./apps/api-gateway/docker-compose.local.yml up -d" + "command": "bash ./apps/api-gateway/deploy-docker.sh" }, "build-with-engine": { "command": "webpack-cli build", diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile index be185a5a..540a0d7a 100644 --- a/apps/web/Dockerfile +++ b/apps/web/Dockerfile @@ -1,11 +1,14 @@ -FROM linkerry-base:latest AS builder +FROM linkerry/base:latest AS builder ARG NODE_ENV ARG BUILD_FLAG WORKDIR /app/builder -RUN npx nx run web:build ${BUILD_FLAG} || echo "nx run web:build failed" +# RUN ls apps/web/.next -a +RUN npx nx run web:build -d || echo "nx run web:build failed" +# RUN ls apps/web/.next -a +# RUN ls apps/web/.next/standalone FROM node:lts-alpine AS runner diff --git a/apps/web/Dockerfile-test b/apps/web/Dockerfile-test deleted file mode 100644 index 02f4d72b..00000000 --- a/apps/web/Dockerfile-test +++ /dev/null @@ -1,2 +0,0 @@ -FROM nginx:latest -COPY ./apps/web/html/hello.html /usr/share/nginx/html/hello.html diff --git a/apps/web/deploy-docker.sh b/apps/web/deploy-docker.sh new file mode 100644 index 00000000..fdd6ce9c --- /dev/null +++ b/apps/web/deploy-docker.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +# Build images +docker build -t linkerry/web -f ./apps/web/Dockerfile . --platform=linux/amd64 --progress=plain + +# Push docker image to container registry +docker login -u "$CONTAINER_REGISTRY_USERNAME" -p "$CONTAINER_REGISTRY_PASSWORD" "$CONTAINER_REGISTRY_ADDRESS" + +docker tag linkerry/web registry.digitalocean.com/linkerry/web:"$ENV" +docker push registry.digitalocean.com/linkerry/web:"$ENV" diff --git a/apps/web/docker-compose.local.yml b/apps/web/docker-compose.local.yml index 28f46f7c..db17d454 100644 --- a/apps/web/docker-compose.local.yml +++ b/apps/web/docker-compose.local.yml @@ -6,7 +6,7 @@ services: build: context: ./ cache_from: - - linkerry-base:latest + - linkerry/base:latest dockerfile: ./Dockerfile args: NODE_ENV: 'production' diff --git a/apps/web/docker-compose.prod.yml b/apps/web/docker-compose.prod.yml index 51383f47..5fbaf094 100644 --- a/apps/web/docker-compose.prod.yml +++ b/apps/web/docker-compose.prod.yml @@ -1,30 +1,17 @@ version: '3.8' - services: web: - container_name: web - build: - context: ./ - cache_from: - - linkerry-base:latest - dockerfile: ./Dockerfile - args: - NODE_ENV: 'production' - BUILD_FLAG: '' - image: web:latest - env_file: - - ../../.env + image: registry.digitalocean.com/linkerry/web:dev ports: - - 3000:3000 + - ${VIRTUAL_PORT}:${VIRTUAL_PORT} + env_file: + - .env environment: - NODE_ENV: 'production' - networks: - - proxy - restart: on-failure - -volumes: - redis: - driver: local + - VIRTUAL_HOST=${VIRTUAL_HOST} + - LETSENCRYPT_HOST=${LETSENCRYPT_HOST} + - LETSENCRYPT_EMAIL=anteqkois@gmail.com + - VIRTUAL_PORT=${VIRTUAL_PORT} + restart: unless-stopped networks: default: diff --git a/apps/web/html/hello.html b/apps/web/html/hello.html deleted file mode 100644 index a71b99af..00000000 --- a/apps/web/html/hello.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - Hello World! - - -

This is an example of a simple HTML page served from the Nginx container.

- - diff --git a/apps/web/project.json b/apps/web/project.json index b8e0be64..fab604f8 100644 --- a/apps/web/project.json +++ b/apps/web/project.json @@ -7,10 +7,7 @@ "// targets": "to see all targets run: nx show project web --web", "targets": { "docker-compose": { - "command": "bash ./apps/web/build_and_deploy.sh" - // "command": "docker build -t linkerry/test -f ./apps/web/Dockerfile-test ." - // "command": " echo \"web\" was changed" - // "command": "docker compose -f ./apps/web/docker-compose.local.yml up -d" + "command": "bash ./apps/web/deploy-docker.sh" } } } diff --git a/docs/devops/ci-manual-steps.md b/docs/devops/ci-manual-steps.md new file mode 100644 index 00000000..630d0440 --- /dev/null +++ b/docs/devops/ci-manual-steps.md @@ -0,0 +1,46 @@ +Run loccally `nx run web:docker-compose` + +Connect to server `ssh root@64.226.97.74` + +Install docker `https://docs.docker.com/engine/install/ubuntu/` + + +Setup proxy +`git clone --recurse-submodules https://github.com/evertramos/nginx-proxy-automation.git proxy` +`cd proxy/bin && ./fresh-start.sh --yes --skip-docker-image-check -e anteqkois@gmail.com` +test +`./test.sh api.linkerry.com` + +Create dir like a domaina: `mkdir api.linkerry.com` + +Create docker-compose file: `cd api.linkerry.com && touch docker-compose.yml` + +Copy and create env file + +Login to docker container registry +`docker login -u "$CONTAINER_REGISTRY_USERNAME" -p "$CONTAINER_REGISTRY_PASSWORD" "$CONTAINER_REGISTRY_ADDRESS"` + +Docker compose: +``` +version: '3.8' +services: + web: + image: registry.digitalocean.com/linkerry/web:dev + ports: + - ${VIRTUAL_PORT}:${VIRTUAL_PORT} + env_file: + - .env + environment: + - VIRTUAL_HOST=${VIRTUAL_HOST} + - LETSENCRYPT_HOST=${LETSENCRYPT_HOST} + - LETSENCRYPT_EMAIL=anteqkois@gmail.com + - VIRTUAL_PORT=${VIRTUAL_PORT} + restart: unless-stopped +networks: + default: + external: + name: ${NETWORK:-proxy} +``` + +start docker compose +`docker compose -f ./docker-compose.yml up -d` diff --git a/docs/devops/ci.md b/docs/devops/ci.md index 67598a59..dd3dcc6f 100644 --- a/docs/devops/ci.md +++ b/docs/devops/ci.md @@ -1,5 +1,5 @@ # build base docker image -`docker build . -t linkerry-base:latest` +`docker build . -t linkerry/base:latest` # build and run server docker compose `docker compose -f ./apps/api-gateway/docker-compose.local.yml up -d` diff --git a/env.d.ts b/env.d.ts index 53e4a26e..76d9011f 100644 --- a/env.d.ts +++ b/env.d.ts @@ -3,8 +3,6 @@ declare global { interface ProcessEnv { // common PORT_API_GATEWAY: string, - PORT_EXTERNAL_ALERTS: string, - PORT_CONDITION_EVENT_CONSUMER: string, KAFKA_CONDITION_GROUP_ID: string, KAFKA_CONDITION_TOPIC_NAME: string, diff --git a/package.json b/package.json index 3f17d2bd..10b1e1e3 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "registry": "sleep 3 && make publish-connectors & npx nx local-registry", "ngrok": "ngrok http --domain=fairly-winning-chamois.ngrok-free.app 3001", "stripe": "stripe listen --forward-to localhost:3001/api/v1/stripe/webhook", - "docker-base": "docker build . -t linkerry-base:latest", + "docker-base": "docker build . -t linkerry/base:latest --platform=linux/amd64", "docker-api": "docker compose -f ./apps/api-gateway/docker-compose.local.yml up -d", "docker-web": "docker compose -f ./apps/web/docker-compose.local.yml up -d" },