| 1 |
# Copyright 2019 The Kubernetes Authors. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
# This image is a haproxy image + minimal config so the container will not exit |
| 16 |
# while we rewrite the config at runtime and signal haproxy to reload. |
| 17 |
|
| 18 |
ARG BASE="registry.k8s.io/build-image/debian-base:bullseye-v1.4.3" |
| 19 |
FROM ${BASE} AS build |
| 20 |
|
| 21 |
# NOTE: copyrights.tar.gz is a quirk of Kubernetes's debian-base image |
| 22 |
# We extract these here so we can grab the relevant files are easily |
| 23 |
# staged for copying into our final image. |
| 24 |
RUN [ ! -f /usr/share/copyrights.tar.gz ] || tar -C / -xzvf /usr/share/copyrights.tar.gz |
| 25 |
|
| 26 |
# install: |
| 27 |
# - haproxy (see: https://haproxy.debian.net/) |
| 28 |
# - bash (ldd is a bash script and debian-base removes bash) |
| 29 |
# - procps (for `kill` which kind needs) |
| 30 |
RUN apt update && \ |
| 31 |
apt install -y --no-install-recommends haproxy=2.2.\* \ |
| 32 |
procps bash |
| 33 |
|
| 34 |
# copy in script for staging distro provided binary to distroless |
| 35 |
COPY --chmod=0755 stage-binary-and-deps.sh /usr/local/bin/ |
| 36 |
|
| 37 |
# stage everything for copying into the final image |
| 38 |
# NOTE: kind currently also uses "mkdir" and "cp" to write files within the container |
| 39 |
# TODO: mkdir especially should be unnecessary, with a little refactoring |
| 40 |
# NOTE: kill is used to signal haproxy to reload |
| 41 |
ARG STAGE_DIR="/opt/stage" |
| 42 |
RUN mkdir -p "${STAGE_DIR}" && \ |
| 43 |
stage-binary-and-deps.sh haproxy "${STAGE_DIR}" && \ |
| 44 |
stage-binary-and-deps.sh cp "${STAGE_DIR}" && \ |
| 45 |
stage-binary-and-deps.sh mkdir "${STAGE_DIR}" && \ |
| 46 |
stage-binary-and-deps.sh kill "${STAGE_DIR}" && \ |
| 47 |
find "${STAGE_DIR}" |
| 48 |
|
| 49 |
################################################################################ |
| 50 |
|
| 51 |
# See: https://github.com/GoogleContainerTools/distroless/tree/main/base |
| 52 |
# This has /etc/passwd, tzdata, cacerts |
| 53 |
FROM "gcr.io/distroless/static-debian11" |
| 54 |
|
| 55 |
ARG STAGE_DIR="/opt/stage" |
| 56 |
|
| 57 |
# copy staged binary + deps + copyright |
| 58 |
COPY --from=build "${STAGE_DIR}/" / |
| 59 |
|
| 60 |
# add our minimal config |
| 61 |
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg |
| 62 |
|
| 63 |
# below roughly matches the standard haproxy image |
| 64 |
STOPSIGNAL SIGUSR1 |
| 65 |
ENTRYPOINT ["haproxy", "-W", "-db", "-f", "/usr/local/etc/haproxy/haproxy.cfg"] |