-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (52 loc) · 2.06 KB
/
deploy.yaml
File metadata and controls
59 lines (52 loc) · 2.06 KB
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
56
57
58
59
name: Deploy to Batman Server
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code (for access to docker-compose-reverseproxy.yaml and nginx.conf)
uses: actions/checkout@v4
- name: Connect to Tailscale
uses: tailscale/github-action@v2
with:
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
tags: tag:batman-ci
- name: Copy nginx.conf to Batman Server
uses: appleboy/scp-action@v0.1.7
with:
source: "docker-compose-reverseproxy.yaml,nginx.conf"
target: /home/${{ secrets.BATMAN_SERVER_USER}}/
host: ${{ secrets.BATMAN_SERVER_IP }}
username: ${{ secrets.BATMAN_SERVER_USER }}
key: ${{ secrets.BATMAN_SERVER_SSH_KEY }}
- name: Deploy to Batman Server
uses: appleboy/ssh-action@v0.1.0
with:
host: ${{ secrets.BATMAN_SERVER_IP }}
username: ${{ secrets.BATMAN_SERVER_USER }}
key: ${{ secrets.BATMAN_SERVER_SSH_KEY }}
port: 22
script: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker compose -f docker-compose-reverseproxy.yaml up -d
- name: List and remove non-latest images in Batman Server
uses: appleboy/ssh-action@v0.1.0
with:
host: ${{ secrets.BATMAN_SERVER_IP }}
username: ${{ secrets.BATMAN_SERVER_USER }}
key: ${{ secrets.BATMAN_SERVER_SSH_KEY }}
port: 22
script: |
images=$(docker images --format '{{.Repository}}:{{.Tag}} {{.ID}}' | grep -v ':latest')
echo "Images to be removed:"
echo "$images"
while IFS= read -r image; do
repo_tag=$(echo $image | awk '{print $1}')
image_id=$(echo $image | awk '{print $2}')
echo "Removing image $repo_tag with ID $image_id"
docker rmi "$image_id" || true
done <<< "$images"