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: π Deploy to Naver Cloud Platform | |
on: | |
push: | |
branches: | |
- release # Only in release branch | |
jobs: | |
push_to_registry: | |
name: Push to ncp container registry | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to NCP Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ secrets.NCP_CONTAINER_REGISTRY }} | |
username: ${{ secrets.NCP_ACCESS_KEY }} | |
password: ${{ secrets.NCP_SECRET_KEY }} | |
- name: build and push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: ./backend/Dockerfile | |
push: true | |
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/server:latest | |
cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/server:latest | |
cache-to: type=inline | |
secrets: | | |
GIT_AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }} | |
pull_from_registry: | |
name: Connect server ssh and pull from container registry | |
needs: push_to_registry | |
runs-on: ubuntu-latest | |
steps: | |
- name: connect ssh | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
password: ${{ secrets.SERVER_PASSWORD }} | |
port: ${{ secrets.SERVER_PORT }} | |
script: | | |
sudo docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/server | |
sudo docker stop $(docker ps -a -q) | |
sudo docker rm $(docker ps -a -q) | |
sudo docker run -d -p 3000:3000 --env-file ${{ secrets.ENV_FILE }} -v ${{ secrets.HOST_DIR}}:${{secrets.CONTAINER_DIR}} ${{ secrets.NCP_CONTAINER_REGISTRY }}/server | |
sudo docker image prune -f |