-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (93 loc) · 2.76 KB
/
main.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: Test, build and deploy
on:
push:
branches:
- main
workflow_dispatch:
env:
IMAGE: ghcr.io/${{ github.repository }}
#PLATFORMS: linux/amd64,linux/arm64
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.5.3
- name: Start containerized environment
run: make
- name: Set up dependencies
run: make deps
- name: Run linter
run: make lint
- name: Run tests
run: make test
- name: Stop containerized environment
continue-on-error: true
run: make down
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
TAG: ${{ steps.metadata.outputs.TAG }}
steps:
- name: Checkout
uses: actions/checkout@v3.5.3
- name: Set up metadata
id: metadata
run: |
TAG="${GITHUB_SHA::8}"
if [[ "${GITHUB_REF}" == "refs/tags/*" ]]; then
TAG="${GITHUB_REF#refs/tags/v}"
fi
echo "TAG=${TAG}" >> "${GITHUB_OUTPUT}"
#- name: Set up QEMU
# uses: docker/setup-qemu-action@v2.2.0
# with:
# platforms: ${{ env.PLATFORMS }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.9.1
- name: Log into image registry
uses: docker/login-action@v2.2.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build
uses: docker/build-push-action@v4.1.1
with:
context: .
target: runtime
#platforms: ${{ env.PLATFORMS }}
push: true
tags: ${{ env.IMAGE }}:${{ steps.metadata.outputs.TAG }},${{ env.IMAGE }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
runs-on: ubuntu-latest
needs:
- test
- build
steps:
- name: Log into image registry
uses: docker/login-action@v2.2.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract binary
run: |
ID=$(docker create ${{ env.IMAGE }}:${{needs.build.outputs.TAG}} --entrypoint 'sleep infinity')
docker cp "${ID}:/usr/local/bin/bin" ./app
docker rm --volumes "${ID}"
- name: Set up SSH
uses: shimataro/ssh-key-action@v2.5.1
with:
name: id_ed25519
key: ${{ secrets.SSH_KEY }}
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
- name: Deploy
run: |
scp -P 22001 ./app caddy@${{ secrets.WEB_HOST }}:/srv/avptp/brain
ssh caddy@${{ secrets.WEB_HOST }} -p 22001 sudo systemctl restart avptp-brain