Skip to content

Commit

Permalink
ci(ci): chore
Browse files Browse the repository at this point in the history
  • Loading branch information
anteqkois committed May 4, 2024
1 parent fcf2938 commit e2ba9a0
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 65 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tools
.editorconfig
.dockerignore
.env
.env.*
.eslintignore
.gitignore
.prettierignore
Expand All @@ -29,3 +30,4 @@ apps/web-e2e
.git
*.log
*.md
.next
2 changes: 1 addition & 1 deletion apps/api-gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM linkerry-base:latest AS builder
FROM linkerry/base:latest AS builder

ARG NODE_ENV
ARG BUILD_FLAG
Expand Down
12 changes: 12 additions & 0 deletions apps/api-gateway/deploy-docker.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion apps/api-gateway/docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
build:
context: ./
cache_from:
- linkerry-base:latest
- linkerry/base:latest
dockerfile: ./Dockerfile
args:
NODE_ENV: 'production'
Expand Down
27 changes: 10 additions & 17 deletions apps/api-gateway/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
- [email protected]
- 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:
Expand Down
3 changes: 1 addition & 2 deletions apps/api-gateway/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions apps/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 0 additions & 2 deletions apps/web/Dockerfile-test

This file was deleted.

12 changes: 12 additions & 0 deletions apps/web/deploy-docker.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion apps/web/docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
build:
context: ./
cache_from:
- linkerry-base:latest
- linkerry/base:latest
dockerfile: ./Dockerfile
args:
NODE_ENV: 'production'
Expand Down
31 changes: 9 additions & 22 deletions apps/web/docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -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}
- [email protected]
- VIRTUAL_PORT=${VIRTUAL_PORT}
restart: unless-stopped

networks:
default:
Expand Down
9 changes: 0 additions & 9 deletions apps/web/html/hello.html

This file was deleted.

5 changes: 1 addition & 4 deletions apps/web/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
46 changes: 46 additions & 0 deletions docs/devops/ci-manual-steps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Run loccally `nx run web:docker-compose`

Connect to server `ssh [email protected]`

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 [email protected]`
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}
- [email protected]
- VIRTUAL_PORT=${VIRTUAL_PORT}
restart: unless-stopped
networks:
default:
external:
name: ${NETWORK:-proxy}
```

start docker compose
`docker compose -f ./docker-compose.yml up -d`
2 changes: 1 addition & 1 deletion docs/devops/ci.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 0 additions & 2 deletions env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit e2ba9a0

Please sign in to comment.