Skip to content

Commit

Permalink
feat: Optimize Docker-based deployment and CI/CD pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
유미라 authored and 유미라 committed Nov 27, 2024
1 parent 966b3c0 commit def2b19
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 25 deletions.
30 changes: 25 additions & 5 deletions .github/workflows/client-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,39 @@ jobs:
VITE_SOCKET_URL: ${{secrets.VITE_SOCKET_URL}}
run: pnpm build

deploy:
docker-deploy:
needs: ci
runs-on: ubuntu-latest
steps:
- name: Checkout repository
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
git pull origin develop
docker compose build nginx
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter-nginx:latest
docker compose up -d nginx
13 changes: 3 additions & 10 deletions .github/workflows/server-ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
context: .
file: ./Dockerfile.nestjs
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter:latest
tags: ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter-api:latest
build-args: |
REDIS_HOST=${{ secrets.REDIS_HOST }}
REDIS_PORT=${{ secrets.REDIS_PORT }}
Expand All @@ -74,12 +74,5 @@ jobs:
username: mira
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /home/mira/web30-stop-troublepainter
git pull origin develop
echo "REDIS_HOST=${{ secrets.REDIS_HOST }}" > .env
echo "REDIS_PORT=${{ secrets.REDIS_PORT }}" >> .env
echo "CLOVA_API_KEY=${{ secrets.CLOVA_API_KEY }}" >> .env
echo "CLOVA_GATEWAY_KEY=${{ secrets.CLOVA_GATEWAY_KEY }}" >> .env
docker compose up -d
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/troublepainter-api:latest
docker compose up -d api
5 changes: 0 additions & 5 deletions Dockerfile.nestjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,8 @@ RUN corepack enable && corepack prepare [email protected] --activate && cd server && p

WORKDIR /app/server

ARG REDIS_HOST
ARG REDIS_PORT

ENV NODE_ENV=production
ENV PORT=3000
ENV REDIS_HOST=$REDIS_HOST
ENV REDIS_PORT=$REDIS_PORT

EXPOSE 3000

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.nginx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ FROM nginx:alpine
COPY nginx.conf /etc/nginx/templates/default.conf.template
COPY --from=builder /app/client/dist /usr/share/nginx/html

EXPOSE 80
EXPOSE 80 443

CMD ["nginx", "-g", "daemon off;"]
2 changes: 1 addition & 1 deletion client/src/api/api.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const API_CONFIG = {
BASE_URL,
ENDPOINTS: {
GAME: {
CREATE_ROOM: '/game/rooms',
CREATE_ROOM: '/api/game/rooms',
},
},
OPTIONS: {
Expand Down
6 changes: 3 additions & 3 deletions client/src/stores/socket/socket.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export const SOCKET_CONFIG = {
},
/** 네임스페이스별 경로 */
PATHS: {
[SocketNamespace.GAME]: '/game',
[SocketNamespace.DRAWING]: '/drawing',
[SocketNamespace.CHAT]: '/chat',
[SocketNamespace.GAME]: '/socket.io/game',
[SocketNamespace.DRAWING]: 'socket.io/drawing',
[SocketNamespace.CHAT]: '/socket.io/chat',
},
} as const;

Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ services:
context: .
dockerfile: Dockerfile.nginx
container_name: troublepainter_nginx
environment:
- NODE_ENV=production
- VITE_API_URL=${VITE_API_URL}
- VITE_SOCKET_URL=${VITE_SOCKET_URL}
volumes:
- /etc/letsencrypt:/etc/letsencrypt
ports:
Expand Down

0 comments on commit def2b19

Please sign in to comment.