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

Staging #38

Merged
merged 84 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
a15b8a6
Merge pull request #4 from TickLabVN/feature/add-ci-for-lint
quannhg Sep 14, 2023
7a4fde6
fix(deployment): change CMD in docker container and fix random port w…
ngyngcphu Sep 18, 2023
0c72c11
Merge branch 'feature/auth' of github.com:TickLabVN/ssps-be into feat…
quannhg Sep 20, 2023
565a308
feat(auth): implement authorization with admin and student
quannhg Sep 23, 2023
192a999
feat(printing request): implement an api for get all printing request…
quannhg Oct 2, 2023
a37c900
feat(home page): implement an api to send slide image urls of home page
quannhg Oct 2, 2023
5fb7e7f
feat(user): implement api for get current remain coins of user
quannhg Oct 2, 2023
2040e31
feat(docker-compose): modify docker-compose to using .env file and us…
quannhg Oct 2, 2023
f248ee2
Merge pull request #7 from TickLabVN/feat/implement-home
quannhg Oct 2, 2023
64dd69b
Merge pull request #8 from TickLabVN/feature/implement-authorization-…
quannhg Oct 2, 2023
39a0440
Merge pull request #9 from TickLabVN/feature/auth
quannhg Oct 2, 2023
7a9cf05
feat(priting request): implement api for upload file to priting request
quannhg Oct 11, 2023
6ee011e
feat(printing request): create new table of file, add roll back mecha…
quannhg Oct 11, 2023
07fbc16
feat(printing request): change to use node-printer, implement logic p…
quannhg Oct 15, 2023
1b3bbe2
refactor(printing request): separate Locations into db table. Update …
quannhg Oct 17, 2023
1515e35
feat(printing request): implement api for create printing request
quannhg Oct 17, 2023
9657185
feat(printing request): implment get all and remove specific file api…
quannhg Oct 17, 2023
faa7204
ci(release.yml): implement auto deploy for test branch
quannhg Oct 18, 2023
e74f22f
fix(release.yml): remove needs of release job for buld and deploy jobs
quannhg Oct 18, 2023
420637a
fix(release.yml): ensure image name don't have capitalize
quannhg Oct 18, 2023
123ae77
fix(docker): install neccesary packets for node-printer at developmen…
quannhg Oct 19, 2023
5d3e42b
fix(dockerfile): add python3 and cup-devs to package of step 2
quannhg Oct 21, 2023
237924b
Merge pull request #13 from TickLabVN/test/implement-cd-using-github-…
quannhg Oct 21, 2023
6680c8f
Merge pull request #14 from TickLabVN/feature/implement-upload-file-api
quannhg Oct 21, 2023
3d06865
fix(server.ts): add credentials equal true to config of fastify/cors
quannhg Oct 25, 2023
4e19fba
feat(printingrequest): split upload file and config api to two sepera…
quannhg Oct 25, 2023
8ca0d88
feat(configuration): create new table for saving configurations
quannhg Oct 25, 2023
221e391
Merge pull request #15 from TickLabVN/feature/split-upload-api
quannhg Oct 25, 2023
8fd3c62
feat(workflows): split cd for deploy of development and product
quannhg Oct 29, 2023
684d6ef
Merge pull request #16 from TickLabVN/feature/implement-cd-for-develo…
quannhg Oct 29, 2023
6999d15
feat(purchase coin): implement PayPal Coin Purchase APIs
quannhg Nov 1, 2023
01c9f05
Merge pull request #17 from TickLabVN/feat/add-paypal-coin-purchase
quannhg Nov 1, 2023
6416e91
feat(configuration): move dollar to coin config to db
quannhg Nov 1, 2023
0dfda11
fix(cors): cors is true for any incoming request on developer server
quannhg Nov 1, 2023
0a03664
Merge pull request #18 from TickLabVN:hotfix/accept-all-request-on-de…
quannhg Nov 1, 2023
366a64f
fix(configuration): save value of DOLLAR_TO_COIN in code instead of d…
quannhg Nov 1, 2023
9b04c47
Merge pull request #19 from TickLabVN:hotfix/change-config-to-hard-code
quannhg Nov 1, 2023
1983de2
fix(env.ts): accessing env variable via 'process.env' and implementin…
quannhg Nov 14, 2023
3e1c192
feat(google oauth): implement handler logic for google oauth callback
quannhg Nov 15, 2023
e698ae9
fix(env.ts): resolve circular dependencies among configs, constants, …
quannhg Nov 15, 2023
f42f5d0
Merge branch 'staging' into featute/integrate-google-oauth
quannhg Nov 15, 2023
40f6f9d
Merge pull request #20 from TickLabVN/featute/integrate-google-oauth
quannhg Nov 15, 2023
b7fb5a3
fix(user.handler.ts): change return of api/user to {id, email}
quannhg Nov 15, 2023
de0f964
Merge pull request #21 from TickLabVN/fix/change-result-of-get-user-b…
quannhg Nov 15, 2023
94c78ba
fix(configuration): put retrieve configuration in db from configs fol…
quannhg Nov 16, 2023
c0d9f07
feat(cd): implement CD for cloned containers to ensure the success of…
quannhg Nov 16, 2023
46e5410
fix(cd): separate ports and docker-compose file for test deployment s…
quannhg Nov 18, 2023
1a33700
feat(upload file): create schema body for upload file api to it can w…
quannhg Nov 18, 2023
94f5cfa
fix(configuration): convert DB configuration getter to arrow function
quannhg Nov 18, 2023
3882c49
fix(cd): update developer CD for new Docker Compose settings
quannhg Nov 18, 2023
2d050ef
Merge pull request #27 from TickLabVN/bugfix/access-config-db-before-…
quannhg Nov 18, 2023
ac726ec
feat(configuration): implement API for getting all configurations and…
quannhg Nov 20, 2023
d97784c
Merge pull request #28 from TickLabVN/feature/implement-accepted-exte…
quannhg Nov 20, 2023
e8868bf
fix(cd): adjust name of docker compose file in dev-deploy
quannhg Nov 20, 2023
03b10ed
Merge pull request #29 from TickLabVN/bugfix/name-of-dockerfile-in-de…
quannhg Nov 20, 2023
fdad29d
feat(printing request): upload numPages and numFiles in file uploads
quannhg Nov 21, 2023
1b347df
fix(role): create corresponding student when user has the 'student' role
quannhg Nov 21, 2023
8e92aff
feat(printing request): implement API for canceling printing requests
quannhg Nov 21, 2023
acc795d
feat(printing request): implement API for changing the print quantity…
quannhg Nov 21, 2023
f22cb96
Merge pull request #30 from TickLabVN/bugfix/print-request-processing…
quannhg Nov 21, 2023
e37593f
feat(edit pdf file): uncomple edit pdf file for config printing file
quannhg Nov 22, 2023
fc534b5
fix(google oauth): add response in gg redirect schema; fix catch handler
quannhg Nov 28, 2023
0b26f27
Merge pull request #31 from TickLabVN:bugfix/adjust-swagger-of-gg-oau…
quannhg Nov 28, 2023
4d5a5f6
feat(printing-config): implement API for adjusting copies of a single…
quannhg Dec 1, 2023
1a334a6
Merge pull request #32 from TickLabVN/feat/increase-amount-of-copies-…
quannhg Dec 1, 2023
0c01474
feat(edit pdf): implement landscape with page per sheet parameter
quannhg Dec 2, 2023
7d7ca4b
feat(edit pdf): implement portrait with page per sheet parameter
quannhg Dec 2, 2023
f4ea167
feat(edit pdf): implement setting for two-sided short or long edge
quannhg Dec 2, 2023
516be6a
feat(edit pdf): implement a comprehensive function wrapping the entir…
quannhg Dec 2, 2023
88b2472
fix(printing config): update numOfCopies increase numCoins; increase …
quannhg Dec 2, 2023
420d9eb
fix(printing file): retrieve all files of printing requests ordered b…
quannhg Dec 2, 2023
e6ed59c
fix(printing config): update coins of printing request base on number…
quannhg Dec 2, 2023
7ff7a0a
fix(printing config): remove duplicate increase of coins and pages in…
quannhg Dec 2, 2023
8a6ae5a
Merge pull request #33 from TickLabVN/feat/config-pdf-file
quannhg Dec 2, 2023
792036e
refactor(edit pdf): combine PageSide and EdgeBinding to PageSideEdge …
quannhg Dec 2, 2023
953d97a
feat(printing): complete handler for configuring print file and sendi…
quannhg Dec 2, 2023
9d3fee1
Merge pull request #34 from TickLabVN/feat/config-pdf-file
quannhg Dec 2, 2023
1143d44
feat(auth): implement API for logout
quannhg Dec 2, 2023
837af80
Merge pull request #35 from TickLabVN:feature/implement-log-out
quannhg Dec 2, 2023
4fab935
fix(upload file): increase limits of fastify multipart
quannhg Dec 2, 2023
6d96d92
ci(release.yml): remove deloy job
quannhg Dec 2, 2023
c56e4b8
Merge pull request #36 from TickLabVN/hotfix/can-not-upload-big-file
quannhg Dec 2, 2023
46a03ff
feat(edit pdf): change select page custom from array to comma-separat…
quannhg Dec 3, 2023
457e679
Merge pull request #37 from TickLabVN/feature/refactor-body-upload-co…
quannhg Dec 3, 2023
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
3 changes: 2 additions & 1 deletion .barrelsby.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"./src/hooks",
"./src/interfaces",
"./src/repositories",
"./src/utils"
"./src/utils",
"./src/services"
],
"exclude": ["__mock__", "__mocks__", ".spec.ts"],
"delete": true
Expand Down
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB=
POSTGRES_URL=

CORS_WHITE_LIST=
COOKIE_SECRET=
JWT_SECRET=
2 changes: 1 addition & 1 deletion .github/workflows/commit-lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Check conventional of commit message
on:
- pull_request
- push
Expand Down
118 changes: 118 additions & 0 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
on:
push:
branches:
- staging

permissions:
contents: write
pull-requests: write
packages: write

env:
REGISTRY: ${{vars.REGISTRY_NAME}}
IMAGE_NAME: ticklabvn/ssps-be
CD_USERNAME: ${{github.actor}}
TEST_DEPLOY_IMAGE_NAME: ticklabvn/ssps-be-test-deploy

name: Release and deploy

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout repository

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
with:
version: v0.9.1

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.CD_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

deploy:
name: Deploy
runs-on: ubuntu-latest
needs: [build]
env:
POSTGRES_URL: postgresql://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@postgres:${{secrets.POSTGRES_PORT}}/${{ secrets.POSTGRES_DB }}?schema=public
steps:
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VPS_HOST }}
port: ${{ secrets.VPS_PORT }}
username: ${{ secrets.VPS_USERNAME }}
password: ${{ secrets.VPS_PASSWORD }}

script: |
export CR_PAT=${{ secrets.REGISTRY_TOKEN }}
echo $CR_PAT | docker login ${{ env.REGISTRY }} -u ${{ env.CD_USERNAME }} --password-stdin
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

mkdir -p $HOME/${{env.IMAGE_NAME}} && cd $HOME/${{env.IMAGE_NAME}}

rm -f .env
echo FASTIFY_PORT=${{ secrets.FASTIFY_PORT }} >> .env
echo FASTIFY_TEST_PORT=${{ secrets.FASTIFY_PORT_TEST_DEPLOY }} >> .env
echo >> .env

echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env
echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env
echo POSTGRES_DB=${{ secrets.POSTGRES_DB }} >> .env
echo POSTGRES_PORT=${{ secrets.POSTGRES_PORT }} >> .env
echo POSTGRES_TEST_PORT=${{ secrets.POSTGRES_PORT_TEST_DEPLOY }} >> .env
echo POSTGRES_URL=${{ env.POSTGRES_URL }} >> .env
echo >> .env

echo CORS_WHITE_LIST=${{ secrets.CORS_WHITE_LIST }} >> .env
echo COOKIE_SECRET=${{ secrets.COOKIE_SECRET }} >> .env
echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env
echo >> .env

echo MINIO_URL=${{ secrets.MINIO_URL }} >> .env
echo MINIO_SERVER_ENDPOINT=${{ secrets.MINIO_SERVER_ENDPOINT }} >> .env
echo MINIO_PORT=${{ secrets.MINIO_PORT }} >> .env
echo MINIO_ACCESS_KEY=${{ secrets.MINIO_ACCESS_KEY }} >> .env
echo MINIO_SECRET_KEY=${{ secrets.MINIO_SECRET_KEY }} >> .env
echo MINIO_BUCKET_NAME=${{ secrets.MINIO_BUCKET_NAME }} >> .env
echo >> .env

echo CHECKOUT_ENVIRONMENT=${{ vars.CHECKOUT_ENVIRONMENT }} >> .env
echo PAYPAL_LIVE_ENDPOINT=${{ vars.PAYPAL_LIVE_ENDPOINT }} >> .env
echo PAYPAL_SANDBOX_ENDPOINT=${{ vars.PAYPAL_SANDBOX_ENDPOINT }} >> .env
echo PAYPAL_CLIENT_ID=${{ secrets.PAYPAL_CLIENT_ID }} >> .env
echo PAYPAL_CLIENT_SECRET=${{ secrets.PAYPAL_CLIENT_SECRET }} >> .env
echo >> .env

echo GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} >> .env
echo GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} >> .env
echo GOOGLE_REDIRECT_URL=${{ secrets.GOOGLE_REDIRECT_URL }} >> .env
echo UI_HOME_URL=${{ secrets.UI_HOME_URL }} >> .env
echo >> .env

curl -s https://${{secrets.READ_FILE_ACCESS_TOKEN}}@raw.githubusercontent.com/${{github.repository}}/staging/docker-compose.yml -O -f
docker compose -f docker-compose.yml down --volumes --remove-orphans
docker compose -f docker-compose.yml up -d ${{vars.DOCKER_COMPOSE_DEPLOY_SERVICE_NAME}} &&
docker exec -it ssps-be /bin/sh -c "npx prisma db seed"

docker exec -it ssps-be /bin/sh -c "npx prisma db seed"

docker logout ${{ env.REGISTRY }}

104 changes: 30 additions & 74 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
on:
push:
branches:
- master
- main

permissions:
contents: write
pull-requests: write
packages: write

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# Image name MUST have a pattern like <org_name_lowercase>/<repo_name_lowercase>
IMAGE_NAME: phucvinh57/fastify-template
# username login to ghcr MUST be organization or personal name in lower case
CD_USERNAME: phucvinh57
REGISTRY: ${{vars.REGISTRY_NAME}}
IMAGE_NAME: ticklabvn/ssps-be
CD_USERNAME: ${{github.actor}}

name: Release and deploy

Expand All @@ -31,74 +28,33 @@ jobs:
release-type: node
pull-request-header: "Bot (:robot:) requested to create a new release on ${{ github.ref_name }}"

## Use if need to build package
# build:
# name: Build
# needs: [release]
# runs-on: ubuntu-latest
# if: ${{ needs.release.outputs.build == 'true' }}
# steps:
# - uses: actions/checkout@v3
# name: Checkout repository

# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2

# - name: Setup Docker buildx
# uses: docker/setup-buildx-action@v2
# with:
# version: v0.9.1
build:
name: Build
needs: [release]
runs-on: ubuntu-latest
if: ${{ needs.release.outputs.build == 'true' }}
steps:
- uses: actions/checkout@v3
name: Checkout repository

# - name: Log into registry ${{ env.REGISTRY }}
# uses: docker/login-action@v2
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ env.CD_USERNAME }}
# password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

# - name: Build and push
# uses: docker/build-push-action@v3
# with:
# context: .
# push: true
# tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.release.outputs.tag_name }}
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
with:
version: v0.9.1

## Use if need to deploy on a server
# deploy:
# name: Deploy
# runs-on: ubuntu-latest
# needs: [build]
# env:
# POSTGRES_URL: postgresql://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@postgres:5432/${{ secrets.POSTGRES_DB }}?schema=public
# steps:
# - name: Deploy
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.VPS_HOST }}
# port: ${{ secrets.VPS_PORT }}
# username: ${{ secrets.VPS_USERNAME }}
# password: ${{ secrets.VPS_PASSWORD }}
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.CD_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }}

# # TODO: Remove docker volumes in Dev stage only
# script: |
# export CR_PAT=${{ secrets.GITHUB_TOKEN }}
# echo $CR_PAT | docker login ${{ env.REGISTRY }} -u ${{ env.CD_USERNAME }} --password-stdin
# docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}

# cd $HOME/thesis-222
# rm -f .env
# echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env
# echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env
# echo POSTGRES_DB=${{ secrets.POSTGRES_DB }} >> .env
# echo POSTGRES_URL=${{ env.POSTGRES_URL }} >> .env
# echo COOKIE_SECRET=${{ secrets.COOKIE_SECRET }} >> .env
# echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env
# echo CORS_WHITE_LIST=${{ vars.CORS_WHITE_LIST }} >> .env

# # curl https://raw.githubusercontent.com/phucvinh57/fastify-template/master/docker-compose.yml -o docker-compose.yml
# docker-compose stop fastify
# docker-compose rm -f fastify
# docker-compose up -d fastify

# docker logout ${{ env.REGISTRY }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.release.outputs.tag_name }}
45 changes: 45 additions & 0 deletions .github/workflows/remove-test-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
on:
pull_request:
types:
- closed

permissions:
contents: write
pull-requests: write
packages: write

env:
REGISTRY: ${{ vars.REGISTRY_NAME }}

name: Remove test deploy

jobs:
remove:
name: Remove test deploying
runs-on: ubuntu-latest

env:
TEST_DEPLOY_IMAGE_NAME: ticklabvn/ssps-be-test-deploy

if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.base.ref == 'staging'

steps:
- name: remove
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VPS_HOST }}
port: ${{ secrets.VPS_PORT }}
username: ${{ secrets.VPS_USERNAME }}
password: ${{ secrets.VPS_PASSWORD }}
script: |
# Remove the test deploy container, image, and folder
cd $HOME/${{ env.TEST_DEPLOY_IMAGE_NAME }}
if [ $? -eq 0 ]; then
docker compose -f docker-compose.test-deploy.yml down --volumes --remove-orphans
docker image rm -f ${{ env.REGISTRY }}/${{ env.TEST_DEPLOY_IMAGE_NAME }}:latest
rm -rf $HOME/${{ env.TEST_DEPLOY_IMAGE_NAME }}
else
echo "Could not change directory to $HOME/${{ env.TEST_DEPLOY_IMAGE_NAME }}. Skipping removal."
fi


Loading
Loading