-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (81 loc) · 2.48 KB
/
docker-image.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Build and push image
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build-binary:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
- name: Build
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/resume ./src/*.go
- name: List files in ./bin directory
run: |
ls -lhr ./bin
- uses: actions/upload-artifact@master
with:
name: compiled-binary
path: ./bin/resume
build-and-push-image:
runs-on: ubuntu-latest
needs: build-binary
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@master
with:
name: compiled-binary
path: ./bin/resume
- name: List files in ./bin directory
run: |
ls -lhr ./bin
- name: List files in current directory
run: |
pwd
ls -lhr .
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: rogierlommers/resume:latest
pull-and-run-latest:
name: "Pull latest image and run"
runs-on: ubuntu-latest
needs: build-and-push-image
steps:
# More info: https://github.com/tailscale/github-action
- name: Tailscale
uses: tailscale/github-action@v2
with:
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
tags: tag:ci
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/ssh.key
chmod 600 ~/.ssh/ssh.key
cat >>~/.ssh/config <<END
Host services
HostName $(tailscale ip -4 services)
User $SSH_USER
IdentityFile ~/.ssh/ssh.key
StrictHostKeyChecking no
Port 22
END
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_KEY: ${{ secrets.SSH_KEY }}
- name: Run docker-compose commands
run: ssh services 'cd /srv/local/services && docker compose kill resume && docker system prune --all --force && docker compose up resume -d'
- name: Run tailscale logouut
run: sudo tailscale logout