Skip to content
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

Allow to pass Caddyfile config via environment variable #248

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions 2.5/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ EXPOSE 2019

WORKDIR /srv

COPY entrypoint.sh /bin/entrypoint.sh

ENTRYPOINT [ "entrypoint.sh" ]

CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
13 changes: 13 additions & 0 deletions 2.5/alpine/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
set -e

# Check if Caddyfile config is passed via $CADDYFILE
if [[ "$CADDYFILE" ]]; then
echo 'Storing $CADDYFILE variable to ./Caddyfile'
printf "$CADDYFILE" > Caddyfile # echo doesn't preserve newlines
fi
Comment on lines +4 to +8
Copy link

@polarathene polarathene Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this run from the WORKDIR that is set to /srv? While the --config for CMD is set to /etc/caddy/Caddyfile? Is that intentional?


NOTE: the ENV check is using [[ ... ]], this is bash specific and not supported by plain sh AFAIK. In this case /bin/sh is symlinked to busybox; ash also symlinks to that - busybox is compatible with this syntax, although it wouldn't hurt to instead use #! /bin/ash though? :)

Have you tested that this is working correctly? Surely you're changing the CMD on your end if that is the case?


# Running passed command
if [[ "$1" ]]; then
exec "$@"
fi
Comment on lines +10 to +13
Copy link

@polarathene polarathene Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be true all the time (custom CMD passed in, or falling back to default CMD), unless the ENTRYPOINT is modified when extending theDockerfile (seems to apply to both "shell" and "exec" forms of ENTRYPOINT ignoring the CMD directive). Whereas only the "shell" form of ENTRYPOINT while in the same stage as the CMD directive results in CMD being ignored.

If the --entrypoint option is used (always "exec" form), then CMD from the Dockerfile is ignored (even if referencing the same entrypoint.sh file the original ENTRYPOINT would have used). Only when an explicit command is provided after the image name with docker run will the $@ have any values/args that can be processed.

Is the check for args (command) being provided serving any real purpose? (could just exec $@ without the conditional?)