[GWL-48] [FIX] 수동 배포에서 자동 배포로 구현하기 [도커] #1
Workflow file for this run
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
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 Tunneling and Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.BASTION_HOST }} | |
username: ${{ secrets.BASTION_USER }} | |
key: ${{ secrets.BASTION_SSH_KEY }} | |
script: | | |
ssh -o StrictHostKeyChecking=no -L 9999:${{ secrets.INTERNAL_SERVER_IP }}:22 ${{ secrets.BASTION_USER }}@localhost -i ${{ secrets.BASTION_SSH_PRIVATE_KEY_PATH }} -fN | |
ssh -o StrictHostKeyChecking=no -p 9999 ${{ secrets.SERVER_USER }}@localhost -i ${{ secrets.SERVER_SSH_PRIVATE_KEY_PATH }} ' | |
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest | |
docker stop my-app || true | |
docker rm my-app || true | |
docker run --name my-app -d -p 3000:3000 --env-file /var/env/.env ${{ secrets.NCP_CONTAINER_REGISTRY }}/my-app:latest | |
' |