Skip to content

Merge pull request #1 from thedmdim/compose2 #4

Merge pull request #1 from thedmdim/compose2

Merge pull request #1 from thedmdim/compose2 #4

name: build image, publish and deploy
on:
push:
branches:
- master
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: |
docker build -t ghcr.io/thedmdim/ytstalker:latest .
docker push ghcr.io/thedmdim/ytstalker:latest
deploy:
needs: publish
name: deploy image
runs-on: ubuntu-latest
steps:
- name: prepare ssh
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H "$SERVER_IP" >> ~/.ssh/known_hosts
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_IP: ${{ secrets.SERVER_IP }}
- name: SSH into the server and update the code
run: |
ssh $SERVER_USERNAME@$SERVER_IP 'docker compose -f /root/ytstalker/docker-compose.yml up --pull always -d app'
env:
SERVER_USERNAME: ${{ secrets.SERVER_USERNAME }}
SERVER_IP: ${{ secrets.SERVER_IP }}