Skip to content

Commit

Permalink
Switch to musl on amd64/arm64... enable other platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
kilna committed May 21, 2024
1 parent 53de564 commit 6850748
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
platforms: linux/amd64,linux/386,linux/arm64,linux/arm,linux/riscv64
push: true
labels: |
org.opencontainers.image.created:${{ github.event.release.created_at }}
Expand Down
42 changes: 28 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM alpine AS build

ARG ENVHTTPD_BUSYBOX_VERSION=1.36.1
ARG ENVHTTPD_TINI_VERSION=0.19.0

LABEL org.opencontainers.image.title="envhttpd"
LABEL org.opencontainers.image.authors="Kilna Anthony <kilna@kilna.com>"
Expand All @@ -15,30 +14,45 @@ COPY ./busybox.config /build/busybox/.config

WORKDIR /build

ARG TARGETARCH

RUN set -e -x; \
tini_base=https://github.com/krallin/tini/releases/download/; \
busybox_base=https://busybox.net/downloads/; \
apk update; \
apk add alpine-sdk dpkg; \
mkdir -p /opt/bin; \
arch="$(dpkg --print-architecture | rev | cut -d- -f1 | rev)"; \
wget "$tini_base/v$ENVHTTPD_TINI_VERSION/tini-static-$arch" \
-O /opt/bin/tini; \
wget "$busybox_base/busybox-$ENVHTTPD_BUSYBOX_VERSION.tar.bz2" \
-O /build/busybox.tar.bz2; \
cd busybox; \
tar -x --strip-components=1 -f ../busybox.tar.bz2; \
make; \
./make_single_applets.sh; \
make V=1 install
case "$TARGETARCH" in \
amd64|arm64*) \
echo "Building busybox on known-working platform $TARGETARCH"; \
apk add alpine-sdk dpkg; \
wget "$busybox_base/busybox-$ENVHTTPD_BUSYBOX_VERSION.tar.bz2" \
-O /build/busybox.tar.bz2; \
cd busybox; \
tar -x --strip-components=1 -f ../busybox.tar.bz2; \
make; \
./make_single_applets.sh; \
make V=1 install;; \
*) \
echo "Installing busybox on platform; Todo: build on $TARGETARCH"; \
apk add busybox-extras; \
cd /opt/bin; \
cp -a /bin/busybox* ./; \
for exe in cat cut env mkdir rev sh tr; do ln -s busybox $exe; done; \
ln -s busybox-extras httpd;; \
esac; \
mkdir -p /opt/lib; \
cp -a /lib/*musl* /opt/lib; \
apk add tini; \
cp /sbin/tini /opt/bin/

# Switch to the scratch image
FROM scratch

COPY --chown=root:root --chmod=644 ./etc/* /etc/
COPY --chown=root:root --chmod=555 ./envhttpd /bin/
COPY --from=build --chown=root:root --chmod=555 /opt/bin/* /bin/
COPY --from=build --chown=root:root --chmod=555 /opt/sbin/* /sbin/
COPY --from=build --chown=root:root --chmod=555 /opt/ /

#RUN ls -laR /bin /etc /lib /sbin

USER www-data
WORKDIR /var/www
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[![GitHub Repo stars](https://img.shields.io/github/stars/kilna/envhttpd?style=social)](https://github.com/kilna/envhttpd/stargazers)

A docker image of a web server that delivers environment variables as JSON and
discrete curl-able endpoints; weighing in at less than 2mb, it is ideal to use
discrete curl-able endpoints; weighing in at less than 1mb, it is ideal to use
as a queryable pod metadata sidecar in Kubernetes, or any situation in which
you need to expose simple data without a lot of overhead.

Expand Down
12 changes: 6 additions & 6 deletions busybox.config
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
#
# Build Options
#
CONFIG_STATIC=y
CONFIG_STATIC=n
# CONFIG_PIE is not set
# CONFIG_NOMMU is not set
# CONFIG_BUILD_LIBBUSYBOX is not set
Expand Down Expand Up @@ -209,7 +209,7 @@ CONFIG_GZIP_FAST=0
# CONFIG_FEATURE_PRESERVE_HARDLINKS is not set
# CONFIG_FEATURE_HUMAN_READABLE is not set
# CONFIG_BASENAME is not set
# CONFIG_CAT is not set
CONFIG_CAT=y
# CONFIG_FEATURE_CATN is not set
# CONFIG_FEATURE_CATV is not set
# CONFIG_CHGRP is not set
Expand Down Expand Up @@ -327,7 +327,7 @@ CONFIG_MKDIR=y
# CONFIG_TIMEOUT is not set
# CONFIG_TOUCH is not set
# CONFIG_FEATURE_TOUCH_SUSV3 is not set
# CONFIG_TR is not set
CONFIG_TR=y
# CONFIG_FEATURE_TR_CLASSES is not set
# CONFIG_FEATURE_TR_EQUIV is not set
# CONFIG_TRUE is not set
Expand Down Expand Up @@ -410,7 +410,7 @@ CONFIG_DEFAULT_SETFONT_DIR=""
# CONFIG_FEATURE_DIFF_DIR is not set
# CONFIG_ED is not set
# CONFIG_PATCH is not set
CONFIG_SED=y
CONFIG_SED=n
# CONFIG_VI is not set
CONFIG_FEATURE_VI_MAX_LEN=0
# CONFIG_FEATURE_VI_8BIT is not set
Expand Down Expand Up @@ -678,7 +678,7 @@ CONFIG_REV=y
# CONFIG_SCRIPTREPLAY is not set
# CONFIG_SETARCH is not set
# CONFIG_LINUX32 is not set
CONFIG_LINUX64=y
CONFIG_LINUX64=n
# CONFIG_SETPRIV is not set
# CONFIG_FEATURE_SETPRIV_DUMP is not set
# CONFIG_FEATURE_SETPRIV_CAPABILITIES is not set
Expand Down Expand Up @@ -866,7 +866,7 @@ CONFIG_FEATURE_HTTPD_PORT_DEFAULT=8111
# CONFIG_FEATURE_HTTPD_SETUID is not set
CONFIG_FEATURE_HTTPD_BASIC_AUTH=n
# CONFIG_FEATURE_HTTPD_AUTH_MD5 is not set
# CONFIG_FEATURE_HTTPD_CGI is not set
CONFIG_FEATURE_HTTPD_CGI=n
# CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set
# CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set
# CONFIG_FEATURE_HTTPD_ENCODE_URL_STR is not set
Expand Down
9 changes: 3 additions & 6 deletions envhttpd
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ json_esc() {
s/\\n/\\n/g; s/\\r/\\r/g; s/\\f/\\f/g; s/\\b/\\b/g;'
}

clean() {
sed -e 's|[^A-Za-z0-9_.,;:-]||g'
}

json='{'
while read var; do
var="$(echo "$var" | cut -f1 -d=)" # Strip off value past =
Expand All @@ -45,7 +41,8 @@ while read var; do
"$(eval "echo \"\${$var}\"" | json_esc)"
)"
mkdir -p "$(echo "$var" | clean)"
eval "echo \"\${$var}\" >\"$(echo "$var" | clean)/index.txt\""
name="$(echo "$var" | tr -d 'A-Za-z0-9_.,;:-')"
eval "echo \"\${$var}\" >\"${name}/index.txt\""
fi
done <<EOT
$(env)
Expand All @@ -57,5 +54,5 @@ echo "$json" >index.txt

unset json

exec /sbin/httpd -f -v -p $ENVHTTPD_PORT -c /etc/httpd.conf
exec httpd -f -v -p $ENVHTTPD_PORT -c /etc/httpd.conf

0 comments on commit 6850748

Please sign in to comment.