Skip to content

Commit db06149

Browse files
authored
Build statsd_exporter from source (#777)
* feat: build statsd_exporter from source * fix: hadolint / comments * fix: hadolint * fix: pre-commit lint fixes * fix: shellcheck * chore: reverted changes related to druid, will create separate PR for those * fix: use heredoc and caching * docs: adapted changelog * fix: use heredoc for the package installation part * fix: merge RUN layers * docs: clarified hadolint ignore comments
1 parent 71868da commit db06149

File tree

8 files changed

+69
-26
lines changed

8 files changed

+69
-26
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ All notable changes to this project will be documented in this file.
3434
- superset: Add version `3.1.3` and `4.0.2` ([#768]).
3535
- druid: Support for 30.0.0 using Java 17 ([#731])
3636
- hbase: Support for HBase 2.4.18 ([#740]).
37+
- airflow & superset: Build `statsd_exporter` from source ([#777]).
3738

3839
### Changed
3940

@@ -132,6 +133,7 @@ All notable changes to this project will be documented in this file.
132133
[#762]: https://github.com/stackabletech/docker-images/pull/762
133134
[#767]: https://github.com/stackabletech/docker-images/pull/767
134135
[#768]: https://github.com/stackabletech/docker-images/pull/768
136+
[#777]: https://github.com/stackabletech/docker-images/pull/777
135137

136138
## [24.3.0] - 2024-03-20
137139

airflow/Dockerfile

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ ARG GIT_SYNC
1010
# which should contain a image location (e.g. registry.k8s.io/git-sync/git-sync:v3.6.8)
1111
FROM oci.stackable.tech/sdp/git-sync:${GIT_SYNC} as gitsync-image
1212

13+
# Not tagging base image because it is built as part of the same process
14+
# hadolint ignore=DL3006
15+
FROM stackable/image/statsd_exporter AS statsd_exporter-builder
16+
1317
FROM stackable/image/vector AS airflow-build-image
1418

1519
ARG PRODUCT
1620
ARG PYTHON
17-
ARG STATSD_EXPORTER
1821
ARG TARGETARCH
1922
ARG TARGETOS
2023

@@ -26,8 +29,6 @@ ENV AIRFLOW_EXTRAS=async,amazon,celery,cncf.kubernetes,docker,dask,elasticsearch
2629

2730
RUN microdnf update && \
2831
microdnf install \
29-
# Used to extract statsd_exporter
30-
tar \
3132
cyrus-sasl-devel \
3233
# Needed by ./configure to build gevent, see snippet [1] at the end of file
3334
diffutils \
@@ -53,11 +54,8 @@ RUN python3 -m venv --system-site-packages /stackable/app && \
5354
# Needed for pandas S3 integration to e.g. write and read csv and parquet files to/from S3
5455
pip install --no-cache-dir s3fs
5556

56-
# Choosing correct binary with respect to architecture
5757
WORKDIR /stackable
58-
RUN curl --fail -L "https://repo.stackable.tech/repository/packages/statsd_exporter/statsd_exporter-${STATSD_EXPORTER}.${TARGETOS}-${TARGETARCH}.tar.gz" | \
59-
tar -xzC /stackable && ln -s "statsd_exporter-${STATSD_EXPORTER}.${TARGETOS}-${TARGETARCH}/statsd_exporter" statsd_exporter
60-
58+
COPY --from=statsd_exporter-builder /statsd_exporter/statsd_exporter /stackable/statsd_exporter
6159

6260
FROM stackable/image/vector AS airflow-main-image
6361

conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
testing_tools = importlib.import_module("testing-tools.versions")
3333
zookeeper = importlib.import_module("zookeeper.versions")
3434
tools = importlib.import_module("tools.versions")
35+
statsd_exporter = importlib.import_module("statsd_exporter.versions")
3536

3637
products = [
3738
{"name": "airflow", "versions": airflow.versions},
@@ -58,6 +59,7 @@
5859
{"name": "testing-tools", "versions": testing_tools.versions},
5960
{"name": "zookeeper", "versions": zookeeper.versions},
6061
{"name": "tools", "versions": tools.versions},
62+
{"name": "statsd_exporter", "versions": statsd_exporter.versions},
6163
]
6264

6365
open_shift_projects = {

statsd_exporter/Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# syntax=docker/dockerfile:1.8.1@sha256:e87caa74dcb7d46cd820352bfea12591f3dba3ddc4285e19c7dcd13359f7cefd
2+
3+
# Ignoring DL3038 globally because set `assumeyes=True` in dnf.conf in our base image
4+
# Ignoring DL4006 globally because we inherit the SHELL from our base image
5+
# hadolint global ignore=DL3038,DL4006
6+
7+
# Not tagging base image because this is an intermediate image
8+
# hadolint ignore=DL3006
9+
FROM stackable/image/stackable-base
10+
ARG PRODUCT
11+
12+
WORKDIR /statsd_exporter
13+
14+
# Ignoring DL3041 because we don't pin versions
15+
# Ignoring DL3003 because using `WORKDIR` would require us to split the RUN command into multiple layers
16+
# hadolint ignore=DL3041,DL3003
17+
RUN --mount=type=cache,id=go-statsd-exporter,uid=1000,target=/go_cache <<EOF
18+
microdnf update
19+
20+
# Tar and gzip are used to unpack the statsd_exporter source
21+
# Golang is used to build statsd_exporter
22+
microdnf install \
23+
tar \
24+
gzip \
25+
golang
26+
27+
microdnf clean all
28+
rm -rf /var/cache/yum
29+
30+
export GOPATH=/go_cache
31+
curl --fail -L "https://repo.stackable.tech/repository/packages/statsd_exporter/statsd_exporter-${PRODUCT}.src.tar.gz" | tar -xzC .
32+
(
33+
cd "statsd_exporter-${PRODUCT}" || exit
34+
go build -o ../statsd_exporter
35+
)
36+
rm -rf "statsd_exporter-${PRODUCT}"
37+
EOF

statsd_exporter/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# statsd_exporter
2+
3+
This is the Docker image that builds statsd_exporter.
4+
5+
This image does _not_ need to be built manually.
6+
It will be built automatically if specified as a dependency in our `conf.py` file.
7+
Which will then be transformed to a dependency in a Docker `buildx bake` file.

.scripts/upload_new_statsd_exporter_version.sh renamed to statsd_exporter/upload_new_statsd_exporter_version.sh

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ set -euo pipefail
55
VERSION=${1:?"Missing version number argument (arg 1)"}
66
NEXUS_USER=${2:?"Missing Nexus username argument (arg 2)"}
77

8-
ARCHITECTURES=(
9-
arm64
10-
amd64
11-
)
12-
138
read -r -s -p "Nexus Password: " NEXUS_PASSWORD
149
echo ""
1510

@@ -36,14 +31,11 @@ trap cleanup EXIT
3631

3732
cd "$WORK_DIR" || exit
3833

39-
for arch in "${ARCHITECTURES[@]}"; do
40-
# Statsd_exporter does not currently publish signatures or SBOMs
41-
echo "Downloading STATSD EXPORTER"
42-
curl --fail -LOs "https://github.com/prometheus/statsd_exporter/releases/download/v$VERSION/statsd_exporter-$VERSION.linux-$arch.tar.gz"
34+
echo "Downloading STATSD EXPORTER source code"
35+
curl --fail -LOs "https://github.com/prometheus/statsd_exporter/archive/refs/tags/v$VERSION.tar.gz" && mv "v$VERSION.tar.gz" "statsd_exporter-$VERSION.src.tar.gz"
4336

44-
echo "Uploading to Nexus"
45-
curl --fail -u "$NEXUS_USER:$NEXUS_PASSWORD" --upload-file "statsd_exporter-$VERSION.linux-$arch.tar.gz" 'https://repo.stackable.tech/repository/packages/statsd_exporter/'
46-
done
37+
echo "Uploading to Nexus"
38+
curl --fail -u "$NEXUS_USER:$NEXUS_PASSWORD" --upload-file "statsd_exporter-$VERSION.src.tar.gz" 'https://repo.stackable.tech/repository/packages/statsd_exporter/'
4739

48-
echo "Successfully uploaded new version of STATSD-EXPORTER ($VERSION) to Nexus"
40+
echo "Successfully uploaded new version of STATSD-EXPORTER source code ($VERSION) to Nexus"
4941
echo "https://repo.stackable.tech/service/rest/repository/browse/packages/statsd_exporter/"

statsd_exporter/versions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
versions = [
2+
{
3+
"product": "0.26.1",
4+
"stackable-base": "1.0.0",
5+
}
6+
]

superset/Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44
# Ignoring DL4006 globally because we inherit the SHELL from our base image
55
# hadolint global ignore=DL3038,DL4006
66

7+
# Not tagging base image because it is built as part of the same process
8+
# hadolint ignore=DL3006
9+
FROM stackable/image/statsd_exporter AS statsd_exporter-builder
10+
711
FROM stackable/image/vector AS builder
812

913
ARG PRODUCT
1014
ARG PYTHON
1115
ARG AUTHLIB
12-
ARG STATSD_EXPORTER
1316
ARG TARGETARCH
1417
ARG TARGETOS
1518

1619
COPY superset/constraints-${PRODUCT}.txt /tmp/constraints.txt
1720

1821
RUN microdnf update \
1922
&& microdnf install \
20-
# Used to extract statsd_exporter
21-
tar \
2223
cyrus-sasl-devel \
2324
# Needed to find all patch files, used in `apply_patches.sh`
2425
findutils \
@@ -75,10 +76,8 @@ RUN python3 -m venv /stackable/app \
7576
COPY superset/stackable/patches /patches
7677
RUN /patches/apply_patches.sh ${PRODUCT}
7778

78-
# Choosing correct binary with respect to architecture
7979
WORKDIR /stackable
80-
RUN curl --fail -L "https://repo.stackable.tech/repository/packages/statsd_exporter/statsd_exporter-${STATSD_EXPORTER}.${TARGETOS}-${TARGETARCH}.tar.gz" | \
81-
tar -xzC /stackable && ln -s "statsd_exporter-${STATSD_EXPORTER}.${TARGETOS}-${TARGETARCH}/statsd_exporter" statsd_exporter
80+
COPY --from=statsd_exporter-builder /statsd_exporter/statsd_exporter /stackable/statsd_exporter
8281

8382
# Final image
8483
FROM stackable/image/vector

0 commit comments

Comments
 (0)