Skip to content

Commit 8542b7a

Browse files
authored
Merge pull request #107 from shonenxnaifu/development
Development
2 parents 8c2ea01 + 3554cd8 commit 8542b7a

21 files changed

+5168
-5302
lines changed

.github/workflows/build-and-deploy-dev.yml

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ on:
1515
required: true
1616
#2
1717
env:
18-
REGISTRY: "registry.digitalocean.com/research-dev-registry"
1918
IMAGE_NAME: "docker_shonen_dev"
2019
CONTAINER_NAME: "docker_shonen_dev_ctr"
2120

@@ -43,6 +42,7 @@ jobs:
4342
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
4443
with:
4544
context: .
45+
file: ./Dockerfile.dev
4646
push: true
4747
tags: pawitrawarda/docker_shonen_dev:latest
4848
labels: latest
@@ -51,21 +51,56 @@ jobs:
5151
runs-on: ubuntu-latest
5252
needs: build_and_push
5353
steps:
54-
- name: Deploy to Digital Ocean droplet via SSH action
54+
- name: Checkout the repo
55+
uses: actions/checkout@v4
56+
57+
- name: Create directory on server
5558
uses: appleboy/ssh-action@master
5659
with:
5760
host: ${{ secrets.HOST_KAZUHA }}
5861
username: ${{ secrets.USERNAME }}
5962
key: ${{ secrets.SSHKEY_KAZUHA }}
6063
port: ${{ secrets.PORT }}
6164
passphrase: ${{ secrets.PASSPHRASE_KAZUHA }}
62-
envs: IMAGE_NAME,REGISTRY,CONTAINER_NAME,{{ secrets.DIGITALOCEAN_ACCESS_TOKEN }},GITHUB_SHA
6365
script: |
64-
# Pull registry
65-
docker pull pawitrawarda/$(echo $IMAGE_NAME):latest
66-
# Stop running container
67-
docker stop $(echo $CONTAINER_NAME)
68-
# Remove old container
69-
docker rm $(echo $CONTAINER_NAME)
70-
# Run a new container from a new image
71-
docker run -d -p 8093:3000 --name $(echo $CONTAINER_NAME) --memory=75m --memory-swap=75m --restart=unless-stopped pawitrawarda/$(echo $IMAGE_NAME):latest
66+
# Create directory if doesn't exist
67+
sudo mkdir -p /opt/apps-container/personal-web
68+
69+
- name: Copy docker-compose.yml to server
70+
uses: appleboy/scp-action@v1
71+
with:
72+
host: ${{ secrets.HOST_KAZUHA }}
73+
username: ${{ secrets.USERNAME }}
74+
key: ${{ secrets.SSHKEY_KAZUHA }}
75+
port: ${{ secrets.PORT }}
76+
passphrase: ${{ secrets.PASSPHRASE_KAZUHA }}
77+
source: "./docker-compose.yml"
78+
target: "/opt/apps-container/personal-web/"
79+
80+
- name: Deploy using Docker Compose
81+
uses: appleboy/ssh-action@master
82+
with:
83+
host: ${{ secrets.HOST_KAZUHA }}
84+
username: ${{ secrets.USERNAME }}
85+
key: ${{ secrets.SSHKEY_KAZUHA }}
86+
port: ${{ secrets.PORT }}
87+
passphrase: ${{ secrets.PASSPHRASE_KAZUHA }}
88+
envs: IMAGE_NAME, CONTAINER_NAME
89+
script: |
90+
# Navigate to the directory and deploy
91+
cd /opt/apps-container/personal-web
92+
93+
# Pull latest image
94+
docker compose pull personal-web-dev
95+
96+
# Stop and remove existing container
97+
docker compose down --remove-orphans personal-web-dev
98+
99+
# Start services
100+
docker compose up -d --force-recreate personal-web-dev
101+
102+
# Check status of the containers
103+
docker compose ps
104+
105+
# Remove unused images
106+
docker image prune -f

.github/workflows/build-and-deploy-prod.yml

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ on:
1515
required: true
1616
#2
1717
env:
18-
IMAGE_NAME: "docker_shonen_dev"
19-
CONTAINER_NAME: "docker_shonen_dev_prod_ctr"
18+
IMAGE_NAME: "docker_shonen_prod"
19+
CONTAINER_NAME: "docker_shonen_prod_ctr"
2020

2121
#3
2222
jobs:
@@ -36,21 +36,48 @@ jobs:
3636
id: meta
3737
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
3838
with:
39-
images: pawitrawarda/docker_shonen_dev
39+
images: pawitrawarda/docker_shonen_prod
4040

4141
- name: Build and push Docker image
4242
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
4343
with:
4444
context: .
45+
file: ./Dockerfile.prod
4546
push: true
46-
tags: pawitrawarda/docker_shonen_dev:latest
47+
tags: pawitrawarda/docker_shonen_prod:latest
4748
labels: latest
4849

4950
deploy:
5051
runs-on: ubuntu-latest
5152
needs: build_and_push
5253
steps:
53-
- name: Deploy to Digital Ocean droplet via SSH action
54+
- name: Checkout the repo
55+
uses: actions/checkout@v4
56+
57+
- name: Create directory on server
58+
uses: appleboy/ssh-action@master
59+
with:
60+
host: ${{ secrets.HOST_KAZUHA }}
61+
username: ${{ secrets.USERNAME }}
62+
key: ${{ secrets.SSHKEY_KAZUHA }}
63+
port: ${{ secrets.PORT }}
64+
passphrase: ${{ secrets.PASSPHRASE_KAZUHA }}
65+
script: |
66+
# Create directory if doesn't exist
67+
sudo mkdir -p /opt/apps-container/personal-web
68+
69+
- name: Copy docker-compose.yml to server
70+
uses: appleboy/scp-action@v1
71+
with:
72+
host: ${{ secrets.HOST_KAZUHA }}
73+
username: ${{ secrets.USERNAME }}
74+
key: ${{ secrets.SSHKEY_KAZUHA }}
75+
port: ${{ secrets.PORT }}
76+
passphrase: ${{ secrets.PASSPHRASE_KAZUHA }}
77+
source: "./docker-compose.yml"
78+
target: "/opt/apps-container/personal-web/"
79+
80+
- name: Deploy using Docker Compose
5481
uses: appleboy/ssh-action@master
5582
with:
5683
host: ${{ secrets.HOST_KAZUHA }}
@@ -60,11 +87,20 @@ jobs:
6087
passphrase: ${{ secrets.PASSPHRASE_KAZUHA }}
6188
envs: IMAGE_NAME, CONTAINER_NAME
6289
script: |
63-
# Pull registry
64-
docker pull pawitrawarda/$(echo $IMAGE_NAME):latest
65-
# Stop running container
66-
docker stop $(echo $CONTAINER_NAME)
67-
# Remove old container
68-
docker rm $(echo $CONTAINER_NAME)
69-
# Run a new container from a new image
70-
docker run -d -p 8092:3000 --name $(echo $CONTAINER_NAME) --memory=75m --memory-swap=75m pawitrawarda/$(echo $IMAGE_NAME):latest
90+
# Navigate to the directory and deploy
91+
cd /opt/apps-container/personal-web
92+
93+
# Pull latest image
94+
docker compose pull personal-web-prod
95+
96+
# Stop and remove existing container
97+
docker compose down --remove-orphans personal-web-prod
98+
99+
# Start services
100+
docker compose up -d --force-recreate personal-web-prod
101+
102+
# Check status of the containers
103+
docker compose ps
104+
105+
# Remove unused images
106+
docker image prune -f

.github/workflows/lint.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,23 @@ jobs:
1313
name: Linting
1414
runs-on: ubuntu-latest
1515
steps:
16-
- name: Install NodeJS
17-
uses: actions/setup-node@v2
16+
# - name: Install NodeJS
17+
# uses: actions/setup-node@v2
18+
# with:
19+
# node-version: ${{ env.NODE_VERSION }}
20+
21+
- name: Install Bun
22+
uses: oven-sh/setup-bun@v2
1823
with:
19-
node-version: ${{ env.NODE_VERSION }}
20-
24+
bun-version: latest
25+
2126
- name: Code Checkout
2227
uses: actions/checkout@v2
2328

2429
- name: Install Dependencies
25-
run: npm ci --legacy-peer-deps
30+
run: bun install --frozen-lockfile
31+
# run: npm install --legacy-peer-deps
2632

2733
- name: Code Linting
28-
run: npm run lint
34+
run: bun --bun run lint
35+
# run: npm run lint

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
npm run lint
4+
bun run lint

Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
FROM node:current-alpine AS dependency
1+
FROM oven/bun:canary-slim AS dependency
22

33
WORKDIR /app
44
COPY package.json .
5-
COPY package-lock.json .
6-
RUN npm ci --legacy-peer-deps
5+
COPY bun.lock .
6+
RUN bun install
77

8-
FROM node:current-alpine AS builder
8+
FROM oven/bun:canary-slim AS builder
99
WORKDIR /app
1010
COPY . .
1111
COPY --from=dependency /app/node_modules ./node_modules
12-
RUN npm run build
12+
RUN bun run build
1313

14-
FROM node:current-alpine AS runner
14+
FROM oven/bun:canary-slim AS runner
1515
WORKDIR /app
1616
COPY --from=builder /app/public ./public
1717
COPY --from=builder /app/.next/standalone ./
1818
COPY --from=builder /app/.next/static ./.next/static
1919
# COPY --from=builder /app/.next ./.next
20-
CMD ["node", "server.js"]
21-
# CMD ["npm", "start"]
20+
CMD ["bun", "run", "server.js"]
21+
# CMD ["npm", "start"]

Dockerfile.dev

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM node:22-alpine AS dependency
2+
3+
WORKDIR /app
4+
COPY package.json .
5+
COPY package-lock.json .
6+
RUN npm install --legacy-peer-deps
7+
8+
FROM node:22-alpine AS builder
9+
WORKDIR /app
10+
COPY . .
11+
COPY --from=dependency /app/node_modules ./node_modules
12+
RUN npm install --cpu=x64 --os=linux --libc=glibc sharp
13+
RUN npm run build
14+
15+
FROM gcr.io/distroless/nodejs22-debian12:latest-amd64 AS runner
16+
WORKDIR /app
17+
COPY --from=builder /app/public ./public
18+
COPY --from=builder /app/.next/standalone ./
19+
COPY --from=builder /app/.next/static ./.next/static
20+
ENV NODE_ENV=production
21+
CMD ["server.js"]

Dockerfile.dev.bun

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM oven/bun:slim AS dependency
2+
3+
WORKDIR /app
4+
COPY package.json .
5+
COPY bun.lock .
6+
ENV NODE_ENV=production
7+
RUN bun install --frozen-lockfile
8+
9+
FROM oven/bun:slim AS builder
10+
WORKDIR /app
11+
COPY . .
12+
COPY --from=dependency /app/node_modules ./node_modules
13+
ENV NODE_ENV=production
14+
RUN bun --bun run build
15+
16+
FROM oven/bun:distroless AS runner
17+
WORKDIR /app
18+
COPY --from=builder /app/public ./public
19+
COPY --from=builder /app/.next/standalone ./
20+
COPY --from=builder /app/.next/static ./.next/static
21+
ENV NODE_ENV=production
22+
ENTRYPOINT [ "bun", "run", "server.js" ]
23+
# CMD ["bun", "run", "server.js"]

Dockerfile.prod

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM node:22-alpine AS dependency
2+
3+
WORKDIR /app
4+
COPY package.json .
5+
COPY package-lock.json .
6+
RUN npm install --legacy-peer-deps
7+
8+
FROM node:22-alpine AS builder
9+
WORKDIR /app
10+
COPY . .
11+
COPY --from=dependency /app/node_modules ./node_modules
12+
RUN npm install --cpu=x64 --os=linux --libc=glibc sharp
13+
RUN npm run build
14+
15+
FROM gcr.io/distroless/nodejs22-debian12:latest-amd64 AS runner
16+
WORKDIR /app
17+
COPY --from=builder /app/public ./public
18+
COPY --from=builder /app/.next/standalone ./
19+
COPY --from=builder /app/.next/static ./.next/static
20+
ENV NODE_ENV=production
21+
CMD ["server.js"]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: "Simple CI/CD For NextJS Project: Implementation and Configuration Part 1"
3+
description: Implementation and Configuration CI/CD for Linter with Github Action.
4+
image: ""
5+
publishedAt: "2025-08-19"
6+
updatedAt: "2025-08-19"
7+
author: "Pawitra Warda"
8+
isPublished: true
9+
tags:
10+
- webdev
11+
- devops
12+
- cicd
13+
---
14+
15+
## Introduction
16+
17+
## Dependencies
18+
19+
- prettier
20+
- eslint
21+
- @typescript-eslint/eslint-plugin
22+
- @typescript-eslint/parser
23+
- eslint-config-airbnb
24+
- eslint-config-airbnb-typescript
25+
- eslint-config-next
26+
- eslint-config-prettier
27+
- eslint-plugin-impo`rt
28+
- eslint-plugin-jsx-a11y
29+
- eslint-plugin-prettier
30+
- eslint-plugin-react
31+
- eslint-plugin-react-hooks
32+
- husky
33+
34+
## Configuration

0 commit comments

Comments
 (0)