Server Deployment #5
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: Server Deployment | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'server/**' | |
workflow_dispatch: # 수동 실행을 허용하는 이벤트 | |
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: make .env | |
if: true | |
run: | | |
cd server | |
echo "${{ secrets.ENV_BE_DB}}" > configs/.env.db.production | |
cd .. | |
cd feed-crawler | |
echo "${{ secrets.ENV_BE_RSS }}" > .env | |
cd .. | |
- 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: ./dockerfile.server | |
push: true | |
tags: ${{ secrets.NCP_CONTAINER_REGISTRY }}/server:latest, | |
${{ secrets.NCP_CONTAINER_REGISTRY }}/server:${{ github.run_number }} | |
cache-from: type=registry,ref=${{ secrets.NCP_CONTAINER_REGISTRY }}/server:latest | |
cache-to: type=inline | |
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.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.SSH_KEY }} | |
port: ${{ secrets.PORT }} | |
script: | | |
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/server | |
docker stop server | |
docker rm server | |
docker run -d --name server --network denannu_refact41-denannu ${{ secrets.NCP_CONTAINER_REGISTRY }}/server | |
docker image prune -f |