Skip to content

Commit c9ed75c

Browse files
authored
Dockerfile updates (#432)
* Dockerfile updates - Also uses OpenContainer annotations as in our product images - Switches to a different user id for security reasons * Fix template strings to use {[ and }] * Update hadolint * Add docker syntax directive and a validation check * Add comment for hadolint
1 parent a16c534 commit c9ed75c

File tree

3 files changed

+83
-17
lines changed

3 files changed

+83
-17
lines changed

.github/workflows/pr_pre-commit.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
pull_request:
66

77
env:
8-
HADOLINT_VERSION: "v1.17.6"
8+
HADOLINT_VERSION: "v2.12.0"
99

1010
jobs:
1111
pre-commit:
@@ -18,6 +18,8 @@ jobs:
1818
with:
1919
python-version: '3.12'
2020
- name: Setup Hadolint
21+
# We need to download this here due to a bug in the pre-commit/hadolint setup
22+
# https://github.com/hadolint/hadolint/issues/886
2123
shell: bash
2224
run: |
2325
set -euo pipefail

config/versions.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ rust_version: 1.80.1
77
# IMPORTANT
88
# If you change the Hadolint version here, make sure to also change the hook
99
# refs in the local and template .pre-commit-config.yaml files.
10+
# And due to a bug you also need to update the version in .github/workflows/pr_pre_commit.yml
1011
hadolint_version: v2.12.0

template/docker/Dockerfile.j2

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,102 @@
1+
# syntax=docker/dockerfile:1.10.0@sha256:865e5dd094beca432e8c0a1d5e1c465db5f998dca4e439981029b3b81fb39ed5
2+
# NOTE: The syntax directive needs to be the first line in a Dockerfile
3+
14
# =============
25
# This file is automatically generated from the templates in stackabletech/operator-templating
36
# DON'T MANUALLY EDIT THIS FILE
47
# =============
8+
9+
# https://docs.docker.com/build/checks/#fail-build-on-check-violations
10+
# check=error=true
11+
512
# We want to automatically use the latest. We also don't tag our images with a version.
613
# hadolint ignore=DL3007
714
FROM oci.stackable.tech/sdp/ubi9-rust-builder:latest AS builder
815

16+
917
# We want to automatically use the latest.
1018
# hadolint ignore=DL3007
1119
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest AS operator
1220

1321
ARG VERSION
1422
ARG RELEASE="1"
1523

16-
LABEL name="Stackable Operator for {[ operator.pretty_string }]" \
17-
maintainer="[email protected]" \
18-
vendor="Stackable GmbH" \
19-
version="${VERSION}" \
20-
release="${RELEASE}" \
21-
summary="Deploy and manage {[ operator.pretty_string }] clusters." \
22-
description="Deploy and manage {[ operator.pretty_string }] clusters."
24+
# These are chosen at random and are this high on purpose to have very little chance to clash with an existing user or group on the host system
25+
ARG STACKABLE_USER_GID="574654813"
26+
ARG STACKABLE_USER_UID="782252253"
27+
28+
# These labels have mostly been superceded by the OpenContainer spec annotations below but it doesn't hurt to include them
29+
# http://label-schema.org/rc1/
30+
LABEL name="Stackable Operator for {[ operator.pretty_string }]"
31+
LABEL maintainer="[email protected]"
32+
LABEL vendor="Stackable GmbH"
33+
LABEL version="${VERSION}"
34+
LABEL release="${RELEASE}"
35+
LABEL summary="Deploy and manage {[ operator.pretty_string }] clusters."
36+
LABEL description="Deploy and manage {[ operator.pretty_string }] clusters."
2337

38+
# Overwriting/Pinning UBI labels
39+
# https://github.com/projectatomic/ContainerApplicationGenericLabels
40+
LABEL vcs-ref=""
41+
LABEL distribution-scope="public"
42+
LABEL url="https://stackable.tech"
43+
ARG TARGETARCH
44+
LABEL architecture="${TARGETARCH}"
45+
LABEL com.redhat.component=""
46+
# It complains about it being an invalid label but RedHat uses it and we want to override it and it works....
47+
# hadolint ignore=DL3048
48+
LABEL com.redhat.license_terms=""
49+
LABEL io.buildah.version=""
50+
LABEL io.openshift.expose-services=""
51+
52+
# https://github.com/opencontainers/image-spec/blob/036563a4a268d7c08b51a08f05a02a0fe74c7268/annotations.md#annotations
53+
LABEL org.opencontainers.image.authors="[email protected]"
54+
LABEL org.opencontainers.image.url="https://stackable.tech"
55+
LABEL org.opencontainers.image.vendor="Stackable GmbH"
56+
LABEL org.opencontainers.image.licenses="OSL-3.0"
57+
LABEL org.opencontainers.image.documentation="https://docs.stackable.tech/home/stable/{[ operator.product_string }]/"
58+
LABEL org.opencontainers.image.version="${VERSION}"
59+
LABEL org.opencontainers.image.revision="${RELEASE}"
60+
LABEL org.opencontainers.image.title="Stackable Operator for {[ operator.pretty_string }]"
61+
LABEL org.opencontainers.image.description="Deploy and manage {[ operator.pretty_string }] clusters."
62+
63+
# https://docs.openshift.com/container-platform/4.16/openshift_images/create-images.html#defining-image-metadata
64+
# https://github.com/projectatomic/ContainerApplicationGenericLabels/blob/master/vendor/redhat/labels.md
65+
LABEL io.openshift.tags="ubi9,stackable,sdp,{[ operator.product_string }]"
66+
LABEL io.k8s.description="Deploy and manage {[ operator.pretty_string }] clusters."
67+
LABEL io.k8s.display-name="Stackable Operator for {[ operator.pretty_string }]"
68+
69+
RUN <<EOF
2470
# Update image and install kerberos client libraries
2571
# install_weak_deps in microdnf does not support the literal "False" as dnf does
2672
# https://github.com/rpm-software-management/microdnf/blob/a600c62f29262d71a6259b70dc220df65a2ab9b5/dnf/dnf-main.c#L176-L189
73+
microdnf update
2774
# NOTE (@NickLarsenNZ): Maybe we should consider pinning package versions?
2875
# hadolint ignore=DL3041
29-
RUN microdnf update -y --setopt=install_weak_deps=0 \
30-
&& microdnf install -y --setopt=install_weak_deps=0 \
31-
krb5-libs \
32-
libkadm5 \
33-
&& microdnf clean all \
34-
&& rm -rf /var/cache/yum
76+
microdnf install -y \
77+
krb5-libs \
78+
libkadm5 \
79+
shadow-utils
80+
81+
groupadd --gid ${STACKABLE_USER_GID} --system ${STACKABLE_USER_NAME}
82+
# The --no-log-init is required to work around a bug/problem in Go/Docker when very large UIDs are used
83+
# See https://github.com/moby/moby/issues/5419#issuecomment-41478290 for more context
84+
# Making this a system user prevents a mail dir from being created, expiry of passwords etc. but it will warn:
85+
# useradd warning: stackable's uid 1000 is greater than SYS_UID_MAX 999
86+
# We can safely ignore this warning, to get rid of the warning we could change /etc/login.defs but that does not seem worth it
87+
# We'll leave the home directory hardcoded to /stackable because I don't want to deal with which chars might be valid and which might not in user name vs. directory
88+
useradd \
89+
--no-log-init \
90+
--gid ${STACKABLE_USER_GID} \
91+
--uid ${STACKABLE_USER_UID} \
92+
--system \
93+
--create-home \
94+
--home-dir /stackable \
95+
stackable
96+
microdnf remove shadow-utils
97+
microdnf clean all
98+
rm -rf /var/cache/yum
99+
EOF
35100
36101
COPY LICENSE /licenses/LICENSE
37102
@@ -40,9 +105,7 @@ COPY --from=builder /app/* /usr/local/bin/
40105
COPY deploy/config-spec/properties.yaml /etc/stackable/{[operator.name}]/config-spec/properties.yaml
41106
# {[% endif %}]
42107
43-
RUN groupadd -g 1000 stackable && adduser -u 1000 -g stackable -c 'Stackable Operator' stackable
44-
45-
USER stackable:stackable
108+
USER ${STACKABLE_USER_UID}
46109
47110
ENTRYPOINT ["stackable-{[ operator.name }]"]
48111
CMD ["run"]

0 commit comments

Comments
 (0)