Skip to content

Commit

Permalink
Sync + caddy front
Browse files Browse the repository at this point in the history
Signed-off-by: dubo-dubon-duponey <dubodubonduponey+github@pm.me>
  • Loading branch information
dubo-dubon-duponey committed Aug 29, 2020
1 parent 4cbfb06 commit 14c4f5a
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 23 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/CI.yml
Expand Up @@ -2,10 +2,6 @@ name: CI

on: [push, pull_request]

env:
DEBOOTSTRAP_SUITE: buster
DEBOOTSTRAP_DATE: 2020-08-01

jobs:
test:
# The type of runner that the job will run on
Expand All @@ -15,6 +11,8 @@ jobs:
steps:
- name: Checks-out repository
uses: actions/checkout@v2
with:
submodules: true

- name: Enable cache
uses: actions/cache@v2.1.1
Expand All @@ -31,7 +29,7 @@ jobs:
run: |
mkdir -p "$GITHUB_WORKSPACE/cache/apt"
chmod a+rwx "$GITHUB_WORKSPACE/cache/apt"
docker run -d --name aptcache --read-only --cap-drop=ALL --volume $GITHUB_WORKSPACE/cache/apt:/data --expose 3142 dubodubonduponey/aptutil
docker run -d --name aptcache --read-only --cap-drop=ALL --volume $GITHUB_WORKSPACE/cache/apt:/data --expose 3142 dubodubonduponey/aptutil:buster-2020-08-01
- name: Install multi-arch buildx environment
run: |
Expand Down
8 changes: 2 additions & 6 deletions .travis.yml
Expand Up @@ -27,7 +27,7 @@ before_install:
- docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64

install:
- curl -sL -o hadolint "https://github.com/hadolint/hadolint/releases/download/v1.16.0/hadolint-$(uname -s)-$(uname -m)"
- curl -sL -o hadolint "https://github.com/hadolint/hadolint/releases/download/v1.18.0/hadolint-$(uname -s)-$(uname -m)"
&& chmod 700 ./hadolint

script:
Expand All @@ -36,8 +36,4 @@ script:
matrix:
include:
- os: linux
dist: bionic
env:
- DEBOOTSTRAP_SUITE=buster
- DEBOOTSTRAP_DATE=2020-08-01
- TEST_DOES_NOT_BUILD=
dist: focal
27 changes: 25 additions & 2 deletions Dockerfile
Expand Up @@ -56,6 +56,23 @@ RUN env GOOS=linux GOARCH="$(printf "%s" "$TARGETPLATFORM" | sed -E 's
COPY --from=builder-healthcheck /dist/boot/bin /dist/boot/bin
RUN chmod 555 /dist/boot/bin/*

#######################
# Caddy
#######################
# hadolint ignore=DL3006
FROM --platform=$BUILDPLATFORM $BUILDER_BASE AS builder-caddy

# This is 2.1.1+ with golang 1.15 support (08/21/2020)
ARG GIT_REPO=github.com/caddyserver/caddy
ARG GIT_VERSION=0279a57ac465b2920abf71d86203d9feac2015b5

WORKDIR $GOPATH/src/$GIT_REPO
RUN git clone https://$GIT_REPO .
RUN git checkout $GIT_VERSION

# hadolint ignore=DL4006
RUN env GOOS=linux GOARCH="$(printf "%s" "$TARGETPLATFORM" | sed -E 's/^[^/]+\/([^/]+).*/\1/')" go build -v -ldflags "-s -w" \
-o /dist/boot/bin/caddy ./cmd/caddy

#######################
# Builder assembly
Expand All @@ -65,6 +82,7 @@ FROM $BUILDER_BASE

COPY --from=builder-healthcheck /dist/boot/bin /dist/boot/bin
COPY --from=builder-cacher /dist/boot/bin /dist/boot/bin
COPY --from=builder-caddy /dist/boot/bin /dist/boot/bin

RUN chmod 555 /dist/boot/bin/*; \
epoch="$(date --date "$BUILD_CREATED" +%s)"; \
Expand All @@ -78,12 +96,17 @@ FROM $RUNTIME_BASE

COPY --from=builder --chown=$BUILD_UID:root /dist .

EXPOSE 3142/tcp
EXPOSE 8080/tcp

VOLUME /data

ENV USERNAME=dubo-dubon-duponey
ENV PASSWORD=base64_bcrypt_encoded_use_caddy_hash_password_to_generate
ENV REALM="My precious"
ENV LOG_LEVEL=info
ENV PORT=8080

# System constants, unlikely to ever require modifications in normal use
ENV HEALTHCHECK_URL="http://127.0.0.1:3142/archive?healthcheck=internal"
ENV PORT=3142

HEALTHCHECK --interval=30s --timeout=30s --start-period=10s --retries=1 CMD http-health || exit 1
2 changes: 1 addition & 1 deletion build.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -o errexit -o errtrace -o functrace -o nounset -o pipefail

export DEBOOTSTRAP_DATE="${DEBOOTSTRAP_DATE:-2020-08-01}"
export DEBOOTSTRAP_DATE="${DEBOOTSTRAP_DATE:-2020-08-15}"

# For good info on qemu / multi-arch and buildx:
# https://medium.com/@artur.klauser/building-multi-architecture-docker-images-with-buildx-27d80f7e2408
Expand Down
16 changes: 9 additions & 7 deletions context/runtime/boot/entrypoint.sh
Expand Up @@ -7,11 +7,13 @@ set -o errexit -o errtrace -o functrace -o nounset -o pipefail
exit 1
}

LOG_LEVEL="${LOG_LEVEL:-info}"
LOG_FORMAT="${LOG_FORMAT:-plain}"
apt-cacher -f /config/apt-cacher.toml -logfile /dev/stdout -logformat "${APT_LOG_FORMAT:-plain}" -loglevel "${APT_LOG_LEVEL:-error}" &

# Run once configured
#args=(apt-mirror -f /config/apt-mirror.toml -logfile /dev/stdout -logformat "$LOG_FORMAT" -loglevel "$LOG_LEVEL")
args=(apt-cacher -f /config/apt-cacher.toml -logfile /dev/stdout -logformat "$LOG_FORMAT" -loglevel "$LOG_LEVEL")

exec "${args[@]}" "$@"
case "${1:-}" in
"hash-password")
exec caddy "$@"
;;
*)
exec caddy run -config /config/caddy/main.conf --adapter caddyfile
;;
esac
4 changes: 2 additions & 2 deletions context/runtime/config/apt-cacher.toml
@@ -1,6 +1,6 @@
# listen_address is the listening address of go-apt-cacher.
# Default is ":3142".
listen_address = ":3142"
listen_address = "127.0.0.1:3142"

# Interval to check updates for Release/InRelease files.
# Default: 600 seconds
Expand Down Expand Up @@ -32,7 +32,7 @@ max_conns = 10
# Details at https://godoc.org/github.com/cybozu-go/well#LogConfig
[log]
#filename = "/var/log/go-apt-cacher.log"
level = "info"
level = "error"
format = "plain"

# mapping declares which prefix maps to a Debian repository URL.
Expand Down
10 changes: 10 additions & 0 deletions context/runtime/config/caddy/main.conf
@@ -0,0 +1,10 @@
{
# {$debug}
# default_sni {$SNI}
admin off
# local_certs
auto_https off
}

# Import all sites config
import sites.d/*.conf
44 changes: 44 additions & 0 deletions context/runtime/config/caddy/sites.d/aptutil.conf
@@ -0,0 +1,44 @@
http://:{$PORT} {
@proxy {
header Proxy-Authorization Basic*
}

@noproxy {
not {
header Proxy-Authorization Basic*
}
}

request_header @proxy Authorization {http.request.header.Proxy-Authorization}
request_header @proxy -Proxy-Authorization

log {
output stdout
format json
level {$LOG_LEVEL}
}

header {
X-Xss-Protection "1; mode=block"
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
Referrer-Policy "strict-origin-when-cross-origin"
}

reverse_proxy @proxy http://127.0.0.1:{$PORT}

basicauth @noproxy bcrypt "{$REALM}" {
{$USERNAME} {$PASSWORD}
}

reverse_proxy @noproxy http://127.0.0.1:3142 {
# active health checking
# XXX health does not seem to work /archive?healthcheck=internal
health_path /
health_port 3142
health_interval 60s
health_timeout 5s
health_status 200
health_status 404
}
}
9 changes: 9 additions & 0 deletions docker-bake.override.hcl
Expand Up @@ -7,4 +7,13 @@ target "default" {
tags = [
"dubodubonduponey/aptutil",
]
/* platforms = [
"linux/amd64",
"linux/arm64",
"linux/arm/v7",
"linux/arm/v6",
"linux/386",
"linux/s390x",
"linux/ppc64el",
]*/
}

0 comments on commit 14c4f5a

Please sign in to comment.