Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Deploy Docker Images on remote VM #31

Merged
merged 61 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
697c167
feat(ci): init deployment workflow
Jun 7, 2024
7295505
feat(ci): enable action for push on dev branch
Jun 7, 2024
9bc853d
fix(ci): use correct branch name
Jun 7, 2024
2b33be8
fix(ci): update github env secret names
Jun 7, 2024
084017c
feat(ci): test remote ssh command
Jun 7, 2024
95445a0
refactor(ci): rename dev docker compose file to docker-compose.local.yml
jomunker Jun 7, 2024
6a6c5e7
feat(ci): add dev docker compose file
jomunker Jun 7, 2024
cf94b8e
feat(ci): try to login to ghcrio container reg remotely
Jun 7, 2024
1c91a68
fix(ci): change secret var name
Jun 7, 2024
4db0569
feat(ci): pull latest docker images remotely
Jun 7, 2024
68338b7
feat(ci): deploy container images on remote vm
Jun 7, 2024
e7b8f36
fix(ci): fix remote working dir
Jun 7, 2024
9f81225
feat(ci): stop remote script execution on failure
Jun 7, 2024
c2d8807
fix(ci): fix remote cd cmd
Jun 7, 2024
bd8b280
fix(ci): remove redundant docker .env file references
Jun 7, 2024
42b6d1c
refactor(ci): ensure container startup
Jun 7, 2024
af8367b
fix(ci): use non-standard db port
Jun 7, 2024
584ce3b
fix(compose): use DATABASE_PORT variable
Jun 10, 2024
56955ee
refactor(ci): update action name
Jun 10, 2024
fb8f31b
feat(ci): deploy based on file changes
Jun 10, 2024
3307b03
refactor(ci): ensure containers are recreated upon deployment
Jun 11, 2024
3e31425
feat(ci): remove build context from web
jomunker Jun 11, 2024
185f481
feat(ci): remove unnecessary volumes
jomunker Jun 11, 2024
1d4bf1a
feat(ci): adjust cms secrets
jomunker Jun 11, 2024
3bcf533
feat(ci): update .env.example
jomunker Jun 11, 2024
6169d1c
feat(ci): scp database files to VM
Jun 11, 2024
a00d5ac
fix(ci): web crashing because auth secret was missing in production mode
jomunker Jun 11, 2024
5000400
feat(ci): change database port back to 3306
jomunker Jun 14, 2024
7ceef05
feat(ci): add feature/deployment-vm to on push trigger for cms build …
jomunker Jun 14, 2024
ed1cf56
feat(ci): deploy branch docker image tag
Jun 14, 2024
497b818
fix(ci): revert docker image tag override
Jun 14, 2024
a8ca125
feat(cms): add cms prefix to url on non local envs
jomunker Jun 14, 2024
ea03308
fix(ci): pull branch image name
Jun 14, 2024
a406c3a
fix(ci): avoid copying db files
Jun 14, 2024
40db849
feat(cms): add URL variable
Jun 14, 2024
6cb68ba
feat(cms): update cors to allow preview.vim.org
Jun 14, 2024
b9fedd6
feat(cms): add admin flags to disable promotional features
jomunker Jun 15, 2024
f4a8b86
feat: add environment variables to set telemetry and update flags of cms
jomunker Jun 15, 2024
54b932c
feat(cms): hardcode url
jomunker Jun 15, 2024
9dda23c
fix(cms): avoid setting strapi url on NODE_ENV=development
Jun 16, 2024
446cd91
refactor: remove unnecessary compose version
Jun 16, 2024
dbccfe4
feat(cms): set CMS_URL at buildtime
Jun 16, 2024
4ec94f5
fix(cms): ensure CMS_URL env var is used
Jun 16, 2024
d29c1b8
feat(ci): print CMS_URL in CMS prod build
Jun 16, 2024
5d8123b
fix(ci): convert CMS_URL to env var instead of secret
Jun 16, 2024
4fd62ae
test(ci): print env var
Jun 16, 2024
0ae9db7
fix(ci): access CMS_URL as repo var
Jun 16, 2024
a0c742a
feat(ci): run deployment after images were pushed
Jun 16, 2024
a5f177a
feat(ci): allow manual run of deploy
Jun 16, 2024
70711b2
refactor(ci): remove workflow_dispatch
Jun 16, 2024
3b6dc13
refactor(ci): clean up log statement
Jun 16, 2024
2682903
refactor(ci): remove branch rule on workflow_run
Jun 16, 2024
279599e
feat(ci): deploy on dev branches
Jun 17, 2024
df5d60e
refactor(ci): avoid quotes in workflow_run
Jun 17, 2024
adbbcb9
refactor(ci): remove temporary branch rules
Jun 17, 2024
37065a2
chore(ci): add nginx configuration files
jomunker Jun 17, 2024
fa07b97
feat(build): change NODE_ENV=development
FabianUntermoser Jun 18, 2024
0886094
refactor(build): remove CMS_URL env var not needed at runtime
Jun 18, 2024
6b30221
feat(ci): run actions for 'feature/*' branches
Jun 18, 2024
520ab92
feat(ci): add temporary deploy rule
Jun 18, 2024
5b7df30
refactor(ci): remove temporary deployment rules
Jun 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
NODE_ENV=development

DATABASE_CLIENT=mysql2
DATABASE_USERNAME=vim
DATABASE_PASSWORD=super-secret
DATABASE_PORT=3306
DATABASE_SSL=false

WEB_DATABASE_NAME=vim
CMS_DATABASE_NAME=vim_cms
NEXT_PRIVATE_STANDALONE=true
NEXTAUTH_SECRET=testsecret

CMS_DATABASE_NAME=vim_cms
CMS_HOST=0.0.0.0
CMS_PORT=1337
CMS_APP_KEYS=testkey1,testkey2
CMS_API_TOKEN_SALT=testtoken
CMS_ADMIN_JWT_SECRET=testsecret
CMS_JWT_SECRET=testsecret
CMS_TRANSFER_TOKEN_SALT=testtoken
CMS_DISABLE_UPDATE_NOTIFICATION=false
CMS_TELEMETRY_DISABLED=true
11 changes: 5 additions & 6 deletions .github/workflows/build-push-cms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ on:
branches:
- main
- development
paths:
- cms/**
workflow_dispatch:
- 'feature/**'

jobs:
push_to_registries:
Expand All @@ -19,14 +17,14 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
Expand All @@ -37,7 +35,7 @@ jobs:
type=semver,pattern={{version}}
images: |
ghcr.io/${{ github.repository }}/cms

- name: Build and push Docker images
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
Expand All @@ -46,3 +44,4 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: CMS_URL=${{vars.CMS_URL}}
8 changes: 4 additions & 4 deletions .github/workflows/build-push-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ on:
branches:
- main
- development
- 'feature/**'
paths:
- web/**
workflow_dispatch:

jobs:
push_to_registries:
Expand All @@ -19,14 +19,14 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
Expand All @@ -37,7 +37,7 @@ jobs:
type=semver,pattern={{version}}
images: |
ghcr.io/${{ github.repository }}/web

- name: Build and push Docker images
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/deploy-vm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Deploy Docker Images

on:
pull_request:
branches:
- main
- development
workflow_run:
workflows:
- Build and Push Web Docker Image
- Build and Push CMS Docker Image
branches:
- development
types:
- completed

jobs:
deploy:
runs-on: ubuntu-latest

steps:

- name: Checkout code
uses: actions/checkout@v2

- name: setup environment file
run: |
test -f .env || cp .env.example .env

- name: copy files to server
uses: appleboy/scp-action@v0.1.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
source: "./docker-compose.dev.yml,./.env"
target: "~/${{ github.event.repository.name }}/"

- name: pull & start container images
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script_stop: true
script: |
cd ~/${{ github.event.repository.name }}/
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{github.actor}} --password-stdin
docker compose -f docker-compose.dev.yml pull
docker compose -f docker-compose.dev.yml down
docker compose -f docker-compose.dev.yml up -d --wait --no-build --force-recreate
docker compose -f docker-compose.dev.yml logs -t -n 50
1 change: 1 addition & 0 deletions .github/workflows/verify-cms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
- development
- 'feature/**'
paths:
- cms/**
pull_request:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/verify-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ on:
branches:
- main
- development
- 'feature/**'
paths:
- web/**
pull_request:
branches:
- main
- development
- 'feature/**'
paths:
- web/**

Expand Down
4 changes: 4 additions & 0 deletions cms/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
STRAPI_DISABLE_UPDATE_NOTIFICATION=false
STRAPI_TELEMETRY_DISABLED=true
NODE_ENV=development

HOST=0.0.0.0
PORT=1337
APP_KEYS="toBeModified1,toBeModified2"
Expand Down
4 changes: 4 additions & 0 deletions cms/Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev l
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

ARG CMS_URL
ENV CMS_URL=${CMS_URL}
RUN echo "CMS_URL=$CMS_URL"

WORKDIR /opt/
COPY package.json package-lock.json ./
RUN npm install -g node-gyp
Expand Down
3 changes: 2 additions & 1 deletion cms/config/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default ({ env }) => ({
},
},
flags: {
nps: env.bool("FLAG_NPS", true),
nps: env.bool("FLAG_NPS", false),
promoteEE: env.bool("FLAG_EE", false),
},
watchIgnoreFiles: ["**/config/sync/**"],
});
2 changes: 1 addition & 1 deletion cms/config/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = [
{
name: "strapi::cors",
config: {
origin: ["http://localhost:3000", "http://web:3000", "http://localhost:1337", "http://cms:1337"],
origin: ["http://localhost:3000", "http://web:3000", "http://localhost:1337", "http://cms:1337", "http://preview.vim.org"],
methods: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"],
headers: ["Content-Type", "Authorization", "Origin", "Accept"],
keepHeaderOnError: true,
Expand Down
1 change: 1 addition & 0 deletions cms/config/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default ({ env }) => ({
host: env("HOST", "0.0.0.0"),
port: env.int("PORT", 1337),
url: env("NODE_ENV") === "development" ? "" : env("CMS_URL"),
app: {
keys: env.array("APP_KEYS"),
},
Expand Down
64 changes: 64 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
services:
web:
container_name: web
image: ghcr.io/vim/website_next_generation/web:${TAG:-development}
FabianUntermoser marked this conversation as resolved.
Show resolved Hide resolved
environment:
- CMS_API=http://cms:1337/api
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
ports:
- 3000:3000
networks:
- vim_network

db:
container_name: db
image: mysql:8
restart: unless-stopped
environment:
- MYSQL_ROOT_PASSWORD=${DATABASE_PASSWORD}
- MYSQL_USER=${DATABASE_USERNAME}
- MYSQL_PASSWORD=${DATABASE_PASSWORD}
- MYSQL_DATABASE=${CMS_DATABASE_NAME}
volumes:
- vim-cms-data:/var/lib/mysql
- ./db/docker-scripts:/docker-entrypoint-initdb.d
ports:
- ${DATABASE_PORT}:3306
FabianUntermoser marked this conversation as resolved.
Show resolved Hide resolved
networks:
- vim_network

cms:
container_name: strapi
image: ghcr.io/vim/website_next_generation/cms:${TAG:-development}
FabianUntermoser marked this conversation as resolved.
Show resolved Hide resolved
restart: unless-stopped
environment:
DATABASE_CLIENT: ${DATABASE_CLIENT}
DATABASE_HOST: db
DATABASE_PORT: ${DATABASE_PORT}
DATABASE_NAME: ${CMS_DATABASE_NAME}
DATABASE_USERNAME: ${DATABASE_USERNAME}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
DATABASE_SSL: false
HOST: ${CMS_HOST}
PORT: ${CMS_PORT}
APP_KEYS: ${CMS_APP_KEYS}
API_TOKEN_SALT: ${CMS_API_TOKEN_SALT}
ADMIN_JWT_SECRET: ${CMS_ADMIN_JWT_SECRET}
TRANSFER_TOKEN_SALT: ${CMS_TRANSFER_TOKEN_SALT}
JWT_SECRET: ${CMS_JWT_SECRET}
STRAPI_DISABLE_UPDATE_NOTIFICATION: ${CMS_DISABLE_UPDATE_NOTIFICATION}
STRAPI_TELEMETRY_DISABLED: ${CMS_TELEMETRY_DISABLED}
ports:
- 1337:1337
networks:
- vim_network
depends_on:
- db

volumes:
vim-cms-data:

networks:
vim_network:
name: vim_network
driver: bridge
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3"
services:
web:
container_name: web
Expand Down Expand Up @@ -29,7 +28,7 @@ services:
- vim-cms-data:/var/lib/mysql
- ./db/docker-scripts:/docker-entrypoint-initdb.d
ports:
- 3306:3306
- ${DATABASE_PORT}:3306
networks:
FabianUntermoser marked this conversation as resolved.
Show resolved Hide resolved
- vim_network

Expand All @@ -51,6 +50,8 @@ services:
ADMIN_JWT_SECRET: ${CMS_ADMIN_JWT_SECRET}
APP_KEYS: ${CMS_APP_KEYS}
NODE_ENV: ${NODE_ENV}
STRAPI_DISABLE_UPDATE_NOTIFICATION: false
STRAPI_TELEMETRY_DISABLED: true
volumes:
- ./cms/config:/opt/app/config
- ./cms/src:/opt/app/src
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: clean build run logsmake

DC=docker compose -f .development.docker-compose.yml
DC=docker compose -f docker-compose.local.yml

default: help
init: init-env check-env install
Expand Down
9 changes: 9 additions & 0 deletions nginx/conf.d/upstream.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Strapi server
upstream strapi {
server 127.0.0.1:1337;
}

# NextJS server
upstream nextjs {
server 127.0.0.1:3000;
}
Loading
Loading