Skip to content

Commit

Permalink
⚙️ chore docker를 이용한 CD 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jinddings committed Nov 5, 2024
1 parent 20da861 commit 1cdf45c
Show file tree
Hide file tree
Showing 6 changed files with 2,303 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [back/main, front/main]
pull_request:
branches: [alpha, main, back/main, front/main, dev]
branches: [main, back/main, front/main, dev]

jobs:
test-and-build:
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: deploy

on:
push:
branches: [main, alpha]
pull_request:
branches: [main, alpha]

env:
DOCKER_IMAGE: BE

jobs:
login:
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

build-and-deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm test
env:
CI: true

- name: Run linter
run: npm run lint

- name: Build application
run: npm run build

- name: Build and Push Docker Image
env:
NCP_ACCESS_KEY: ${{ secrets.NCP_ACCESS_KEY }}
NCP_SECRET_KEY: ${{ secrets.NCP_SECRET_KEY }}
run: |
docker build -t $DOCKER_IMAGE:$DOCKER_TAG .
docker tag $DOCKER_IMAGE:$DOCKER_TAG $DOCKER_IMAGE:latest
docker push $DOCKER_IMAGE:$DOCKER_TAG
docker push $DOCKER_IMAGE:latest
- name: Deploy to NCP Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.NCP_SERVER_HOST }}
username: ${{ secrets.NCP_SERVER_USERNAME }}
key: ${{ secrets.NCP_SERVER_SSH_KEY }}
script: |
docker pull ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}
docker stop my-app || true
docker rm my-app || true
docker run -d \
--name my-app \
-p 8080:8080 \
${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}
4 changes: 4 additions & 0 deletions BE/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
Dockerfile
node_modules
dist
8 changes: 8 additions & 0 deletions BE/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:20
RUN mkdir -p /var/app
WORKDIR /var/app
COPY . .
RUN npm install
RUN npm run build
EXPOSE 3000
CMD [ "node", "dist/main.js" ]
Loading

0 comments on commit 1cdf45c

Please sign in to comment.