-
Notifications
You must be signed in to change notification settings - Fork 310
Add custom entrypoint to generate the configuration #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ccec3f7
1d0b3e8
f40ba7f
356fbd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ LABEL maintainer "Abiola Ibrahim <[email protected]>" | |
|
|
||
| LABEL caddy_version="0.10.10" | ||
|
|
||
| RUN apk add --no-cache openssh-client git | ||
| RUN apk add --no-cache openssh-client git bash | ||
|
|
||
| # install caddy | ||
| COPY --from=builder /install/caddy /usr/bin/caddy | ||
|
|
@@ -26,12 +26,12 @@ RUN /usr/bin/caddy -version | |
| RUN /usr/bin/caddy -plugins | ||
|
|
||
| EXPOSE 80 443 2015 | ||
| VOLUME /root/.caddy /srv | ||
| VOLUME /root/.caddy /srv /etc/caddy | ||
| WORKDIR /srv | ||
|
|
||
| COPY Caddyfile /etc/Caddyfile | ||
| COPY index.html /srv/index.html | ||
| COPY docker-entrypoint.sh / | ||
| COPY docker-entrypoint.d /docker-entrypoint.d/ | ||
|
|
||
| ENTRYPOINT ["/usr/bin/caddy"] | ||
| CMD ["--conf", "/etc/Caddyfile", "--log", "stdout"] | ||
|
|
||
| ENTRYPOINT ["/bin/bash", "/docker-entrypoint.sh"] | ||
| CMD ["/usr/bin/caddy", "--conf", "/etc/caddy/Caddyfile", "--log", "stdout"] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The readme.md has a few mentions where the main config is located in the container. But this change moves it. How would someone use the default config with this pull request? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ## This file was autogenerated by /entrypoint.sh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| offset=0 | ||
| while true; do | ||
| BASEVAR="CADDY_ENTRY${offset}" | ||
| HOSTNAME="${BASEVAR}_HOSTNAME" | ||
| if [ -z ${!HOSTNAME} ]; then | ||
| break | ||
| fi | ||
| echo "${!HOSTNAME} {" | ||
| for each in $(find /docker-entrypoint.d/40-listen-points/ | sort -n); do | ||
| case $each in | ||
| *.part) | ||
| source $each | ||
| ;; | ||
| esac | ||
| done | ||
| echo "}" | ||
| offset=$((offset + 1)) | ||
| done |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| echo " log stdout" | ||
| echo " errors stderr" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| TLS_VAR=$"{BASEVAR}_TLS_MODE" | ||
| TLS="${!TLS_VAR}" | ||
| if [ -z "${TLS}" ]; then | ||
| TLS="self_signed" | ||
| fi | ||
|
|
||
| echo " tls $TLS" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| FILTER_MAXBUFFER_SIZE="${BASEVAR}_FILTER_MAXBUFFER_SIZE" | ||
| if [ ! -z "${!FILTER_MAXBUFFER_SIZE}" ]; then | ||
| echo " filter max_buffer_size ${!FILTER_MAXBUFFER_SIZE}" | ||
| fi | ||
|
|
||
| inneroffset=0 | ||
| while true; do | ||
| FILTER_PATH="${BASEVAR}_FILTER${inneroffset}_PATH" | ||
| FILTER_CONTENT_TYPE="${BASEVAR}_FILTER${inneroffset}_CONTENT_TYPE" | ||
| FILTER_SEARCH_PATTERN="${BASEVAR}_FILTER${inneroffset}_SEARCH_PATTERN" | ||
| FILTER_REPLACEMENT="${BASEVAR}_FILTER${inneroffset}_REPLACEMENT" | ||
| if [ -z "${!FILTER_PATH}" ] || [ -z "${!FILTER_CONTENT_TYPE}" ] || [ -z "${!FILTER_SEARCH_PATTERN}" ] || [ -z "${!FILTER_REPLACEMENT}" ]; then | ||
| break | ||
| fi | ||
| echo " filter rule {" | ||
| echo " path ${!FILTER_PATH}" | ||
| echo " content_type ${!FILTER_CONTENT_TYPE}" | ||
| echo " search_pattern ${!FILTER_SEARCH_PATTERN}" | ||
| echo " replacement ${!FILTER_REPLACEMENT}" | ||
| echo " }" | ||
| inneroffset=$((inneroffset + 1)) | ||
| done |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| inneroffset=0 | ||
| while true; do | ||
| USERNAME="${BASEVAR}_AUTH${inneroffset}_USERNAME" | ||
| HTTP_PATH="${BASEVAR}_AUTH${inneroffset}_PATH" | ||
| PASSWORD="${BASEVAR}_AUTH${inneroffset}_PASSWORD" | ||
| if [ -z "${!USERNAME}" ] || [ -z "${!HTTP_PATH}" ] || [ -z "${!PASSWORD}" ]; then | ||
| break | ||
| fi | ||
| echo " basicauth ${!HTTP_PATH} ${!USERNAME} ${!PASSWORD}" | ||
| inneroffset=$((inneroffset + 1)) | ||
| done |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| inneroffset=0 | ||
| while true; do | ||
| PROXY_BASEVAR="${BASEVAR}_PROXY${inneroffset}" | ||
| PROXY_PATH="${PROXY_BASEVAR}_PATH" | ||
| PROXY_DEST="${PROXY_BASEVAR}_DEST" | ||
| if [ -z "${!PROXY_PATH}" ] || [ -z "${!PROXY_DEST}" ]; then | ||
| break | ||
| fi | ||
| echo " proxy ${!PROXY_PATH} ${!PROXY_DEST} {" | ||
| WITHOUT="${PROXY_BASEVAR}_WITHOUT" | ||
| if [ ! -z "${!WITHOUT}" ]; then | ||
| echo " without ${!WITHOUT}" | ||
| fi | ||
| WEBSOCKET="${PROXY_BASEVAR}_WEBSOCKET" | ||
| if [ ! -z "${!WEBSOCKET}" ]; then | ||
| echo " websocket" | ||
| fi | ||
| TRANSPARENT="${PROXY_BASEVAR}_TRANSPARENT" | ||
| if [ ! -z "${!TRANSPARENT}" ]; then | ||
| echo " transparent" | ||
| fi | ||
| echo " }" | ||
| inneroffset=$((inneroffset + 1)) | ||
| done | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| inneroffset=0 | ||
| while true; do | ||
| CUSTOM="${BASEVAR}_CUSTOM${inneroffset}" | ||
| if [ -z "${!CUSTOM}" ]; then | ||
| break | ||
| fi | ||
| echo " ${!CUSTOM}" | ||
| inneroffset=$((inneroffset + 1)) | ||
| done |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/bin/bash | ||
|
|
||
| rm -f /etc/caddy/Caddyfile | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this affect people using one of the recommended run commands (https://github.com/abiosoft/caddy-docker#using-local-caddyfile-and-sites-root)? Disabling an docker entrypoint command is somewhat awkward to do with the docker command. Perhaps an check could be added to see if the any of the env vars are present before rewriting the config. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a backward compatibility mode, enabled by default. |
||
| case $CADDY_GENERATE_CONFIG in | ||
| yes|true) | ||
| for each in $(find /docker-entrypoint.d/ | sort -n) ; do | ||
| case $each in | ||
| *.sh) | ||
| source "$each" >> /etc/caddy/Caddyfile | ||
| ;; | ||
| *.conf) | ||
| cat "$each" >> /etc/caddy/Caddyfile | ||
| ;; | ||
| esac | ||
| done | ||
| ;; | ||
| *) | ||
| echo "Using Provided Caddyfile instead of generating it" | ||
| cp /etc/Caddyfile /etc/caddy/Caddyfile | ||
| ;; | ||
| esac | ||
|
|
||
| exec $@ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the config is being auto generated, having it also stored in an docker volume seems somewhat counter-intuitive. Does this provide an advantage for larger installations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, a volume means read-write data, and the image itself should be read-only.