-
Notifications
You must be signed in to change notification settings - Fork 1
55 lines (48 loc) · 1.41 KB
/
build-and-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
name: build image, publish and deploy
on:
push:
branches:
- master
paths-ignore:
- README.md
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ghcr.io/thedmdim/ytstalker:latest
cache-from: type=gha
cache-to: type=gha,mode=max
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/beget-compose/docker-compose.yml up --pull always -d ytstalker'
env:
SERVER_USERNAME: ${{ secrets.SERVER_USERNAME }}
SERVER_IP: ${{ secrets.SERVER_IP }}