-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Separate client build and nginx deployment
- Loading branch information
유미라
authored and
유미라
committed
Dec 3, 2024
1 parent
0d40d39
commit f78a721
Showing
4 changed files
with
91 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters