|
| 1 | +# syntax=docker/dockerfile:1.16.0@sha256:e2dd261f92e4b763d789984f6eab84be66ab4f5f08052316d8eb8f173593acf7 |
| 2 | +# check=error=true;skip=InvalidDefaultArgInFrom |
| 3 | + |
| 4 | +ARG GOLANG |
| 5 | + |
| 6 | +FROM oci.stackable.tech/sdp/library/golang:${GOLANG} AS golang-image |
| 7 | + |
| 8 | +FROM stackable/image/stackable-devel AS elasticsearch-exporter-builder |
| 9 | + |
| 10 | +ARG PRODUCT |
| 11 | +ARG PROMU |
| 12 | +ARG RELEASE |
| 13 | +ARG STACKABLE_USER_UID |
| 14 | +ARG TARGETARCH |
| 15 | +ARG TARGETOS |
| 16 | + |
| 17 | +ENV GOARCH=$TARGETARCH |
| 18 | +ENV GOOS=$TARGETOS |
| 19 | + |
| 20 | +# tar - used to archive the elasticsearch-exporter source |
| 21 | +# git - needed by patchable and the cyclonedx-gomod tool to determine the version of elasticsearch-exporter |
| 22 | +RUN <<EOF |
| 23 | +microdnf update |
| 24 | +microdnf install \ |
| 25 | + git \ |
| 26 | + tar |
| 27 | +microdnf clean all |
| 28 | +EOF |
| 29 | + |
| 30 | +# Manually install Go since the dnf package is sometimes not recent enough |
| 31 | +COPY --from=golang-image /usr/local/go/ /usr/local/go/ |
| 32 | +ENV PATH="/usr/local/go/bin:${PATH}" |
| 33 | + |
| 34 | +COPY --chown=${STACKABLE_USER_UID}:0 opensearch/elasticsearch-exporter/stackable/patches/patchable.toml /stackable/src/opensearch/elasticsearch-exporter/stackable/patches/patchable.toml |
| 35 | +COPY --chown=${STACKABLE_USER_UID}:0 opensearch/elasticsearch-exporter/stackable/patches/${PRODUCT} /stackable/src/opensearch/elasticsearch-exporter/stackable/patches/${PRODUCT} |
| 36 | + |
| 37 | +WORKDIR /stackable |
| 38 | + |
| 39 | +RUN <<EOF |
| 40 | +# We use version 1.7.0, since a newer version of cyclonedx-gomod is not compatible with the version of Golang (>= 1.23.1) |
| 41 | +go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v1.7.0 |
| 42 | +# prometheus utility |
| 43 | +go install github.com/prometheus/promu@v0.17.0 |
| 44 | + |
| 45 | +cd "$(/stackable/patchable --images-repo-root=src checkout opensearch/elasticsearch-exporter ${PRODUCT})" |
| 46 | + |
| 47 | +ORIGINAL_VERSION=${PRODUCT} |
| 48 | +NEW_VERSION="${PRODUCT}-stackable${RELEASE}" |
| 49 | + |
| 50 | +# Create snapshot of the source code including custom patches |
| 51 | +tar -czf /stackable/opensearch-elasticsearch-exporter-${NEW_VERSION}-src.tar.gz . |
| 52 | + |
| 53 | +# Unfortunately, we need to create a dummy Git repository to allow cyclonedx-gomod to determine the version of elasticsearch-exporter |
| 54 | +rm .git |
| 55 | +git init |
| 56 | +git config user.email "fake.commiter@stackable.tech" |
| 57 | +git config user.name "Fake commiter" |
| 58 | +git commit --allow-empty --message "Fake commit, so that we can create a tag" |
| 59 | +git tag "v${NEW_VERSION}" |
| 60 | +# required by promu |
| 61 | +git remote add origin https://github.com/stackabletech/elasticsearch_exporter.git |
| 62 | +make build |
| 63 | +# move artifact to /stackable/*/ to copy in final image |
| 64 | +~/go/bin/cyclonedx-gomod app -json -output-version 1.5 -output "/stackable/opensearch-elasticsearch-exporter-${NEW_VERSION}.cdx.json" -packages -files |
| 65 | +sed -i "s/${NEW_VERSION}/${ORIGINAL_VERSION}/g" "/stackable/opensearch-elasticsearch-exporter-${NEW_VERSION}.cdx.json" |
| 66 | +# move artifact to /stackable/* to copy in final image |
| 67 | +mv elasticsearch_exporter /stackable/elasticsearch_exporter |
| 68 | +# set correct groups |
| 69 | +chmod -R g=u /stackable/elasticsearch_exporter /stackable/opensearch-elasticsearch-exporter-${NEW_VERSION}-src.tar.gz /stackable/opensearch-elasticsearch-exporter-${NEW_VERSION}.cdx.json |
| 70 | +EOF |
0 commit comments