|
1 | 1 | # syntax=docker/dockerfile:1.16.0@sha256:e2dd261f92e4b763d789984f6eab84be66ab4f5f08052316d8eb8f173593acf7 |
2 | | -# check=error=true |
| 2 | +# check=error=true;skip=InvalidDefaultArgInFrom |
| 3 | + |
| 4 | +ARG GOLANG_VERSION |
| 5 | +FROM oci.stackable.tech/sdp/library/golang:${GOLANG_VERSION} AS golang-image |
| 6 | + |
| 7 | +FROM local-image/stackable-devel AS statsd-exporter-builder |
3 | 8 |
|
4 | | -FROM local-image/stackable-base |
5 | 9 | ARG PRODUCT_VERSION |
| 10 | +ARG CYCLONEDX_GOMOD_VERSION |
6 | 11 | ARG STACKABLE_USER_UID |
| 12 | +ARG TARGETARCH |
| 13 | +ARG TARGETOS |
| 14 | + |
| 15 | +ENV CYCLONEDX_GOMOD_VERSION=$CYCLONEDX_GOMOD_VERSION |
| 16 | +ENV GOARCH=$TARGETARCH |
| 17 | +ENV GOOS=$TARGETOS |
7 | 18 |
|
8 | 19 | WORKDIR /statsd_exporter |
9 | 20 |
|
10 | | -RUN --mount=type=cache,id=go-statsd-exporter,uid=${STACKABLE_USER_UID},target=/go_cache <<EOF |
| 21 | +RUN <<EOF |
11 | 22 | microdnf update |
12 | 23 |
|
13 | 24 | # Tar and gzip are used to unpack the statsd_exporter source |
14 | | -# Golang is used to build statsd_exporter |
15 | 25 | # Git is needed by the cyclonedx-gomod tool to determine the version of statsd_exporter |
16 | 26 | microdnf install \ |
17 | 27 | tar \ |
18 | 28 | gzip \ |
19 | | - git \ |
20 | | - golang |
| 29 | + git |
21 | 30 |
|
22 | 31 | microdnf clean all |
23 | 32 | rm -rf /var/cache/yum |
| 33 | +EOF |
24 | 34 |
|
| 35 | +# Manually install Go since the dnf package is sometimes not recent enough |
| 36 | +COPY --from=golang-image /usr/local/go/ /usr/local/go/ |
| 37 | +ENV PATH="/usr/local/go/bin:${PATH}" |
| 38 | + |
| 39 | +COPY --chown=${STACKABLE_USER_UID}:0 shared/statsd-exporter/stackable/patches/patchable.toml /statsd_exporter/src/shared/statsd-exporter/stackable/patches/patchable.toml |
| 40 | +COPY --chown=${STACKABLE_USER_UID}:0 shared/statsd-exporter/stackable/patches/${PRODUCT_VERSION} /statsd_exporter/src/shared/statsd-exporter/stackable/patches/${PRODUCT_VERSION} |
| 41 | + |
| 42 | +RUN --mount=type=cache,id=go-statsd-exporter,uid=${STACKABLE_USER_UID},target=/go_cache <<EOF |
25 | 43 | export GOPATH=/go_cache |
26 | | -# We use version 1.7.0, since a newer version of cyclonedx-gomod is not compatible with the version of Golang (>= 1.23.1) |
27 | | -go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v1.7.0 |
| 44 | +go install "github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v${CYCLONEDX_GOMOD_VERSION}" |
28 | 45 |
|
29 | | -curl "https://repo.stackable.tech/repository/packages/statsd_exporter/statsd_exporter-${PRODUCT_VERSION}.src.tar.gz" | tar -xzC . |
30 | 46 | ( |
31 | | - cd "statsd_exporter-${PRODUCT_VERSION}" || exit |
| 47 | + cd "$(/stackable/patchable --images-repo-root=src checkout shared/statsd-exporter ${PRODUCT_VERSION})" |
| 48 | + |
| 49 | + # Create snapshot of the source code including custom patches |
| 50 | + tar -czf /statsd_exporter/statsd-exporter-${PRODUCT_VERSION}-src.tar.gz . |
32 | 51 |
|
33 | 52 | # Unfortunately, we need to create a dummy Git repository to allow cyclonedx-gomod to determine the version of statsd_exporter |
| 53 | + rm .git |
34 | 54 | git init |
35 | 55 | git config user.email "fake.commiter@stackable.tech" |
36 | 56 | git config user.name "Fake commiter" |
37 | 57 | git commit --allow-empty --message "Fake commit, so that we can create a tag" |
38 | 58 | git tag "v${PRODUCT_VERSION}" |
39 | | - go build -o ../statsd_exporter |
40 | | - $GOPATH/bin/cyclonedx-gomod app -json -output-version 1.5 -output ../statsd_exporter-${PRODUCT_VERSION}.cdx.json -packages -files |
| 59 | + go build -o /statsd_exporter/statsd_exporter |
| 60 | + $GOPATH/bin/cyclonedx-gomod app -json -output-version 1.5 -output /statsd_exporter/statsd_exporter-${PRODUCT_VERSION}.cdx.json -packages -files |
41 | 61 | ) |
42 | 62 | rm -rf "statsd_exporter-${PRODUCT_VERSION}" |
| 63 | +# set correct groups |
| 64 | +chmod -R g=u /statsd_exporter/ |
43 | 65 | EOF |
0 commit comments