This repository has been archived on 2021-08-14. You can view files and clone it, but cannot push or open issues/pull-requests.
bever-dam/Dockerfile

68 lines
1.6 KiB
Docker
Raw Normal View History

2021-07-19 18:43:55 +02:00
# Global build argument
ARG THTTPD_VER=2.29
2021-07-19 20:46:16 +02:00
ARG DI_VER=1.2.5
2021-07-19 18:43:55 +02:00
FROM alpine:3 AS builder
2021-07-08 22:38:03 +02:00
2021-07-19 20:46:16 +02:00
# =====BUILD BINARIES=====
2021-07-19 18:43:55 +02:00
WORKDIR /usr/src
ARG THTTPD_VER
2021-07-19 20:46:16 +02:00
ARG DI_VER
2021-07-19 18:43:55 +02:00
# Install build dependencies
# bash: required for dumb-init's Makefile
2021-07-21 15:56:33 +02:00
# clang, build-base: compilation (I just like clang)
# curl: downloading the tarballs
# hugo: generating the static files
RUN apk add --update --no-cache \
bash \
2021-07-21 15:56:33 +02:00
build-base \
clang \
curl \
hugo \
musl-dev
# Build thttpd
RUN curl -sSL "https://www.acme.com/software/thttpd/thttpd-$THTTPD_VER.tar.gz" | \
2021-07-19 18:43:55 +02:00
tar xzf - && \
cd "thttpd-$THTTPD_VER" && \
2021-07-21 15:56:33 +02:00
CC=clang ./configure && \
make CCOPT="-O3 -s -static" -j$(nproc)
2021-07-19 18:43:55 +02:00
2021-07-19 20:46:16 +02:00
# Build dumb-init
# dumb-init's Makefile already specifies static build flags, so we don't have to specify them
2021-07-19 20:46:16 +02:00
RUN curl -sSL "https://github.com/Yelp/dumb-init/archive/refs/tags/v$DI_VER.tar.gz" | \
tar xzf - && \
cd "dumb-init-$DI_VER" && \
2021-07-21 15:56:33 +02:00
CC=clang make build
2021-07-19 18:43:55 +02:00
2021-07-19 20:46:16 +02:00
# =====BUILD BLOG=====
2021-07-19 18:43:55 +02:00
WORKDIR /usr/src/app
2021-07-08 22:38:03 +02:00
# Copy site files for building
COPY . ./
# Generate the site
2021-07-21 15:56:33 +02:00
# The find command fixes file permissions, because thttpd thinks executables should be CGI files
2021-07-19 21:27:47 +02:00
RUN hugo --minify && \
find public -type f -exec chmod 644 {} \;
2021-07-08 22:38:03 +02:00
2021-07-19 18:43:55 +02:00
# ====CREATE RELEASE IMAGE====
2021-07-19 20:46:16 +02:00
FROM scratch
2021-07-19 18:43:55 +02:00
ARG THTTPD_VER
2021-07-19 20:46:16 +02:00
ARG DI_VER
2021-07-19 18:43:55 +02:00
# Copy over binary & static files
2021-07-19 20:46:16 +02:00
COPY --from=builder /usr/src/thttpd-$THTTPD_VER/thttpd /bin/thttpd
COPY --from=builder /usr/src/dumb-init-$DI_VER/dumb-init /bin/dumb-init
COPY --from=builder /usr/src/app/public /static
2021-07-19 18:43:55 +02:00
2021-07-19 19:00:07 +02:00
# A static file server doesn't need root
2021-07-19 20:05:35 +02:00
USER 82:82
2021-07-08 22:38:03 +02:00
2021-07-19 20:46:16 +02:00
ENTRYPOINT [ "/bin/dumb-init", "--" ]
CMD [ "/bin/thttpd", "-D", "-d", "/static", "-p", "8080" ]