Skip to content

Commit

Permalink
chore: ec2 + docker 배포 세팅
Browse files Browse the repository at this point in the history
kimsudang committed Dec 19, 2024
1 parent 91c7fe6 commit 2dcf483
Showing 4 changed files with 68 additions and 56 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PORT=
DATABASE_URL=
MONGODB_URL=
REDIS_HOST=
63 changes: 63 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Docker CI/CD Pipeline

on:
push:
branches:
- main
pull_request:
branches:
- develop

jobs:
build-and-push:
name: 도커 이미지화
runs-on: ubuntu-latest

steps:
- name: 리포지토리 코드 체크아웃
uses: actions/checkout@v3

- name: Docker Buildx 설정
uses: docker/setup-buildx-action@v2

- name: Docker Hub 로그인
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Docker 이미지 빌드 및 푸시
uses: docker/build-push-action@v4
with:
context: ./
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/nestjs-app:${{ github.sha }}

deploy:
name: 서버 배포
needs: build-and-push
runs-on: ubuntu-latest

steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: 서버 배포 및 상태 확인
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /home/ubuntu
docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/nestjs-app:latest
sudo docker-compose down
sudo docker-compose up -d
docker image prune —f
echo "=== Docker 컨테이너 상태 ==="
sudo docker-compose ps
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Node.js 경량 Alpine 버전 사용
FROM node:20-alpine
FROM node:22-alpine

# 작업 디렉토리 설정
WORKDIR /usr/src/app
55 changes: 0 additions & 55 deletions docker-compose.yaml

This file was deleted.

0 comments on commit 2dcf483

Please sign in to comment.