-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (62 loc) · 2 KB
/
Copy pathdeploy.yml
File metadata and controls
74 lines (62 loc) · 2 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Deploy
on:
push:
branches: [master]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v6
with:
go-version: '1.25.x'
- name: Build binary
run: CGO_ENABLED=0 go build -mod=vendor -o apisrv apisrv/cmd/apisrv
- name: Log in to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: deployments/Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ github.sha }}
build-args: CI_PROJECT_NAME=apisrv
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Copy Nomad job file to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
source: deployments/nomad/apisrv.hcl
target: /tmp/nomad-deploy/
- name: Deploy via Nomad
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
script: |
systemctl stop apprentice.service || true
nomad job run \
-var="image=ghcr.io/${{ github.repository }}:${{ github.sha }}" \
-var="db_user=${{ secrets.DB_USER }}" \
-var="db_name=${{ secrets.DB_NAME }}" \
/tmp/nomad-deploy/deployments/nomad/apisrv.hcl