-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (147 loc) · 4.73 KB
/
Copy pathbuild-controller.yml
File metadata and controls
164 lines (147 loc) · 4.73 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Build Controller Image
on:
push:
branches: [main, develop]
tags: ["v*.*.*"]
paths:
- "cmd/sandbox/**"
- "pkg/**"
- "api/**"
- "go.mod"
- "go.sum"
- "installer/dockerfile/Dockerfile.controller"
- "installer/dockerfile/Dockerfile.controller.runner"
- ".github/workflows/build-controller.yml"
pull_request:
paths:
- "cmd/sandbox/**"
- "pkg/**"
- "api/**"
- "go.mod"
- "go.sum"
- "installer/dockerfile/Dockerfile.controller"
- "installer/dockerfile/Dockerfile.controller.runner"
- ".github/workflows/build-controller.yml"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/agent-sandbox-controller
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: make lint-config
- run: make lint
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: go mod tidy
- run: make test
build-binaries:
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Resolve build version
id: build-version
run: |
if [[ "${{ github.ref_type }}" == "tag" ]]; then
VER="${{ github.ref_name }}"
VER="${VER#v}"
else
SHORT="${{ github.sha }}"
VER="$(cat VERSION)+dev.${SHORT:0:7}"
fi
echo "value=${VER}" >> $GITHUB_OUTPUT
- name: Cross-compile binaries
run: |
mkdir -p installer/dockerfile/bin
LDFLAGS="-s -w -X github.com/scitix/agent-sandbox/pkg/version.Version=${{ steps.build-version.outputs.value }}"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="${LDFLAGS}" -o installer/dockerfile/bin/sandbox-amd64 ./cmd/sandbox
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags="${LDFLAGS}" -o installer/dockerfile/bin/sandbox-arm64 ./cmd/sandbox
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: controller-binaries
path: installer/dockerfile/bin/
retention-days: 1
build-image:
runs-on: ubuntu-latest
needs: build-binaries
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: controller-binaries
path: installer/dockerfile/bin/
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=short
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: installer/dockerfile/Dockerfile.controller.runner
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=controller-runner
cache-to: type=gha,scope=controller-runner,mode=max
cleanup:
runs-on: ubuntu-latest
needs: build-image
if: github.event_name != 'pull_request'
permissions:
contents: read
packages: write
steps:
- name: Clean up old non-release images
uses: quartx-analytics/ghcr-cleaner@v1
with:
owner-type: org
token: ${{ secrets.PAT_TOKEN }}
repository-owner: ${{ github.repository_owner }}
package-name: agent-sandbox-controller
delete-untagged: true
keep-at-most: 3
skip-tags: "*.*.*,latest"
continue-on-error: true