Skip to content

[GWL-48] [FIX] 수동 배포에서 자동 배포로 구현하기 [도커] #7

[GWL-48] [FIX] 수동 배포에서 자동 배포로 구현하기 [도커]

[GWL-48] [FIX] 수동 배포에서 자동 배포로 구현하기 [도커] #7

Workflow file for this run

name: BackEnd-CD
on:
pull_request:
branches: 'develop'
types: [opened, synchronize, reopened]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ${{ secrets.NCP_CONTAINER_REGISTRY }}
username: ${{ secrets.NCP_ACCESS_KEY }}
password: ${{ secrets.NCP_SECRET_KEY }}
- uses: docker/build-push-action@v3
with:
context: .
file: ./BackEnd/Dockerfile
push: true
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest
- name: SSH to Internal Server and Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.BASTION_HOST }}
username: ${{ secrets.BASTION_USER }}
password: ${{ secrets.BASTION_PASSWORD }}
port: 22
script: |
sshpass -p ${{ secrets.SERVER_PASSWORD }} ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.INTERNAL_SERVER_IP }} -p 22 '
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest
docker stop my-app || true
docker rm my-app || true
docker cp /var/env/.env my-app:/var/env/.env
docker run --name my-app -d -p 443:3000 -p 80:3000 -p 3306:3306 --env-file /var/env/.env ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest
'