Added Caddy v1.0.5 Docker Image

Signed-off-by: Teddysun <i@teddysun.com>
This commit is contained in:
Teddysun 2020-09-20 14:18:27 +09:00
parent 03fcacd7b3
commit 13d2a17df8
No known key found for this signature in database
GPG Key ID: 09BD4C080AD6C46D
7 changed files with 517 additions and 0 deletions

25
docker/caddy/Caddyfile Normal file
View File

@ -0,0 +1,25 @@
# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace the line below with your
# domain name.
:80
# Set this path to your site's directory.
root * /usr/share/caddy
# Enable the static file server.
file_server
# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080
# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000
# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

39
docker/caddy/Dockerfile Normal file
View File

@ -0,0 +1,39 @@
# Dockerfile for caddy v1.0.5 based alpine
# Copyright (C) 2020 Teddysun <i@teddysun.com>
# Reference URL:
# https://github.com/caddyserver/caddy
# https://github.com/caddyserver/forwardproxy
FROM alpine:3.12
LABEL maintainer="Teddysun <i@teddysun.com>"
WORKDIR /root
COPY caddy.sh /root/caddy.sh
RUN set -ex \
&& mkdir -p /config/caddy /data/caddy /etc/caddy /usr/share/caddy \
&& apk add --no-cache tzdata ca-certificates mailcap \
&& chmod +x /root/caddy.sh \
&& /root/caddy.sh \
&& rm -fv /root/caddy.sh
# set up nsswitch.conf for Go's "netgo" implementation
# see: https://github.com/docker-library/golang/blob/1eb096131592bcbc90aa3b97471811c798a93573/1.14/alpine3.12/Dockerfile#L9
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf
COPY Caddyfile /etc/caddy/Caddyfile
COPY index.html /usr/share/caddy/index.html
# See https://caddyserver.com/docs/conventions#file-locations for details
ENV XDG_CONFIG_HOME /config
ENV XDG_DATA_HOME /data
VOLUME /etc/caddy
VOLUME /config
VOLUME /data
EXPOSE 80
EXPOSE 443
EXPOSE 2015
ENV TZ=Asia/Shanghai
CMD [ "/usr/bin/caddy", "--config", "/etc/caddy/Caddyfile" ]

View File

@ -0,0 +1,40 @@
# Dockerfile for caddy v1.0.5 based alpine
# Copyright (C) 2020 Teddysun <i@teddysun.com>
# Reference URL:
# https://github.com/caddyserver/caddy
# https://github.com/caddyserver/forwardproxy
FROM --platform=${TARGETPLATFORM} alpine:3.12
LABEL maintainer="Teddysun <i@teddysun.com>"
ARG TARGETPLATFORM
WORKDIR /root
COPY caddy.sh /root/caddy.sh
RUN set -ex \
&& mkdir -p /config/caddy /data/caddy /etc/caddy /usr/share/caddy \
&& apk add --no-cache tzdata ca-certificates mailcap \
&& chmod +x /root/caddy.sh \
&& /root/caddy.sh "${TARGETPLATFORM}" \
&& rm -fv /root/caddy.sh
# set up nsswitch.conf for Go's "netgo" implementation
# see: https://github.com/docker-library/golang/blob/1eb096131592bcbc90aa3b97471811c798a93573/1.14/alpine3.12/Dockerfile#L9
RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf
COPY Caddyfile /etc/caddy/Caddyfile
COPY index.html /usr/share/caddy/index.html
# See https://caddyserver.com/docs/conventions#file-locations for details
ENV XDG_CONFIG_HOME /config
ENV XDG_DATA_HOME /data
VOLUME /etc/caddy
VOLUME /config
VOLUME /data
EXPOSE 80
EXPOSE 443
EXPOSE 2015
ENV TZ=Asia/Shanghai
CMD [ "/usr/bin/caddy", "--config", "/etc/caddy/Caddyfile" ]

44
docker/caddy/README.md Normal file
View File

@ -0,0 +1,44 @@
## Caddy Docker Image by Teddysun
[Caddy][1] is a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go.
Docker images are built for quick deployment in various computing cloud providers.
For more information on docker and containerization technologies, refer to [official document][2].
## Prepare the host
If you need to install docker by yourself, follow the [official installation guide][3].
## Pull the image
```bash
$ docker pull teddysun/caddy
```
This pulls the version **v1.0.5** of Caddy.
It can be found at [Docker Hub][4].
## Start a container
You **must create a configuration file** `/etc/caddy/Caddyfile` in host at first:
```
$ mkdir -p /etc/caddy
```
A sample `Caddyfile` please visit [here](https://github.com/caddyserver/dist/blob/master/config/Caddyfile)
Caddy requires write access to two locations: a [data directory](https://caddyserver.com/docs/conventions#data-directory), and a [configuration directory](https://caddyserver.com/docs/conventions#configuration-directory).
There is an example to override the default `Caddyfile`, you can mount a new one at `/etc/caddy/Caddyfile` like below:
```bash
$ docker run -d -p 80:80 --name caddy --restart=always -v /etc/caddy:/etc/caddy teddysun/caddy
```
[1]: https://caddyserver.com/
[2]: https://docs.docker.com/
[3]: https://docs.docker.com/install/
[4]: https://hub.docker.com/r/teddysun/caddy/

View File

@ -0,0 +1,46 @@
#!/bin/sh
#
# This is a Shell script for build multi-architectures caddy binary file with forwardproxy plugin
#
# Supported architectures: amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, s390x
#
# Copyright (C) 2020 Teddysun <i@teddysun.com>
#
# Reference URL:
# https://github.com/caddyserver/caddy
# https://github.com/caddyserver/forwardproxy
cur_dir="$(pwd)"
COMMANDS=( git go )
for CMD in "${COMMANDS[@]}"; do
if [ ! "$(command -v "${CMD}")" ]; then
echo "${CMD} is not installed, please install it and try again" && exit 1
fi
done
cd ${cur_dir}
echo "git clone https://github.com/caddyserver/forwardproxy.git"
git clone https://github.com/caddyserver/forwardproxy.git
cd forwardproxy/cmd/caddy || exit 2
go get -d -v
LDFLAGS="-s -w"
ARCHS=( 386 amd64 arm arm64 ppc64le s390x )
ARMS=( 6 7 )
for ARCH in ${ARCHS[@]}; do
if [ "${ARCH}" = "arm" ]; then
for V in ${ARMS[@]}; do
echo "Building caddy_linux_${ARCH}${V}"
env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GOARM=${V} go build -v -ldflags "${LDFLAGS}" -o ${cur_dir}/caddy_linux_${ARCH}${V}
done
else
echo "Building caddy_linux_${ARCH}"
env CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -v -ldflags "${LDFLAGS}" -o ${cur_dir}/caddy_linux_${ARCH}
fi
done
chmod +x ${cur_dir}/caddy_*
# clean up
cd ${cur_dir} && rm -fr forwardproxy

54
docker/caddy/caddy.sh Normal file
View File

@ -0,0 +1,54 @@
#!/bin/sh
#
# This is a Shell script for caddy based alpine with Docker image
#
# Copyright (C) 2019 - 2020 Teddysun <i@teddysun.com>
#
# Reference URL:
# https://github.com/caddyserver/caddy
# https://github.com/caddyserver/forwardproxy
PLATFORM=$1
if [ -z "$PLATFORM" ]; then
ARCH="amd64"
else
case "$PLATFORM" in
linux/386)
ARCH="386"
;;
linux/amd64)
ARCH="amd64"
;;
linux/arm/v6)
ARCH="arm6"
;;
linux/arm/v7)
ARCH="arm7"
;;
linux/arm64|linux/arm64/v8)
ARCH="arm64"
;;
linux/ppc64le)
ARCH="ppc64le"
;;
linux/s390x)
ARCH="s390x"
;;
*)
ARCH=""
;;
esac
fi
[ -z "${ARCH}" ] && echo "Error: Not supported OS Architecture" && exit 1
# Download binary file
CADDY_FILE="caddy_linux_${ARCH}"
echo "Downloading binary file: ${CADDY_FILE}"
wget -O /usr/bin/caddy https://dl.lamp.sh/files/${CADDY_FILE} > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error: Failed to download binary file: ${CADDY_FILE}" && exit 1
fi
echo "Download binary file: ${CADDY_FILE} completed"
chmod +x /usr/bin/caddy
/usr/bin/caddy version

269
docker/caddy/index.html Normal file

File diff suppressed because one or more lines are too long