Skip to content

Commit 877047c

Browse files
committed
refactoring done
- official netbox library used - check command with filter support - in,out command currently only noop - (unit) tests rewritten - Container image creation updated and documented - Golang image for the build stage - Distroless base without libc and shell for the final image - Concourse config documented - Github workflow for image build and release added - CODEOWNERS added
1 parent 846eb28 commit 877047c

File tree

29 files changed

+1625
-260
lines changed

29 files changed

+1625
-260
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
.git/
21
.idea/
2+
.vscode/
3+
.DS_Store

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @SchwarzM @businessbean

.github/workflows/build-image.yaml

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
name: 'Build and draft release OCI Image'
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
branches-ignore:
7+
- 'master'
8+
jobs:
9+
validateCode:
10+
runs-on: 'ubuntu-24.04'
11+
permissions:
12+
contents: 'read'
13+
steps:
14+
- name: 'checkout code'
15+
uses: 'actions/checkout@v5'
16+
with:
17+
fetch-depth: 0
18+
- name: 'populate env vars'
19+
shell: 'bash'
20+
run: |
21+
#!/usr/bin/env bash
22+
set -euo pipefail
23+
24+
GIT_COMMIT="$(git rev-parse HEAD)"
25+
GIT_TAG="$(git name-rev --tags --name-only ${GIT_COMMIT})"
26+
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
27+
LDFLAGS="-X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.gitCommit=${GIT_COMMIT}' -X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.buildDate=${BUILD_DATE}' -X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.gitVersion=${GIT_TAG}'"
28+
GO_VERSION="$(go list -f {{.GoVersion}} -m)"
29+
echo "GIT_COMMIT=${GIT_COMMIT}" >> "$GITHUB_ENV"
30+
echo "GIT_TAG=${GIT_TAG}" >> "$GITHUB_ENV"
31+
echo "BUILD_DATE=${BUILD_DATE}" >> "$GITHUB_ENV"
32+
echo "LDFLAGS=${LDFLAGS}" >> "$GITHUB_ENV"
33+
echo "GO_VERSION=${GO_VERSION}" >> "$GITHUB_ENV"
34+
- name: 'validate env vars'
35+
shell: 'bash'
36+
run: |
37+
#!/usr/bin/env bash
38+
set -euo pipefail
39+
40+
if [ "${GIT_TAG}" == "undefined" ]; then
41+
echo "no valid tag found"
42+
exit 1
43+
fi
44+
- name: 'setup go'
45+
uses: 'actions/setup-go@v6'
46+
with:
47+
go-version: "${{ env.GO_VERSION }}"
48+
- name: 'golangci-lint'
49+
uses: 'golangci/golangci-lint-action@v8'
50+
with:
51+
version: 'v2.4.0'
52+
- name: 'govulncheck'
53+
shell: 'bash'
54+
run: |
55+
#!/usr/bin/env bash
56+
set -euo pipefail
57+
58+
go install golang.org/x/vuln/cmd/govulncheck@latest
59+
govulncheck -format text -show verbose ./...
60+
- name: 'go test'
61+
shell: 'bash'
62+
run: 'go test -ldflags "${LDFLAGS}" -cover ./...'
63+
- name: 'go build'
64+
shell: 'bash'
65+
run: |
66+
#!/usr/bin/env bash
67+
set -euo pipefail
68+
69+
go build -ldflags "${LDFLAGS}" -o check cmd/check/main.go
70+
go build -ldflags "${LDFLAGS}" -o in cmd/in/main.go
71+
go build -ldflags "${LDFLAGS}" -o out cmd/out/main.go
72+
- name: 'validate version'
73+
shell: 'bash'
74+
run: |
75+
#!/usr/bin/env bash
76+
set -euo pipefail
77+
78+
./check -v | grep -q "${GIT_TAG}"
79+
./in -v | grep -q "${GIT_TAG}"
80+
./out -v | grep -q "${GIT_TAG}"
81+
buildImage:
82+
runs-on: 'ubuntu-24.04'
83+
needs: 'validateCode'
84+
permissions:
85+
contents: 'read'
86+
packages: 'write'
87+
steps:
88+
- name: 'checkout code'
89+
uses: 'actions/checkout@v5'
90+
with:
91+
fetch-depth: 0
92+
- name: 'populate env vars'
93+
shell: 'bash'
94+
run: |
95+
#!/usr/bin/env bash
96+
set -euo pipefail
97+
98+
GIT_COMMIT="$(git rev-parse HEAD)"
99+
GIT_TAG="$(git name-rev --tags --name-only ${GIT_COMMIT})"
100+
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
101+
LDFLAGS="-X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.gitCommit=${GIT_COMMIT}' -X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.buildDate=${BUILD_DATE}' -X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.gitVersion=${GIT_TAG}'"
102+
GO_VERSION="$(go list -f {{.GoVersion}} -m)"
103+
echo "GIT_COMMIT=${GIT_COMMIT}" >> "$GITHUB_ENV"
104+
echo "GIT_TAG=${GIT_TAG}" >> "$GITHUB_ENV"
105+
echo "BUILD_DATE=${BUILD_DATE}" >> "$GITHUB_ENV"
106+
echo "LDFLAGS=${LDFLAGS}" >> "$GITHUB_ENV"
107+
echo "GO_VERSION=${GO_VERSION}" >> "$GITHUB_ENV"
108+
- name: 'validate env vars'
109+
shell: 'bash'
110+
run: |
111+
#!/usr/bin/env bash
112+
set -euo pipefail
113+
114+
if [ "${GIT_TAG}" == "undefined" ]; then
115+
echo "no valid tag found"
116+
exit 1
117+
fi
118+
- name: 'setup go'
119+
uses: 'actions/setup-go@v6'
120+
with:
121+
go-version: "${{ env.GO_VERSION }}"
122+
- name: 'container registry login'
123+
uses: 'docker/login-action@v3'
124+
with:
125+
password: "${{ secrets.GITHUB_TOKEN }}"
126+
registry: 'ghcr.io'
127+
username: "${{ github.actor }}"
128+
- name: 'fetch metadata for the image build'
129+
id: 'meta'
130+
uses: 'docker/metadata-action@v5'
131+
with:
132+
images: "ghcr.io/${{ github.repository }}"
133+
tags: |
134+
type=ref,event=branch
135+
type=semver,pattern={{version}}
136+
type=semver,pattern={{major}}.{{minor}}
137+
type=schedule,pattern={{date 'YYYYMMDD-hhmmss'}}
138+
type=raw,value=draft
139+
- name: 'build and push image'
140+
uses: 'docker/build-push-action@v6'
141+
with:
142+
context: '.'
143+
build-args: |
144+
BUILDER_VERSION=${{ env.GO_VERSION }}-bookworm
145+
GIT_COMMIT=${{ env.GIT_COMMIT }}
146+
GIT_TAG=${{ env.GIT_TAG }}
147+
BUILD_DATE=${{ env.BUILD_DATE}}
148+
labels: "${{ steps.meta.outputs.labels }}"
149+
tags: "${{ steps.meta.outputs.tags }}"
150+
platforms: 'linux/amd64'
151+
push: true
152+
createRelease:
153+
runs-on: 'ubuntu-24.04'
154+
needs: 'buildImage'
155+
permissions:
156+
contents: 'write'
157+
steps:
158+
- name: 'checkout code'
159+
uses: 'actions/checkout@v5'
160+
with:
161+
fetch-depth: 0
162+
- name: 'populate env vars'
163+
shell: 'bash'
164+
run: |
165+
#!/usr/bin/env bash
166+
set -euo pipefail
167+
168+
GIT_COMMIT="$(git rev-parse HEAD)"
169+
GIT_TAG="$(git name-rev --tags --name-only ${GIT_COMMIT})"
170+
echo "GIT_COMMIT=${GIT_COMMIT}" >> "$GITHUB_ENV"
171+
echo "GIT_TAG=${GIT_TAG}" >> "$GITHUB_ENV"
172+
- name: 'validate env vars'
173+
shell: 'bash'
174+
run: |
175+
#!/usr/bin/env bash
176+
set -euo pipefail
177+
178+
if [ "${GIT_TAG}" == "undefined" ]; then
179+
echo "no valid tag found"
180+
exit 1
181+
fi
182+
- name: 'install mdq'
183+
shell: 'bash'
184+
run: |
185+
#!/usr/bin/env bash
186+
set -euo pipefail
187+
188+
curl -LO https://github.com/yshavit/mdq/releases/download/v0.9.0/mdq-linux-x64.tar.gz
189+
tar -xf mdq-linux-x64.tar.gz
190+
rm mdq-linux-x64.tar.gz
191+
- name: 'maintain changelog'
192+
shell: 'bash'
193+
run: |
194+
#!/usr/bin/env bash
195+
set -euo pipefail
196+
197+
cat CHANGELOG.md | ./mdq "# ${GIT_TAG}" >changeLogForRelease.md
198+
echo '* `docker pull ghcr.io/sapcc/concourse-netbox-resource:${{ env.GIT_TAG }}`' >>changeLogForRelease.md
199+
cat changeLogForRelease.md | ./mdq "# ${GIT_TAG}"
200+
- name: 'create release'
201+
uses: 'ncipollo/release-action@v1'
202+
with:
203+
name: concourse-netbox-resource-${{ env.GIT_TAG }}
204+
bodyFile: 'changeLogForRelease.md'
205+
draft: true
206+
makeLatest: "legacy"
207+
tag: "${{ env.GIT_TAG }}"
208+
skipIfReleaseExists: true
209+
allowUpdates: true
210+
updateOnlyUnreleased: true
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: 'Publish release after PR approval'
2+
on:
3+
push:
4+
branches:
5+
- "master"
6+
jobs:
7+
buildImage:
8+
runs-on: 'ubuntu-24.04'
9+
permissions:
10+
contents: 'write'
11+
steps:
12+
- name: 'checkout code'
13+
uses: 'actions/checkout@v5'
14+
- name: 'populate env vars'
15+
shell: 'bash'
16+
run: |
17+
#!/usr/bin/env bash
18+
set -euo pipefail
19+
20+
GIT_COMMIT="$(git rev-parse HEAD)"
21+
GIT_TAG="$(git name-rev --tags --name-only ${GIT_COMMIT})"
22+
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
23+
LDFLAGS="-X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.gitCommit=${GIT_COMMIT}' -X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.buildDate=${BUILD_DATE}' -X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.gitVersion=${GIT_TAG}'"
24+
GO_VERSION="$(go list -f {{.GoVersion}} -m)"
25+
echo "GIT_COMMIT=${GIT_COMMIT}" >> "$GITHUB_ENV"
26+
echo "GIT_TAG=${GIT_TAG}" >> "$GITHUB_ENV"
27+
echo "BUILD_DATE=${BUILD_DATE}" >> "$GITHUB_ENV"
28+
echo "LDFLAGS=${LDFLAGS}" >> "$GITHUB_ENV"
29+
echo "GO_VERSION=${GO_VERSION}" >> "$GITHUB_ENV"
30+
- name: 'validate env vars'
31+
shell: 'bash'
32+
run: |
33+
#!/usr/bin/env bash
34+
set -euo pipefail
35+
36+
if [ "${GIT_TAG}" == "undefined" ]; then
37+
echo "no valid tag found"
38+
exit 1
39+
fi
40+
- name: 'setup go'
41+
uses: 'actions/setup-go@v6'
42+
with:
43+
go-version: "${{ env.GO_VERSION }}"
44+
- name: 'container registry login'
45+
uses: 'docker/login-action@v3'
46+
with:
47+
password: "${{ secrets.GITHUB_TOKEN }}"
48+
registry: 'ghcr.io'
49+
username: "${{ github.actor }}"
50+
- name: 'fetch metadata for the image build'
51+
id: 'meta'
52+
uses: 'docker/metadata-action@v5'
53+
with:
54+
images: "ghcr.io/${{ github.repository }}"
55+
tags: |
56+
type=ref,event=branch
57+
type=semver,pattern={{version}}
58+
type=semver,pattern={{major}}.{{minor}}
59+
type=schedule,pattern={{date 'YYYYMMDD-hhmmss'}}
60+
type=raw,value=release
61+
- name: 'build and push image'
62+
uses: 'docker/build-push-action@v6'
63+
with:
64+
context: '.'
65+
build-args: "BUILDER_VERSION=${{ env.GO_VERSION }}-bookworm"
66+
labels: "${{ steps.meta.outputs.labels }}"
67+
tags: "${{ steps.meta.outputs.tags }}"
68+
platforms: 'linux/amd64'
69+
push: true
70+
createRelease:
71+
runs-on: 'ubuntu-24.04'
72+
needs: 'buildImage'
73+
permissions:
74+
contents: 'write'
75+
steps:
76+
- name: 'checkout code'
77+
uses: 'actions/checkout@v5'
78+
- name: 'populate env vars'
79+
shell: 'bash'
80+
run: |
81+
#!/usr/bin/env bash
82+
set -euo pipefail
83+
84+
GIT_COMMIT="$(git rev-parse HEAD)"
85+
GIT_TAG="$(git name-rev --tags --name-only ${GIT_COMMIT})"
86+
echo "GIT_COMMIT=${GIT_COMMIT}" >> "$GITHUB_ENV"
87+
echo "GIT_TAG=${GIT_TAG}" >> "$GITHUB_ENV"
88+
- name: 'validate env vars'
89+
shell: 'bash'
90+
run: |
91+
#!/usr/bin/env bash
92+
set -euo pipefail
93+
94+
if [ "${GIT_TAG}" == "undefined" ]; then
95+
echo "no valid tag found"
96+
exit 1
97+
fi
98+
- name: 'install mdq'
99+
shell: 'bash'
100+
run: |
101+
#!/usr/bin/env bash
102+
set -euo pipefail
103+
104+
curl -LO https://github.com/yshavit/mdq/releases/download/v0.9.0/mdq-linux-x64.tar.gz
105+
tar -xf mdq-linux-x64.tar.gz
106+
rm mdq-linux-x64.tar.gz
107+
- name: 'maintain changelog'
108+
shell: 'bash'
109+
run: |
110+
#!/usr/bin/env bash
111+
set -euo pipefail
112+
113+
cat CHANGELOG.md | ./mdq "# ${GIT_TAG}" >changeLogForRelease.md
114+
echo '* `docker pull ghcr.io/sapcc/concourse-netbox-resource:${{ env.GIT_TAG }}`' >>changeLogForRelease.md
115+
cat changeLogForRelease.md | ./mdq "# ${GIT_TAG}"
116+
- name: 'create release'
117+
uses: 'ncipollo/release-action@v1'
118+
with:
119+
name: concourse-netbox-resource-${{ env.GIT_TAG }}
120+
bodyFile: 'changeLogForRelease.md'
121+
makeLatest: "legacy"
122+
tag: "${{ env.GIT_TAG }}"
123+
skipIfReleaseExists: true
124+
allowUpdates: true
125+
updateOnlyUnreleased: true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode/
2+
.DS_Store

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# Changelog
3+
4+
## v0.1.0
5+
6+
* official netbox library used
7+
* check command with filter support
8+
* in,out command currently only noop
9+
* (unit) tests rewritten
10+
* Container image creation updated and documented
11+
* Golang image for the build stage
12+
* Distroless base without libc and shell for the final image
13+
* Concourse config documented
14+
* Github actions workflows created

0 commit comments

Comments
 (0)