Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit

Permalink
refactor: migrate backend/ and frontend/ to services/ (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaidev authored Oct 4, 2024
1 parent 3cc6737 commit 852978c
Show file tree
Hide file tree
Showing 124 changed files with 97 additions and 1,431 deletions.
4 changes: 2 additions & 2 deletions .git-hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
conventional_commits_regex="^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-zA-Z0-9_-]+\))?: .+"
CONVENTIONAL_COMMITS_REGEX="^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-zA-Z0-9_-]+\))?: .+"

commit_message=$(cat "$1")

if [[ "$commit_message" =~ $conventional_commits_regex ]]; then
if [[ $commit_message =~ $CONVENTIONAL_COMMITS_REGEX ]]; then
echo "[commit-msg] Pass."
echo ""
exit 0
Expand Down
4 changes: 2 additions & 2 deletions .git-hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Files changed in the current commit.
# For example, "frontend/src/app/page.tsx".
# For example, "services/web/src/app/page.tsx".
changed_files=$(git diff --cached --name-only)

# Target directories to run pre-commit hooks in.
# For example, "frontend".
# For example, "services/web".
# A directory is qualified as a target, if it meets the following conditions:
# 1. It contains at least one changed file.
# 2. It contains a ".git-hooks/pre-commit" file.
Expand Down
26 changes: 11 additions & 15 deletions .github/workflows/build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ on:
inputs:
build:
required: true
default: 'false'
default: false
type: boolean
deploy:
required: true
default: 'false'
default: false
type: boolean
# - main
#paths:
# - 'frontend/**'
# - 'backend/**'

jobs:
build:
Expand All @@ -35,32 +31,32 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push frontend
- name: Build and push web service
uses: docker/build-push-action@v6
with:
build-args: |
NEXT_PUBLIC_API_BASE_URL=${{ secrets.NEXT_PUBLIC_API_BASE_URL }}
context: ./frontend
context: ./services/web
push: true
tags: z1yoon/nus-secondhand-market-frontend:latest
tags: z1yoon/nus-secondhand-market-web:latest

- name: Build and push backend
- name: Build and push account service
uses: docker/build-push-action@v6
with:
context: ./backend
context: ./services/account
push: true
tags: z1yoon/nus-secondhand-market-backend:latest
tags: z1yoon/nus-secondhand-market-account:latest

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: '${{ secrets.AWS_ACCESS_KEY_ID }}'
aws-secret-access-key: '${{ secrets.AWS_SECRET_ACCESS_KEY }}'
aws-access-key-id: "${{ secrets.AWS_ACCESS_KEY_ID }}"
aws-secret-access-key: "${{ secrets.AWS_SECRET_ACCESS_KEY }}"
aws-region: ap-southeast-1
deploy:
if: ${{ github.event.inputs.deploy == 'true' }}
runs-on: ubuntu-latest
#needs: build
#needs: build
steps:
- name: Checkout Code
uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
name: CI for frontend
name: CI for web service

on:
push:
branches:
- main
paths:
- frontend/**
- services/web/**
pull_request:
branches:
- main
paths:
- frontend/**
- services/web/**

jobs:
lint:
runs-on: ubuntu-latest

defaults:
run:
working-directory: frontend
working-directory: services/web

steps:
- name: Check out repository
Expand All @@ -27,14 +27,14 @@ jobs:
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
package_json_file: frontend/package.json
package_json_file: services/web/package.json

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: pnpm
cache-dependency-path: frontend/pnpm-lock.yaml
cache-dependency-path: services/web/pnpm-lock.yaml

- name: Install dependencies
run: pnpm install
Expand All @@ -50,7 +50,7 @@ jobs:

defaults:
run:
working-directory: frontend
working-directory: services/web

steps:
- name: Check out repository
Expand All @@ -59,27 +59,27 @@ jobs:
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
package_json_file: frontend/package.json
package_json_file: services/web/package.json

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: pnpm
cache-dependency-path: frontend/pnpm-lock.yaml
cache-dependency-path: services/web/pnpm-lock.yaml

- name: Install dependencies
run: pnpm install

- name: Format
- name: Check format
run: pnpm prettier . --check

build:
runs-on: ubuntu-latest

defaults:
run:
working-directory: frontend
working-directory: services/web

steps:
- name: Check out repository
Expand All @@ -88,14 +88,14 @@ jobs:
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
package_json_file: frontend/package.json
package_json_file: services/web/package.json

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: pnpm
cache-dependency-path: frontend/pnpm-lock.yaml
cache-dependency-path: services/web/pnpm-lock.yaml

- name: Install dependencies
run: pnpm install
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ temp/
.DS_Store
*.pem
.env
nshm.passphrase
*.passphrase
13 changes: 0 additions & 13 deletions CONTRIBUTING.md

This file was deleted.

32 changes: 16 additions & 16 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
services:
frontend:
web:
build:
context: frontend
dockerfile: Dockerfile
args:
NEXT_PUBLIC_API_BASE_URL: ${NEXT_PUBLIC_API_BASE_URL}
context: services/web
dockerfile: Dockerfile.dev
ports:
- "80:3000"
restart: always
- 3000:3000
environment:
- NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL}
- API_BASE_URL=${API_BASE_URL}
user: root
volumes:
- ./services/web:/app
- /app/node_modules
restart: always

backend:
account:
build:
context: backend
context: services/account
dockerfile: Dockerfile
ports:
- "8081:8081"
restart: always
- 8081:8081
environment:
- POSTGRES_URL=${POSTGRES_URL}
- POSTGRES_USERNAME=${POSTGRES_USERNAME}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
restart: always
depends_on:
- postgres

postgres:
image: postgres:latest
user: root
image: postgres
ports:
- "5432:5432"
- 5432:5432
environment:
- POSTGRES_USER=${POSTGRES_USERNAME}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
volumes:
- pgdata:/var/lib/postgresql/data
- ./init:/docker-entrypoint-initdb.d
- ./services/account/database:/docker-entrypoint-initdb.d

volumes:
pgdata:
10 changes: 5 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
services:
frontend:
image: z1yoon/nus-secondhand-market-frontend:latest
web:
image: z1yoon/nus-secondhand-market-web:latest
ports:
- "80:3000"
restart: always
environment:
- API_BASE_URL=${API_BASE_URL}
user: root

backend:
image: z1yoon/nus-secondhand-market-backend:latest
account:
image: z1yoon/nus-secondhand-market-account:latest
ports:
- "8081:8081"
restart: always
Expand All @@ -32,7 +32,7 @@ services:
- POSTGRES_DB=${POSTGRES_DB}
volumes:
- pgdata:/var/lib/postgresql/data
- ./init:/docker-entrypoint-initdb.d
- ./services/account/database:/docker-entrypoint-initdb.d

volumes:
pgdata:
3 changes: 0 additions & 3 deletions frontend/.env.example

This file was deleted.

4 changes: 1 addition & 3 deletions run
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/bin/sh

DOCKER_COMPOSE_FILE=docker-compose.dev.yaml

if [[ ! -f .env ]] && [[ -f .env.gpg ]]; then
Expand All @@ -10,7 +8,7 @@ if [[ ! -f .env ]] && [[ -f .env.gpg ]]; then
echo ".env file created successfully"
fi

if [ "$(docker ps -q -f name=backend)" ] || [ "$(docker ps -q -f name=frontend)" ]; then
if [ "$(docker ps -q -f name=account)" ] || [ "$(docker ps -q -f name=web)" ]; then
echo "Stopping running containers..."
docker compose -f $DOCKER_COMPOSE_FILE down
fi
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions services/web/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# How user browser accesses API.
# For example, "https://nshm.mrcai.dev/api",
# Note: Do not include a trailing slash.
NEXT_PUBLIC_API_BASE_URL=

# How web service accesses other services.
# For example, "http://service-registry:8761".
# Note: Do not include a trailing slash.
API_BASE_URL=
File renamed without changes.
2 changes: 0 additions & 2 deletions frontend/.gitignore → services/web/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.next/
coverage/
node_modules/
.env*
!.env.example
next-env.d.ts
*.tsbuildinfo
File renamed without changes.
9 changes: 2 additions & 7 deletions frontend/Dockerfile → services/web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM node:lts-alpine AS build

WORKDIR /app

RUN apk add --no-cache libc6-compat curl
RUN apk add --no-cache libc6-compat

RUN corepack enable pnpm

Expand All @@ -25,12 +25,7 @@ FROM node:lts-alpine AS production

WORKDIR /app

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=build --chown=nextjs:nodejs /app/.next/standalone .

USER nextjs
COPY --from=build /app/.next/standalone .

ENV HOSTNAME=0.0.0.0
ENV PORT=3000
Expand Down
21 changes: 21 additions & 0 deletions services/web/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# docker build -f Dockerfile.dev -t web:dev .
# docker run -d -p 3000:3000 --name web --env-file .env -v .:/app -v /app/node_modules web:dev

FROM node:lts-alpine

WORKDIR /app

RUN apk add --no-cache libc6-compat

RUN corepack enable pnpm

COPY package.json pnpm-lock.yaml ./

RUN pnpm install --frozen-lockfile

ENV HOSTNAME=0.0.0.0
ENV PORT=3000

EXPOSE 3000

CMD ["pnpm", "run", "dev"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion frontend/package.json → services/web/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "frontend",
"name": "web-service",
"private": true,
"type": "module",
"packageManager": "pnpm@9.11.0",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
terraform.tfstate*
terraform/.terraform
.terraform/
*.tfstate*
Loading

0 comments on commit 852978c

Please sign in to comment.