Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaosen7 committed Jul 30, 2024
2 parents 7c055fb + c0ae3d6 commit 81c311d
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 229 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ tests
deploy
build.sh
CHANGELOG.md
.github
deploy
.husky
.vscode
volumes
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: 📥 install
- name: 📥 Install dependencies
uses: ./.github/actions/setup

- name: Run check tasks with Turbo
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Docker Build

on:
push:

jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Generate Matrix
id: set-matrix
run: |
apps=$(ls -d apps/*/)
matrix="{\"include\":["
for app in $apps; do
app_name=$(basename $app)
matrix="${matrix}{\"app-dir\":\"${app_name}\",\"app-package-name\":\"@npcs/${app_name}\",\"image-name\":\"ghcr.io/${{ github.actor }}/npcs-${app_name}:latest\"},"
done
matrix="${matrix%?}]}"
echo "::set-output name=matrix::${matrix}"
build:
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Login Registry
if: github.ref == 'refs/heads/main'
run: |
echo ${{ secrets.PAT }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build Docker Image
id: docker_build
uses: docker/build-push-action@v6
with:
push: ${{ github.ref == 'refs/heads/main' && 'true' || 'false' }}
tags: ${{ matrix.image-name }}
cache-from: type=registry,ref=${{ matrix.image-name }}
cache-to: type=inline
context: .
file: ${{ secrets.DOCKERFILE }}
build-args: |
TURBO_TEAM=${{ secrets.TURBO_TEAM }}
TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}
APP_DIR=apps/${{ matrix.app-dir }}
APP_PACKAGE_NAME=${{ matrix.app-package-name }}
- run: |
echo "Docker Image ID: ${{ steps.docker_build.outputs.imageid }}"
echo "Docker Image digest: ${{ steps.docker_build.outputs.digest }}"
echo "Docker Image metadata: ${{ steps.docker_build.outputs.metadata }}"
- name: Trigger Deploy
if: github.ref == 'refs/heads/main'
run: |
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.PAT }}" \
-d "{\"event_type\":\"deploy\",\"client_payload\":{\"app\":\"${{ matrix.app-dir }}\"}}" \
https://api.github.com/repos/${{ github.repository }}/dispatches
- name: Check Deploy Event
run: |
echo "Deploy event triggered for app: ${{ matrix.app-dir }}"
38 changes: 38 additions & 0 deletions .github/workflows/docker-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Docker Deploy

on:
repository_dispatch:
types: [deploy]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Upload to VPS
uses: appleboy/scp-action@master
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT }}
source: ./deploy
target: ${{ secrets.VPS_WORK_DIR }}

- name: Execute deployment via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT }}
envs: REPO_NAME
script: |
cd ${{ secrets.VPS_WORK_DIR }}/deploy
export $(grep -v '^#' ~/.env.local | xargs)
docker compose pull ${{ github.event.client_payload.app }}
docker compose up -d ${{ github.event.client_payload.app }}
docker image prune -f
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: Monorepo Integrity
name: Integrity

on:
push:
paths:
- 'package.json'
- 'pnpm-lock.yaml'
- '.github/**'
- "package.json"
- "pnpm-lock.yaml"
- ".github/workflows/integrity.yml"

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: 📥 install
- name: 📥 Install dependencies
uses: ./.github/actions/setup

- name: 👬🏽 Check for duplicate dependencies in lock file
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Quality

on:
push:

env:
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: 📥 Install dependencies
uses: ./.github/actions/setup

- name: Run check tasks with Turbo
run: |
# To fix the file or directory not find error emmittied by prisma
pnpm turbo prisma-generate --concurrency 1
pnpm turbo typecheck
pnpm turbo lint test
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
FROM node:18-alpine AS base

ARG APP_DIR
RUN echo "APP_DIR: $APP_DIR"

ARG APP_PACKAGE_NAME
RUN echo "APP_PACKAGE_NAME: $APP_PACKAGE_NAME"

# turbo
ARG TURBO_TEAM
ENV TURBO_TEAM=${TURBO_TEAM}
RUN echo "TURBO_TEAM: $TURBO_TEAM"
ARG TURBO_TOKEN
ENV TURBO_TOKEN=${TURBO_TOKEN}
RUN echo "TURBO_TOKEN: $TURBO_TOKEN"

RUN apk update && apk add --no-cache libc6-compat

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pnpm turbo compile:watch
| Do e2e test in CI | | |
| CI file reuse | 1 | |
| CI refactor | | 1 |
| SENTRY | | |

## References

Expand Down
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ module.exports = {
enableMultipleScopes: true,
defaultScope: scopes.then((x) => (x.join(",").length > 70 ? [] : x)),
allowEmptyScopes: false,
defaultSubject: "update",
},
};
13 changes: 9 additions & 4 deletions deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

## Deploy by hand

Requirements to run `start.sh`: docker, docker compose, yq, and some environment variables.

Add your env vars to `~/.env.local`, see `.env.local.example` to get the detail. `start.sh` will auto load them.
### Cheat sheet

```bash
bash ./start.sh
# Load env vars
export $(grep -v '^#' ~/.env.local | xargs)
# Pull the latest image
docker compose pull <app>
# Restart container
docker compose up -d <app>
# Clear unused images
docker image prune -f
```

To kill all containers in current machine.
Expand Down
101 changes: 0 additions & 101 deletions deploy/start.sh

This file was deleted.

Loading

0 comments on commit 81c311d

Please sign in to comment.