Initial commit.
commit
9686393777
|
@ -0,0 +1,8 @@
|
||||||
|
###
|
||||||
|
|
||||||
|
.git*
|
||||||
|
|
||||||
|
.dockerignore
|
||||||
|
Dockerfile
|
||||||
|
|
||||||
|
.editorconfig
|
|
@ -0,0 +1,12 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
|
@ -0,0 +1,51 @@
|
||||||
|
FROM golang:1.8-alpine
|
||||||
|
|
||||||
|
WORKDIR /data
|
||||||
|
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
ca-certificates &&\
|
||||||
|
update-ca-certificates
|
||||||
|
|
||||||
|
# Install build dependencies (permanently since we are going to keep the
|
||||||
|
# ability to install additional plugins which will require a complete Caddy
|
||||||
|
# rebuild)
|
||||||
|
RUN apk add --no-cache --virtual build-deps \
|
||||||
|
bash \
|
||||||
|
gcc \
|
||||||
|
git \
|
||||||
|
xz
|
||||||
|
|
||||||
|
# Preconfiguration
|
||||||
|
RUN \
|
||||||
|
git config --global http.followRedirects true &&\
|
||||||
|
mkdir -vp "${GOPATH}"
|
||||||
|
|
||||||
|
# Add the scripts
|
||||||
|
COPY files/ /usr/local/
|
||||||
|
# Fix permissions and line endings in case we use `docker build` from Windows
|
||||||
|
# because remember, Docker client can run on Windows despite the host running
|
||||||
|
# on Linux!
|
||||||
|
RUN \
|
||||||
|
chmod -v +x /usr/local/bin/* &&\
|
||||||
|
sed -i 's,\r,,g' /usr/local/bin/*
|
||||||
|
|
||||||
|
# Install Caddy itself
|
||||||
|
ARG CADDY_VERSION=master
|
||||||
|
RUN \
|
||||||
|
echo "*** Fetching Caddy..." &&\
|
||||||
|
git clone --recursive "https://github.com/mholt/caddy.git" \
|
||||||
|
"$GOPATH/src/github.com/mholt/caddy" &&\
|
||||||
|
(cd "$GOPATH/src/github.com/mholt/caddy" &&\
|
||||||
|
git checkout "$CADDY_VERSION") &&\
|
||||||
|
docker-caddy-build &&\
|
||||||
|
docker-caddy-pack-source
|
||||||
|
|
||||||
|
# I would have run "setcap cap_net_bind_service=+ep /usr/local/bin/caddy" as well but it will not work in Docker
|
||||||
|
# thanks to inconsistencies with aufs and kernel settings on Ubuntu.
|
||||||
|
#
|
||||||
|
# My recommendation is to let Caddy bind to a non-root port instead and use the Docker userland proxy if possible,
|
||||||
|
# so for example binding Caddy to port 2200 and telling Docker to forward port 80 to port 2200 in the container
|
||||||
|
# should be just fine.
|
||||||
|
|
||||||
|
ENTRYPOINT ["caddy"]
|
||||||
|
CMD ["-agree","-conf=/data/Caddyfile"]
|
|
@ -0,0 +1,25 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
export PATH="$GOPATH/bin:$PATH"
|
||||||
|
|
||||||
|
docker-caddy-unpack-source
|
||||||
|
|
||||||
|
cd "$GOPATH/src/github.com/mholt/caddy/caddy"
|
||||||
|
|
||||||
|
# Make sure all dependencies are available
|
||||||
|
go get -d -v .
|
||||||
|
|
||||||
|
docker-caddy-remove-git-metadata
|
||||||
|
|
||||||
|
./build.bash "/usr/local/bin/caddy"
|
||||||
|
|
||||||
|
# Remove some reproducible and for runtime unnecessary build output files
|
||||||
|
# to save on the image size later on
|
||||||
|
rm -rfv \
|
||||||
|
"/tmp"/* \
|
||||||
|
"/var/tmp"/* \
|
||||||
|
"exec" \
|
||||||
|
"lib" \
|
||||||
|
"pkg"
|
|
@ -0,0 +1,60 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
pluginspath="$GOPATH/src/github.com/mholt/caddy/caddy/caddymain/install_plugins.go"
|
||||||
|
|
||||||
|
plugin() {
|
||||||
|
echo "*** Fetching plugin $1..."
|
||||||
|
|
||||||
|
# Generate Go import path from given Git URL
|
||||||
|
importpath="${3:-$(echo "$1" | sed -e 's,^.\+://,,' -e 's,\.git$,,')}"
|
||||||
|
git clone "$1" "$GOPATH/src/$importpath"
|
||||||
|
|
||||||
|
(
|
||||||
|
cd "$GOPATH/src/$importpath"
|
||||||
|
|
||||||
|
# Checkout wanted version if any given
|
||||||
|
if [ ! -z "$2" ]
|
||||||
|
then
|
||||||
|
git checkout "$2"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "*** Preparing plugin $1..."
|
||||||
|
|
||||||
|
# Fetch dependencies
|
||||||
|
go get -d -v .
|
||||||
|
|
||||||
|
# Run generate across all files (if any extra tools are necessary you will
|
||||||
|
# need to install them before running this script)
|
||||||
|
go generate -v .
|
||||||
|
)
|
||||||
|
|
||||||
|
docker-caddy-remove-git-metadata
|
||||||
|
|
||||||
|
# Add the newly available plugin to an extra Go source file that will be
|
||||||
|
# compiled into the Caddy binary along with the rest of the source tree.
|
||||||
|
if [ ! -e "$pluginspath" ]
|
||||||
|
then
|
||||||
|
echo "package caddymain" > "$pluginspath"
|
||||||
|
fi
|
||||||
|
echo "*** Adding ${importpath} to $pluginspath..."
|
||||||
|
echo "import _ \"${importpath}\"" >> "$pluginspath"
|
||||||
|
}
|
||||||
|
|
||||||
|
docker-caddy-unpack-source
|
||||||
|
|
||||||
|
# Parse arguments and prepare each given plugin.
|
||||||
|
# Supported syntaxes (where reference can be a commit hash or branch name etc.):
|
||||||
|
# - http://server.com/user/repository.git
|
||||||
|
# - https://server.com/user/repository.git
|
||||||
|
# - git://server.com/user/repository.git
|
||||||
|
# - http://server.com/user/repository.git#reference
|
||||||
|
# - https://server.com/user/repository.git#reference
|
||||||
|
# - git://server.com/user/repository.git#reference
|
||||||
|
for plugin in "$@"; do
|
||||||
|
(IFS='#'; plugin $plugin);
|
||||||
|
done
|
||||||
|
|
||||||
|
# Rebuild Caddy with the given plugins now installed
|
||||||
|
exec docker-caddy-build
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -n "${DISABLE_SOURCE_COMPRESSION}" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "${GOPATH}/src/github.com/mholt/caddy" ]; then
|
||||||
|
echo "Tried to pack source when the source directory has been deleted." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
(
|
||||||
|
cd "${GOPATH}"
|
||||||
|
mkdir -p "/usr/src"
|
||||||
|
tar cJ -f "/usr/src/go.tar.xz" .
|
||||||
|
)
|
||||||
|
|
||||||
|
exec rm -r "${GOPATH}"
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -n "${DISABLE_GIT_METADATA_REMOVAL}" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove Git metadata
|
||||||
|
exec find "${GOPATH}" \
|
||||||
|
-name .git -type d \
|
||||||
|
! -path '*/src/github.com/mholt/caddy/*' \
|
||||||
|
-exec rm -r {} +
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -n "${DISABLE_SOURCE_COMPRESSION}" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "${GOPATH}/src/github.com/mholt/caddy" ]; then
|
||||||
|
mkdir -p "${GOPATH}"
|
||||||
|
tar xJ -C "${GOPATH}" -f "/usr/src/go.tar.xz"
|
||||||
|
rm "/usr/src/go.tar.xz"
|
||||||
|
fi
|
Loading…
Reference in New Issue