Skip to content

Commit

Permalink
Merge pull request #34 from J-Hoplin/dev
Browse files Browse the repository at this point in the history
Production 0127
  • Loading branch information
J-Hoplin authored Jan 27, 2024
2 parents dee3425 + 13eba99 commit 51a255d
Show file tree
Hide file tree
Showing 88 changed files with 3,224 additions and 355 deletions.
27 changes: 27 additions & 0 deletions .docker.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="mysql://root:hoplin1234!@db:3306/judge?schema=public"

ADMIN_EMAIL="hoplin.dev@gmail.com"
ADMIN_PW = "admin"

JWT_SECRET="SECRET"

JUDGE_SERVER_ENDPOINT=""

ENV=""
PORT=""

# AWS
AWS_REGION=""
AWS_ACCESS_ID=""
AWS_ACCESS_SECRET=""
AWS_SQS_QUEUE=""
AWS_S3_BUCKET=""

# Sentry
SENTRY_DSN=""
15 changes: 14 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,17 @@ ADMIN_PW = "admin"

JWT_SECRET="SECRET"

JUDGE_SERVER_ENDPOINT="a"
JUDGE_SERVER_ENDPOINT=""

ENV=""
PORT=""

# AWS
AWS_REGION=""
AWS_ACCESS_ID=""
AWS_ACCESS_SECRET=""
AWS_SQS_QUEUE=""
AWS_S3_BUCKET=""

# Sentry
SENTRY_DSN=""
158 changes: 123 additions & 35 deletions .github/workflows/pre-test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
name: CI-Unit-Test
name: CI-Pull-Request-Pretest
on:
pull_request:
branches:
- dev
workflow_call:
inputs:
build_id:
required: true
type: number
deploy_target:
required: true
type: string
run-name: Unit/E2E test of ${{ github.ref_name }} by ${{ github.actor }}
jobs:
unit-testing:
build:
name: Application Build Test & Set up & Initialize Test Database Server
runs-on: ubuntu-latest
steps:
# Checkout repository codes
Expand All @@ -24,6 +17,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn
- name: Initialize .ci.env
run: |
touch .ci.env
Expand All @@ -32,18 +26,70 @@ jobs:
echo "ADMIN_PW=${{secrets.ADMIN_PW}}" >> .ci.env
echo "JWT_SECRET=${{secrets.JWT_SECRET}}" >> .ci.env
echo "JUDGE_SERVER_ENDPOINT=${{secrets.JUDGE_SERVER_ENDPOINT}}" >> .ci.env
echo "AWS_REGION"=${{secrets.AWS_REGION}}>> .ci.env
echo "AWS_ACCESS_ID=${{secrets.AWS_ACCESS_ID}}" >> .ci.env
echo "AWS_ACCESS_SECRET=${{secrets.AWS_ACCESS_SECRET}}" >> .ci.env
echo "AWS_SQS_QUEUE=${{secrets.AWS_SQS_QUEUE}}" >> .ci.env
echo "AWS_S3_BUCKET=${{secrets.AWS_S3_BUCKET}}" >> .ci.env
- name: Install Node.js Dependencies
run: npm install --force
- name: Install dotenv-cli for dotenv cli
run: npm install -g dotenv-cli
run: yarn install --force
- name: Install dotenv-cli for CI script
run: yarn global add dotenv-cli
- id: build-phase
name: Check Nest.js Application Build
continue-on-error: true
run: yarn build
# Push Prisma Schema to test DB
- name: Initialize Prisma Client
run: npm run ci:init
run: yarn ci:init
# Preserve Artifacts for test
- name: Preserve Artifacts
uses: actions/upload-artifact@v4
with:
name: build-result
path: .
- name: 'Discord Alert - Success'
if: steps.build-phase.outcome == 'success'
uses: rjstone/discord-webhook-notify@v1
with:
severity: info
details: 'Build & Setup: Success'
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
- name: 'Discord Alert - Failed'
if: steps.build-phase.outcome != 'success'
uses: rjstone/discord-webhook-notify@v1
with:
severity: error
details: 'Build & Setup: Fail'
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
- name: 'Fail check'
if: steps.build-phase.outcome != 'success'
run: exit1

unit-testing:
needs: build
runs-on: ubuntu-latest
steps:
# Setup environment for Node.js 18
- name: Node.js version 18 Environment setting
uses: actions/setup-node@v4
with:
node-version: 18
- name: Mount volume of pre-build
uses: actions/download-artifact@v4
with:
name: build-result
path: .
- name: Grant Permission to artifacts
run: chmod -R 777 .
- name: Install dotenv-cli for CI script
run: yarn global add dotenv-cli
- id: unit-test-phase
name: Run Unit Test
run: npm run ci:unit
continue-on-error: true
run: yarn ci:unit
- name: 'Discord Alert - Success'
if: steps.unit-test-phase.outcome == 'success'
continue-on-error: true
uses: rjstone/discord-webhook-notify@v1
with:
severity: info
Expand All @@ -56,37 +102,33 @@ jobs:
severity: error
details: 'Unit Test Result: Fail'
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
- name: 'Fail check'
if: steps.unit-test-phase.outcome != 'success'
run: exit1

e2e-testing:
needs: unit-testing
needs: build
runs-on: ubuntu-latest
steps:
- name: Repository Checkout
uses: actions/checkout@v4
- name: Node.js version 18 Environment setting
uses: actions/setup-node@v4
with:
node-version: 18
- name: Initialize .ci.env
run: |
touch .ci.env
echo "DATABASE_URL=${{ secrets.DATABASE_URL}}" >> .ci.env
echo "ADMIN_EMAIL=${{secrets.ADMIN_EMAIL}}" >> .ci.env
echo "ADMIN_PW=${{secrets.ADMIN_PW}}" >> .ci.env
echo "JWT_SECRET=${{secrets.JWT_SECRET}}" >> .ci.env
echo "JUDGE_SERVER_ENDPOINT=${{secrets.JUDGE_SERVER_ENDPOINT}}" >> .ci.env
- name: Install Node.js Dependencies
run: npm install --force
- name: Install dotenv-cli for dotenv cli
run: npm install -g dotenv-cli
- name: Initialize Prisma Client
run: npm run ci:init
- name: Mount volume of pre-build
uses: actions/download-artifact@v4
with:
name: build-result
path: .
- name: Grant Permission to artifacts
run: chmod -R 777 .
- name: Install dotenv-cli for CI script
run: yarn global add dotenv-cli
- id: e2e-test-phase
name: Run E2E Test
run: npm run ci:e2e
continue-on-error: true
run: yarn ci:e2e
- name: 'Discord Alert - Success'
if: steps.e2e-test-phase.outcome == 'success'
continue-on-error: true
uses: rjstone/discord-webhook-notify@v1
with:
severity: info
Expand All @@ -99,3 +141,49 @@ jobs:
severity: error
details: 'E2E Test Result: Failed'
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
- name: 'Fail check'
if: steps.e2e-test-phase.outcome != 'success'
run: exit1

tear-down:
needs: [unit-testing, e2e-testing]
runs-on: ubuntu-latest
steps:
- name: Node.js version 18 Environment setting
uses: actions/setup-node@v4
with:
node-version: 18
- name: Mount volume of pre-build
uses: actions/download-artifact@v4
with:
name: build-result
path: .
- name: Grant Permission to artifacts
run: chmod -R 777 .
- name: Install dotenv-cli for CI script
run: yarn global add dotenv-cli
- id: tear-down-phase
name: Test Database tear-down
continue-on-error: true
run: dotenv -e .ci.env -- node node_modules/prisma/build/index.js db push --force-reset
- uses: geekyeggo/delete-artifact@v4
with:
name: build-result
token: ${{secrets.TOKEN}}
- name: 'Discord Alert - Success'
if: steps.tear-down-phase.outcome == 'success'
uses: rjstone/discord-webhook-notify@v1
with:
severity: info
details: 'Test DB Tear down: Success'
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
- name: 'Discord Alert - Fail'
if: steps.tear-down-phase.outcome != 'success'
uses: rjstone/discord-webhook-notify@v1
with:
severity: error
details: 'Test DB Tear down: Failed'
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
- name: 'Fail check'
if: steps.tear-down-phase.outcome != 'success'
run: exit1
58 changes: 58 additions & 0 deletions .github/workflows/production-dockerize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI-Production-Dockerize
on:
push:
branches:
- production
run-name: Dockerize of production version. Triggerd by ${{github.actor}}
jobs:
dockerize:
name: Dockerize and upload
runs-on: ubuntu-latest
steps:
# Checkout repository code
- name: Repository Checkout
uses: actions/checkout@v4
# Set Node.js version environment
- name: Node.js version 18 Environment setting
uses: actions/setup-node@v4
with:
node-version: 18
# Install dependencies
- name: Install Dependencies
run: npm install --force
- name: Check Build Status
run: npm run build
- name: Setup QEMU for multiplatform build
uses: docker/setup-qemu-action@v3
- name: Setup docker buildx and set platform
uses: docker/setup-buildx-action@v3
- name: Docker Login
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}
- id: build-n-push
name: Build and Push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: hoplin-dev/online-judge:latest
platforms: linux/amd64,linux/arm64
- name: 'Discord Alert - Success'
if: steps.build-n-push.outcome == 'success'
uses: rjstone/discord-webhook-notify@v1
with:
severity: info
details: 'Docker Deploy Success (linux/amd64, linux/arm64)'
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
- name: 'Discord Alert - Fail'
if: steps.build-n-push.outcome != 'success'
uses: rjstone/discord-webhook-notify@v1
with:
severity: error
details: 'Docker Deploy Failed'
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
- name: 'Fail check'
if: steps.build-n-push.outcome != 'success'
run: exit1
9 changes: 0 additions & 9 deletions .platform/hooks/predeploy/01_database_init.sh

This file was deleted.

2 changes: 2 additions & 0 deletions .platform/hooks/predeploy/01_databse_migration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash

4 changes: 4 additions & 0 deletions .platform/hooks/predeploy/02_database_client_generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

# Do not modify
node node_modules/prisma/build/index.js generate
7 changes: 7 additions & 0 deletions .platform/nginx/conf.d/base.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
server {
listen 80;

location / {
proxy_pass http://127.0.0.1:3000;
}
}
1 change: 1 addition & 0 deletions .platform/nginx/conf.d/timeout.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
keepalive_timeout 120;
15 changes: 14 additions & 1 deletion .test.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,17 @@ ADMIN_PW = "admin"

JWT_SECRET="SECRET"

JUDGE_SERVER_ENDPOINT="a"
JUDGE_SERVER_ENDPOINT="test"

ENV=""
PORT=""

# AWS
AWS_REGION="test"
AWS_ACCESS_ID="test"
AWS_ACCESS_SECRET="test"
AWS_SQS_QUEUE="test"
AWS_S3_BUCKET="test"

# Sentry
SENTRY_DSN="test"
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ FROM node:21-bullseye

COPY . .

RUN yarn install\
npx prisma migrate
RUN yarn install


CMD [ "start" ]
CMD [ "docker:start" ]
ENTRYPOINT [ "yarn" ]
Loading

0 comments on commit 51a255d

Please sign in to comment.