Add CI for Jan-cloud (#69)

* Add CI staging for Jan-cloud

* Update web-client/Dockerfile

switch from npm to yarn command

Co-authored-by: Louis <133622055+louis-jan@users.noreply.github.com>

* Update web-client/Dockerfile

Correct yarn build command

Co-authored-by: Louis <133622055+louis-jan@users.noreply.github.com>

---------

Co-authored-by: Hien To <tominhhien97@gmail.com>
Co-authored-by: Louis <133622055+louis-jan@users.noreply.github.com>
This commit is contained in:
hiento09 2023-09-07 10:21:06 +07:00 committed by GitHub
parent 4e202bbe63
commit a251a32528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 116 additions and 6 deletions

53
.github/workflows/ci-production.yml vendored Normal file
View File

@ -0,0 +1,53 @@
name: Jan CI Production
on:
push:
tags: ['v*.*.*']
env:
REGISTRY: ghcr.io
HASURA_WORKER_IMAGE_NAME: ${{ github.repository }}/worker
WEB_CLIENT_IMAGE_NAME: ${{ github.repository }}/web-client
jobs:
build-docker-image:
runs-on: ubuntu-latest
environment: production
permissions:
contents: read
packages: write
steps:
- name: Getting the repo
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get tag
id: tag
uses: dawidd6/action-get-tag@v1
# Build and docker image for app-backend worker
- name: Build docker image for app-backend worker
run: |
cd ./app-backend/worker
docker build -t ${{ env.REGISTRY }}/${{ env.HASURA_WORKER_IMAGE_NAME }}:${{ steps.tag.outputs.tag }} .
docker push ${{ env.REGISTRY }}/${{ env.HASURA_WORKER_IMAGE_NAME }}:${{ steps.tag.outputs.tag }}
# Get .env for FE
- name: Get .env file for build time
run: cd ./web-client && base64 -d <<< "$ENV_FILE_BASE64" > .env
shell: bash
env:
ENV_FILE_BASE64: ${{ secrets.ENV_FILE_BASE64 }}
# Build and push docker for web client
- name: Build docker image for web-client
run: |
cd ./web-client
docker build -t ${{ env.REGISTRY }}/${{ env.WEB_CLIENT_IMAGE_NAME }}:${{ steps.tag.outputs.tag }} .
docker push ${{ env.REGISTRY }}/${{ env.WEB_CLIENT_IMAGE_NAME }}:${{ steps.tag.outputs.tag }}

58
.github/workflows/ci-staging.yml vendored Normal file
View File

@ -0,0 +1,58 @@
name: Jan CI Staging
on:
push:
branches:
- stag
paths:
- 'app-backend/worker/**' # hasura worker source code
- 'web-client/**' # web client source code
env:
REGISTRY: ghcr.io
HASURA_WORKER_IMAGE_NAME: ${{ github.repository }}/worker
WEB_CLIENT_IMAGE_NAME: ${{ github.repository }}/web-client
jobs:
build-docker-image:
runs-on: ubuntu-latest
environment: staging
permissions:
contents: read
packages: write
steps:
- name: Getting the repo
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y.%m.%d')"
# Build docker image for app-backend worker
- name: Build docker image for app-backend worker
if: ${{ contains(github.event.head_commit.added, 'app-backend/worker/') }}
run: |
cd ./app-backend/worker
docker build -t ${{ env.REGISTRY }}/${{ env.HASURA_WORKER_IMAGE_NAME }}:staging-${{ steps.date.outputs.date }}.${{github.run_number}} .
docker push ${{ env.REGISTRY }}/${{ env.HASURA_WORKER_IMAGE_NAME }}:staging-${{ steps.date.outputs.date }}.${{github.run_number}}
# Get .env for FE
- name: Get .env file for build time
run: cd ./web-client && base64 -d <<< "$ENV_FILE_BASE64" > .env
shell: bash
env:
ENV_FILE_BASE64: ${{ secrets.ENV_FILE_BASE64 }}
# Build and push docker for web client
- name: Build docker image for web-client
if: ${{ contains(github.event.head_commit.added, 'web-client/') }}
run: |
cd ./web-client
docker build -t ${{ env.REGISTRY }}/${{ env.WEB_CLIENT_IMAGE_NAME }}:staging-${{ steps.date.outputs.date }}.${{github.run_number}} .
docker push ${{ env.REGISTRY }}/${{ env.WEB_CLIENT_IMAGE_NAME }}:staging-${{ steps.date.outputs.date }}.${{github.run_number}}

View File

@ -4,7 +4,8 @@ on:
push:
branches:
- main
- fix/github-page-customdomain
paths:
- 'docs/**'
# Review gh actions docs if you want to further define triggers, paths, etc
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on

View File

@ -2,11 +2,9 @@ name: Linter & Sonarqube scanner
on:
push:
branches:
- dev
- main
pull_request:
branches:
- dev
- main
jobs:

View File

@ -9,7 +9,7 @@ WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN npm install && npm i -g @nestjs/cli typescript ts-node
RUN yarn add graphql && yarn install
# 2. Rebuild the source code only when needed
FROM base AS builder
@ -18,7 +18,7 @@ COPY --from=deps /app/node_modules ./node_modules
COPY . .
# This will do the trick, use the corresponding env file for each environment.
RUN npm run build
RUN yarn build
# 3. Production image, copy all the files and run next
FROM base AS runner
@ -34,7 +34,7 @@ COPY --from=builder /app/public ./public
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
# COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json