Skip to content

Merge pull request #126 from tnpfldyd/BE-setting/automate-deploy/cach… #5

Merge pull request #126 from tnpfldyd/BE-setting/automate-deploy/cach…

Merge pull request #126 from tnpfldyd/BE-setting/automate-deploy/cach… #5

Workflow file for this run

name: BE-deploy
on:
push:
branches:
- "BE-develop"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: BE-develop
sparse-checkout: nestjs-BE
- name: Login to github Packages
run: echo ${{ secrets.PACKAGE_ACCESS_TOKEN }} | docker login ghcr.io -u ${{ secrets.PACKAGE_USERNAME }} --password-stdin
- name: Build and push Docker image
run: |
docker build -t ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync ./nestjs-BE/server
docker push ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync:latest
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Pull Docker image
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
port: ${{ secrets.REMOTE_PORT }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.REMOTE_SSH_KEY }}
script: |
echo ${{ secrets.PACKAGE_ACCESS_TOKEN }} | docker login ghcr.io -u ${{ secrets.PACKAGE_USERNAME }} --password-stdin
docker pull ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync
docker stop mindsync_server || true
docker rm mindsync_server || true
docker run -d --name mindsync_server -p ${{ secrets.SERVER_PORT }}:${{ secrets.CONTAINER_PORT }} ghcr.io/${{ secrets.PACKAGE_USERNAME }}/mindsync