Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
96775e7
add missing trailing newline
Jun 9, 2025
b95a826
Replace our `sed` with `envsubst`
Jun 9, 2025
59aa8e8
Fix variables to work with `envsubst`
Jun 9, 2025
01a191e
Handle `/admin` endpoint properly
Jun 9, 2025
dc20cc4
`-z` flag is GNU-specific 🤦‍♂️
Jun 9, 2025
eb57c92
Add timestamps to logging
Jun 9, 2025
5b2dbad
use `log_error` instead of returning failure
Jun 9, 2025
8e19922
Typo
Jun 9, 2025
f8fc3bf
Make port checking more robust
Jun 9, 2025
d27eb9e
Lol, another typo
Jun 9, 2025
438b1ab
Add `-u` to exit when we try and use an unset var
Jun 9, 2025
79d2468
Add `-o pipefail`
Jun 9, 2025
de8b38f
Harden variable name checking
Jun 9, 2025
e4e96fb
Make it more DRY
Jun 9, 2025
155d211
Swap `headscale-admin` to the `0.26` branch
Jun 9, 2025
161185d
Revert "Swap `headscale-admin` to the `0.26` branch"
EdGeraghty Jun 9, 2025
8d72065
Add missing `gettext` dependency for `envsubst`
EdGeraghty Jun 9, 2025
ae22179
Futureproof logging
EdGeraghty Jun 10, 2025
5dd1a65
Add a `WARN` logging level
EdGeraghty Jun 10, 2025
4f73c7f
There are no returns to catch
EdGeraghty Jun 10, 2025
0c5b1a4
Catch Caddy failing to start before continuing
EdGeraghty Jun 10, 2025
c5f0983
Fix up `litestream` logic
EdGeraghty Jun 10, 2025
d07d01b
Fix the `DEBUG` check so it doesn't fail out
EdGeraghty Jun 10, 2025
b383478
Improve error handling with `sed`
EdGeraghty Jun 10, 2025
692ac0c
Make sure our noise key has appropriate perms
EdGeraghty Jun 10, 2025
2f236a7
Fix up `create_headscale_config()`
EdGeraghty Jun 10, 2025
9bcc151
Swap `echo -n` to `printf`
EdGeraghty Jun 10, 2025
98d991b
`exec` our final command so it properly passes through signals
EdGeraghty Jun 10, 2025
65c6820
Make boolean logic explicit
EdGeraghty Jun 10, 2025
b8a8432
Exit properly when it errors out
EdGeraghty Jun 10, 2025
76db274
Add a log message if we're not using litestream
EdGeraghty Jun 10, 2025
4b68b6f
Remove redundant log message
EdGeraghty Jun 10, 2025
f48a757
Stop running as `root` inside the container
EdGeraghty Jun 10, 2025
4009671
Revert "Stop running as `root` inside the container"
EdGeraghty Jun 10, 2025
dd470ac
Separate the variable and its value to not mask
Jun 11, 2025
1debb6a
Case insensitivity
Jun 11, 2025
bac098b
Handle errors better
EdGeraghty Jun 14, 2025
4a53398
Add a default `EXPOSE` to our Dockerfile
EdGeraghty Jun 14, 2025
7b493d0
Normalise comments
EdGeraghty Jun 14, 2025
e78786a
Combine the final COPY and chmod to reduce layers
EdGeraghty Jun 14, 2025
feba07e
Use `envsubst` for Caddyfile too
EdGeraghty Jun 15, 2025
e094f14
DRY config file creation
EdGeraghty Jun 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 28 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
# ---
# Tool version args
# Bump these every time there is a new release. Don't forget the checksum!
###################
# BUILD PREP
###################
# Tool version arguments
# Bump these every time there is a new release.
# We're pulling these from github source, don't forget to bump the checksum!
ARG HEADSCALE_VERSION="0.26.1"
ARG HEADSCALE_SHA256="5012577e6fc5d4234aab7b4be0d6e271ea1a4ec38521a8aa472f80ea1fe81cba"

ARG LITESTREAM_VERSION="0.3.13"
ARG LITESTREAM_SHA256="eb75a3de5cab03875cdae9f5f539e6aedadd66607003d9b1e7a9077948818ba0"

# ---
# Container version args
# Bump these every time there is a new release. No checksum needed.
# No checksum needed for these tools, we pull from official images
ARG CADDY_VERSION="2.10.0"
ARG MAIN_IMAGE_ALPINE_VERSION="3.22.0"
ARG HEADSCALE_ADMIN_VERSION="dev"

# ---
# Tool download links
# github download links
# These should never need adjusting unless the URIs change
ARG HEADSCALE_DOWNLOAD_URL="https://github.com/juanfont/headscale/releases/download/v${HEADSCALE_VERSION}/headscale_${HEADSCALE_VERSION}_linux_amd64"
ARG LITESTREAM_DOWNLOAD_URL="https://github.com/benbjohnson/litestream/releases/download/v${LITESTREAM_VERSION}/litestream-v${LITESTREAM_VERSION}-linux-amd64.tar.gz"

###########
# LOGIC STARTS HERE
###########
###################
# BUILD PROCESS
###################

# ---
# Build caddy with Cloudflare DNS support
FROM caddy:${CADDY_VERSION}-builder AS caddy-builder
# Set SHELL flags for RUN commands to allow -e and pipefail
Expand All @@ -34,65 +33,61 @@ FROM caddy:${CADDY_VERSION}-builder AS caddy-builder
RUN xcaddy build \
--with github.com/caddy-dns/cloudflare

# ---
# Docker hates variables in COPY, apparently. Hello, workaround.
FROM goodieshq/headscale-admin:${HEADSCALE_ADMIN_VERSION} AS admin-gui

# ---
# Build our main image
FROM alpine:${MAIN_IMAGE_ALPINE_VERSION}
# Set SHELL flags for RUN commands to allow -e and pipefail
# Rationale: https://github.com/hadolint/hadolint/wiki/DL4006
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]

# ---
# import our "global" `ARG` values into this stage
# Import our "global" `ARG` values into this stage
ARG HEADSCALE_DOWNLOAD_URL
ARG HEADSCALE_SHA256
ARG LITESTREAM_DOWNLOAD_URL
ARG LITESTREAM_SHA256

# ---
# Upgrade system and install various dependencies
# - BusyBox's wget isn't reliable enough
# - I'm gonna need a better shell
# - We need GNU sed
# hadolint ignore=DL3018,SC2086
RUN BUILD_DEPS="wget"; \
RUNTIME_DEPS="bash sed"; \
RUNTIME_DEPS="bash sed gettext"; \
apk --no-cache upgrade; \
apk add --no-cache --virtual BuildTimeDeps ${BUILD_DEPS}; \
apk add --no-cache ${RUNTIME_DEPS}

# ---
# Copy caddy from the first stage
COPY --from=caddy-builder /usr/bin/caddy /usr/local/bin/caddy
# Caddy smoke test
RUN [ "$(command -v caddy)" = '/usr/local/bin/caddy' ]; \
caddy version

# ---
# Headscale
RUN { \
RUN set -ex; { \
wget --retry-connrefused \
--waitretry=1 \
--read-timeout=20 \
--timeout=15 \
-t 0 \
-q \
-O headscale \
${HEADSCALE_DOWNLOAD_URL} \
; \
${HEADSCALE_DOWNLOAD_URL} || { \
echo "Failed to download Headscale from ${HEADSCALE_DOWNLOAD_URL}"; \
exit 1; \
}; \
echo "${HEADSCALE_SHA256} *headscale" | sha256sum -c - >/dev/null 2>&1; \
chmod +x headscale; \
mv headscale /usr/local/bin/; \
}; \
# smoke test
# Headscale smoke test
[ "$(command -v headscale)" = '/usr/local/bin/headscale' ]; \
headscale version;

# Litestream
RUN { \
RUN set -ex; { \
wget --retry-connrefused \
--waitretry=1 \
--read-timeout=20 \
Expand All @@ -107,7 +102,7 @@ FROM alpine:${MAIN_IMAGE_ALPINE_VERSION}
mv litestream /usr/local/bin/; \
rm -f litestream.tar.gz; \
}; \
# smoke test
# Litestream smoke test
[ "$(command -v litestream)" = '/usr/local/bin/litestream' ]; \
litestream version;

Expand All @@ -117,13 +112,16 @@ FROM alpine:${MAIN_IMAGE_ALPINE_VERSION}
# Remove build-time dependencies
RUN apk del BuildTimeDeps

# ---
# copy configuration and templates
# Copy configuration templates
COPY ./templates/headscale.template.yaml /etc/headscale/config.yaml
COPY ./templates/litestream.template.yml /etc/litestream.yml
COPY ./templates/caddy.http.template.yaml /etc/caddy/Caddyfile-http
COPY ./templates/caddy.https.template.yaml /etc/caddy/Caddyfile-https
COPY ./scripts/container-entrypoint.sh /container-entrypoint.sh
RUN chmod +x /container-entrypoint.sh

# Copy and setup entrypoint script
COPY --chmod=755 ./scripts/container-entrypoint.sh /container-entrypoint.sh

# Default HTTPS port - override with $PUBLIC_LISTEN_PORT environment variable
EXPOSE 443

ENTRYPOINT ["/container-entrypoint.sh"]
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Details about configuration options.

## Contributing

Guidelines for contributing to the project.
Guidelines for contributing to the project.
Loading
Loading