forked from jmpsec/osctrl
-
Notifications
You must be signed in to change notification settings - Fork 1
198 lines (178 loc) · 7.33 KB
/
build_and_test_main_merge.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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Build and test osctrl
on:
push:
branches:
- main
env:
GOLANG_VERSION: 1.21.3
OSQUERY_VERSION: 5.12.1
jobs:
build_and_test:
runs-on: ubuntu-22.04
strategy:
matrix:
components: ['tls', 'admin', 'api', 'cli']
goos: ['linux', 'darwin', 'windows']
goarch: ['amd64', 'arm64']
steps:
########################### Checkout code ###########################
- name: Checkout code
uses: actions/[email protected]
with:
fetch-depth: 2
########################### Generate SHA1 commit hash ###########################
# https://newbedev.com/getting-current-branch-and-commit-hash-in-github-action
- name: Declare GIT hash and branch
id: vars
shell: bash
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
########################### Build osctrl ###########################
- name: Build osctrl binaries
# Build all osctrl components for linux for all archs
# Build all osctrl components for darwin for all archs
# Build osctrl cli for windows for all archs
if: matrix.goos == 'linux' || matrix.goos == 'darwin' || (matrix.goos == 'windows' && matrix.components == 'cli')
uses: ./.github/actions/build/binaries
with:
go_os: "${{ matrix.goos }}"
go_arch: "${{ matrix.goarch }}"
osctrl_component: "${{ matrix.components }}"
commit_sha: "${{ steps.vars.outputs.sha_short }}"
commit_branch: "${{ steps.vars.outputs.branch }}"
golang_version: "${{ env.GOLANG_VERSION }}"
########################### Test binaries ###########################
# - name: Run tests
# id: bin_tests
# uses: .github/actions/test/binaries
# with:
# go_os: "${{ matrix.goos }}"
# go_arch: "${{ matrix.goarch }}"
# osctrl_component: "${{ matrix.components }}"
# commit_sha: "${{ steps.vars.outputs.sha_short }}"
# commit_branch: "${{ steps.vars.outputs.branch }}"
# golang_version: "${{ env.GOLANG_VERSION }}"
create_deb_packages:
strategy:
matrix:
components: ['tls', 'admin', 'api', 'cli']
goos: ['linux']
goarch: ['amd64']
needs: [build_and_test]
runs-on: ubuntu-22.04
steps:
########################### Checkout code ###########################
- name: Checkout code
uses: actions/[email protected]
with:
fetch-depth: 2
########################### Generate SHA1 commit hash ###########################
# https://newbedev.com/getting-current-branch-and-commit-hash-in-github-action
- name: Declare GIT hash and branch
id: vars
shell: bash
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
########################### Build DEB packages ###########################
- name: Build osctrl DEB packages
uses: ./.github/actions/build/dpkg
with:
go_os: ${{ matrix.goos }}
go_arch: ${{ matrix.goarch }}
osctrl_component: ${{ matrix.components }}
commit_sha: ${{ steps.vars.outputs.sha_short }}
osquery_version: ${{ env.OSQUERY_VERSION }}
create_docker_images:
needs: [build_and_test]
runs-on: ubuntu-22.04
strategy:
matrix:
components: ['tls', 'admin', 'api', 'cli']
goos: ['linux']
goarch: ['amd64', 'arm64']
steps:
########################### Checkout code ###########################
- name: Checkout code
uses: actions/[email protected]
with:
fetch-depth: 2
########################### Generate SHA1 commit hash ###########################
# https://newbedev.com/getting-current-branch-and-commit-hash-in-github-action
- name: Declare GIT hash and branch
id: vars
shell: bash
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
########################### Build Docker containers ###########################
- name: Build and deploy osctrl Docker containers
uses: ./.github/actions/build/docker
with:
#### golang env vars ####
go_os: ${{ matrix.goos }}
go_arch: ${{ matrix.goarch }}
#### Build vars ####
osctrl_component: ${{ matrix.components }}
commit_sha: ${{ steps.vars.outputs.sha_short }}
docker_tag: ${{ steps.vars.outputs.sha_short }}
#### Dockerhub creds ####
docker_hub_org: ${{ secrets.DOCKER_HUB_ORG }}
docker_hub_username: ${{ secrets.DOCKER_HUB_USERNAME }}
docker_hub_access_token: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
########################### Export image digest to tmp ###########################
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.create_docker_images.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
########################### Upload digest ###########################
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
push_docker_images:
needs: [create_docker_images]
runs-on: ubuntu-22.04
strategy:
matrix:
components: ['tls', 'admin', 'api', 'cli']
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_HUB_ORG }}/osctrl-${{ matrix.components }}
tags: |
type=sha
type=semver,pattern={{version}}
# tag latest version for tagged_releases
type=raw,value=latest,enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
########################### Log into Dockerhub ###########################
- name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ secrets.DOCKER_HUB_ORG }}/osctrl-${{ matrix.components }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ secrets.DOCKER_HUB_ORG }}/osctrl-${{ matrix.components }}:${{ steps.meta.outputs.version }}