Skip to content

Commit

Permalink
Merge pull request #26 from jungvengers/feature/migrate-db
Browse files Browse the repository at this point in the history
feat: migrate mysql to postgres
  • Loading branch information
PleBea authored Oct 16, 2024
2 parents 3833ef1 + 4994582 commit 1eb8d3a
Show file tree
Hide file tree
Showing 111 changed files with 10,915 additions and 51,807 deletions.
21 changes: 10 additions & 11 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ name: Docker

on:
schedule:
- cron: '0 15 * * *'
- cron: "0 15 * * *"
pull_request:
workflow_run:
workflows: [ Test ] # Reuse the name of your tests workflow
branches: [ master, release ]
workflows: [Test] # Reuse the name of your tests workflow
branches: [master, release]
types: completed
workflow_dispatch:

Expand All @@ -34,26 +34,25 @@ jobs:

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

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0
uses: sigstore/cosign-installer@v3.7.0
with:
cosign-release: 'v1.13.1'

cosign-release: "v2.4.1"

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
uses: docker/setup-buildx-action@v3

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand All @@ -63,15 +62,15 @@ jobs:
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
Expand Down
122 changes: 65 additions & 57 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ name: Test

on:
push:
branches: [ master, release ]
branches: [master, release]
pull_request:

env:
# Environments
NODE_ENV: ${{ vars.NODE_ENV }}

DB_HOST: ${{ vars.DB_HOST }}
DB_PORT: ${{ vars.DB_PORT }}
DB_NAME: ${{ vars.DB_NAME }}
DB_USERNAME: ${{ vars.DB_USER }}
DB_PASSWORD: ${{ vars.DB_PASSWORD }}

JWT_SECRET: ${{ vars.JWT_SECRET }}
JWT_EXPIRES_IN: ${{ vars.JWT_EXPIRES_IN }}

ACCESS_TOKEN_SECRET: ${{ vars.ACCESS_TOKEN_SECRET }}
ACCESS_TOKEN_EXPIRES_IN: ${{ vars.ACCESS_TOKEN_EXPIRES_IN }}

REFRESH_TOKEN_SECRET: ${{ vars.REFRESH_TOKEN_SECRET }}
REFRESH_TOKEN_EXPIRES_IN: ${{ vars.REFRESH_TOKEN_EXPIRES_IN }}

CORS_ORIGIN: ${{ vars.CORS_ORIGIN }}
CORS_METHODS: ${{ vars.CORS_METHODS }}

Expand All @@ -48,67 +48,75 @@ jobs:
environment: development
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn global add lerna
- run: lerna bootstrap
- run: lerna run test
- name: Archive npm failure logs
uses: actions/upload-artifact@v2
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
run_install: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- run: corepack up
- run: pnpm test
- name: Archive npm failure logs
uses: actions/upload-artifact@v4
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs
lint:
runs-on: ubuntu-latest
environment: development
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: echo $ACCESS_TOKEN_SECRET
- run: yarn global add lerna
- run: lerna bootstrap
- run: lerna run lint
- name: Archive npm failure logs
uses: actions/upload-artifact@v2
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs

- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
run_install: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- run: corepack up
- run: pnpm lint
- name: Archive npm failure logs
uses: actions/upload-artifact@v4
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs

build:
needs: [ jest, lint ]
needs: [jest, lint]
runs-on: ubuntu-latest
environment: production
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 19.x]
node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: yarn global add lerna
- run: lerna bootstrap
- run: lerna run build
- name: Archive npm failure logs
uses: actions/upload-artifact@v2
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
run_install: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- run: corepack up
- run: pnpm build
- name: Archive npm failure logs
uses: actions/upload-artifact@v4
if: failure()
with:
name: npm-logs
path: ~/.npm/_logs
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ typings/
# Nuxt.js build / generate output
.nuxt
dist
lib

# Gatsby files
.cache/
Expand All @@ -102,3 +103,6 @@ dist

# TernJS port file
.tern-port

# postgres-data
postgres-data
1 change: 0 additions & 1 deletion .yarnrc.yml

This file was deleted.

12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM node:18
FROM node:lts-alpine

WORKDIR /app

RUN corepack enable

COPY . .
RUN yarn global add lerna
RUN lerna bootstrap
RUN lerna run build
RUN corepack up
RUN pnpm install
RUN pnpm build

CMD [ "lerna", "run", "start", "--scope=server" ]
CMD [ "pnpm", "--filter=server", "start" ]
18 changes: 14 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
version: '2.0'
version: "3.0"

services:
server:
image: 'ghcr.io/jungvengers/sunrinsecurity-backend-v3:master'
image: "ghcr.io/jungvengers/sunrinsecurity-backend-v3:master"
env_file:
- .env
- packages/server/.env
environment:
- PORT=3000
ports:
- 3000:3000
extra_hosts:
- host.docker.internal:host-gateway
- host.docker.internal:host-gateway
depends_on:
- db
db:
image: postgres:15
restart: always
volumes:
- ./postgres-data:/var/lib/postgresql/data
ports:
- "5432:5432"
env_file:
- .env
10 changes: 0 additions & 10 deletions lerna.json

This file was deleted.

Loading

0 comments on commit 1eb8d3a

Please sign in to comment.