Skip to content

Commit

Permalink
refactor: Separate client build and nginx deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
유미라 authored and 유미라 committed Dec 3, 2024
1 parent 0d40d39 commit f78a721
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 79 deletions.
99 changes: 40 additions & 59 deletions .github/workflows/client-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,50 @@ on:
paths:
- 'client/**'
- 'core/**'
- 'nginx.conf'
- '.github/workflows/client-ci-cd.yml'
- 'Dockerfile.nginx'

jobs:
ci-cd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: '9'

- name: Install Dependencies
run: pnpm install --frozen-lockfile

- name: Build Core Package
working-directory: ./core
run: pnpm build

- name: Lint Client
working-directory: ./client
run: pnpm lint | true

- name: Test Client
working-directory: ./client
run: pnpm test | true

- name: Build Client
working-directory: ./client
run: pnpm build

- name: Deploy to Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: mira
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /home/mira/web30-stop-troublepainter
docker cp client/dist/. client-dist:/
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: '9'

- name: Install Dependencies
run: pnpm install --frozen-lockfile

- name: Build Core Package
working-directory: ./core
run: pnpm build

- name: Lint Client
working-directory: ./client
run: pnpm lint | true

- name: Test Client
working-directory: ./client
run: pnpm test | true

- name: Docker Setup
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.nginx
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter-nginx:latest
build-args: |
VITE_API_URL=${{secrets.VITE_API_URL}}
VITE_SOCKET_URL=${{secrets.VITE_SOCKET_URL}}
- name: Deploy to Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: mira
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /home/mira/web30-stop-troublepainter
export DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter-nginx:latest
docker compose up -d nginx
47 changes: 47 additions & 0 deletions .github/workflows/nginx-ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Nginx CI/CD

on:
push:
branches: [develop]
paths:
- 'nginx.conf'
- '.github/workflows/nginx-ci-cd.yml'
- 'Dockerfile.nginx'

jobs:
ci-cd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Docker Setup
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.nginx
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter-nginx:latest
build-args: |
VITE_API_URL=${{secrets.VITE_API_URL}}
VITE_SOCKET_URL=${{secrets.VITE_SOCKET_URL}}
- name: Deploy to Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: mira
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /home/mira/web30-stop-troublepainter
export DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter-nginx:latest
docker compose up -d nginx
20 changes: 0 additions & 20 deletions Dockerfile.nginx
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
FROM node:20-alpine AS builder

RUN corepack enable && corepack prepare [email protected] --activate

WORKDIR /app

COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
COPY core/package.json ./core/
COPY client/package.json ./client/

RUN pnpm install --frozen-lockfile

COPY . .

ARG VITE_API_URL
ARG VITE_SOCKET_URL

RUN echo "VITE_API_URL=$VITE_API_URL" > client/.env && echo "VITE_SOCKET_URL=$VITE_SOCKET_URL" >> client/.env && pnpm --filter @troublepainter/core build && pnpm --filter client build

FROM nginx:alpine

COPY nginx.conf /etc/nginx/templates/default.conf.template
COPY --from=builder /app/client/dist /usr/share/nginx/html

EXPOSE 80 443

Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
volumes:
client-dist:

services:
server:
image: ${DOCKERHUB_USERNAME}/troublepainter-server:latest
Expand All @@ -17,6 +20,7 @@ services:
container_name: troublepainter_nginx
volumes:
- /etc/letsencrypt:/etc/letsencrypt
- client-dist:/usr/share/nginx/html
ports:
- "80:80"
- "443:443"
Expand Down

0 comments on commit f78a721

Please sign in to comment.