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

feat: Add gomplate to the docker image #1893

Merged
merged 10 commits into from
Feb 10, 2021
22 changes: 20 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ COPY . .

RUN make release-binary

FROM alpine:3.13.1 AS gomplate

ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
ARG GOMPLATE_VERSION=v3.9.0
nabokihms marked this conversation as resolved.
Show resolved Hide resolved

RUN wget -O /usr/local/bin/gomplate \
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use the slim version instead for a smaller binary: https://github.com/hairyhenderson/gomplate/releases

Copy link
Member

Choose a reason for hiding this comment

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

Actually, does this work with every arm version? arm64, armv7? (The first one is GOARCH, the latter is variant AFAIK)

Copy link
Member Author

@nabokihms nabokihms Feb 10, 2021

Choose a reason for hiding this comment

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

Yes, it does! I have tested with linux/arm/v7 and linux/arm64.

Copy link
Member

Choose a reason for hiding this comment

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

Awesome, thanks!

"https://github.com/hairyhenderson/gomplate/releases/download/${GOMPLATE_VERSION}/gomplate_${TARGETOS:-linux}-${TARGETARCH:-amd64}${TARGETVARIANT}" \
&& chmod +x /usr/local/bin/gomplate

nabokihms marked this conversation as resolved.
Show resolved Hide resolved

FROM alpine:3.13.1

# Dex connectors, such as GitHub and Google logins require root certificates.
Expand All @@ -32,11 +44,16 @@ RUN apk add --no-cache --update ca-certificates openssl
RUN mkdir -p /var/dex
RUN chown -R 1001:1001 /var/dex

RUN mkdir -p /etc/dex
COPY config.docker.yaml /etc/dex/config.docker.yaml
nabokihms marked this conversation as resolved.
Show resolved Hide resolved
RUN chown -R 1001:1001 /etc/dex

# Copy module files for CVE scanning / dependency analysis.
COPY --from=builder /usr/local/src/dex/go.mod /usr/local/src/dex/go.sum /usr/local/src/dex/
COPY --from=builder /usr/local/src/dex/api/v2/go.mod /usr/local/src/dex/api/v2/go.sum /usr/local/src/dex/api/v2/

COPY --from=builder /go/bin/dex /usr/local/bin/dex
COPY --from=gomplate /usr/local/bin/gomplate /usr/local/bin/gomplate

USER 1001:1001

Expand All @@ -46,6 +63,7 @@ COPY --from=builder /usr/local/src/dex/web /web

USER 1001:1001

ENTRYPOINT ["dex"]
COPY docker-entrypoint.sh /
nabokihms marked this conversation as resolved.
Show resolved Hide resolved

CMD ["version"]
ENTRYPOINT ["/docker-entrypoint.sh"]
nabokihms marked this conversation as resolved.
Show resolved Hide resolved
CMD ["serve", "/etc/dex/config.docker.yaml"]
nabokihms marked this conversation as resolved.
Show resolved Hide resolved
46 changes: 46 additions & 0 deletions config.docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
issuer: {{ getenv "DEX_ISSUER" "http://127.0.0.1:5556/dex" }}

Copy link

@heidemn heidemn Jan 30, 2021

Choose a reason for hiding this comment

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

Maybe add a comment that this config file is only an example / for development purposes?

And maybe mention in another comment that for escaping "unfriendly" input like passwords, this function could be used for escaping, to get valid YAML? https://docs.gomplate.ca/functions/strings/#strings-squote
(Sorry haven't tested it yet, but I'm assuming that such escaping is not done automatically by Gomplate)

Copy link
Member

Choose a reason for hiding this comment

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

I think that makes sense. Let's add a comment

storage:
type: sqlite3
config:
file: {{ getenv "DEX_STORAGE_SQLITE3_CONFIG_FILE" "/var/dex/dex.db" }}

web:
{{- if getenv "DEX_WEB_HTTPS" "" }}
https: {{ .Env.DEX_WEB_HTTPS }}
tlsKey: {{ getenv "DEX_WEB_TLS_KEY" | required "$DEX_WEB_TLS_KEY in case of web.https is enabled" }}
tlsCert: {{ getenv "DEX_WEB_TLS_CERT" | required "$DEX_WEB_TLS_CERT in case of web.https is enabled" }}
{{- end }}
http: {{ getenv "DEX_WEB_HTTP" "0.0.0.0:5556" }}

{{- if getenv "DEX_TELEMETRY_HTTP" }}
telemetry:
http: {{ .Env.DEX_TELEMETRY_HTTP }}
{{- end }}

expiry:
deviceRequests: {{ getenv "DEX_EXPIRY_DEVICE_REQUESTS" "5m" }}
signingKeys: {{ getenv "DEX_EXPIRY_SIGNING_KEYS" "6h" }}
idTokens: {{ getenv "DEX_EXPIRY_ID_TOKENS" "24h" }}
authRequests: {{ getenv "DEX_EXPIRY_AUTH_REQUESTS" "24h" }}

logger:
level: {{ getenv "DEX_LOG_LEVEL" "info" }}
format: {{ getenv "DEX_LOG_FORMAT" "text" }}

oauth2:
responseTypes: {{ getenv "DEX_OAUTH2_RESPONSE_TYPES" "[code]" }}
skipApprovalScreen: {{ getenv "DEX_OAUTH2_SKIP_APPROVAL_SCREEN" "false" }}
alwaysShowLoginScreen: {{ getenv "DEX_OAUTH2_ALWAYS_SHOW_LOGIN_SCREEN" "false" }}
{{- if getenv "DEX_OAUTH2_PASSWORD_CONNECTOR" "" }}
passwordConnector: {{ .Env.DEX_OAUTH2_PASSWORD_CONNECTOR }}
{{- end }}

enablePasswordDB: {{ getenv "DEX_ENABLE_PASSWORD_DB" "true" }}

connectors:
{{- if getenv "DEX_CONNECTORS_ENABLE_MOCK" }}
- type: mockCallback
id: mock
name: Example
{{- end }}
31 changes: 31 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh -e

### Usage: /docker-entrypoint.sh <command> <args>
### * If command equals to "serve", config file for serving will be preprocessed using gomplate and saved to tmp dir.
### Example: docker-entrypoint.sh serve config.yaml = dex serve /tmp/dex-config.yaml-ABCDEFG
### * If command is not in the list of known dex commands, it will be executed bypassing entrypoint.
### Example: docker-entrypoint.sh echo "Hello!" = echo "Hello!"

command=$1

case "$command" in
serve)
for file_candidate in $@ ; do
if test -f "$file_candidate"; then
nabokihms marked this conversation as resolved.
Show resolved Hide resolved
tmpfile=$(mktemp /tmp/dex.config.yaml-XXXXXX)
gomplate -f "$file_candidate" -o "$tmpfile"

args="${args} ${tmpfile}"
else
args="${args} ${file_candidate}"
fi
done
exec dex $args
;;
--help|-h|version)
exec dex $@
;;
*)
exec $@
Copy link

@heidemn heidemn Jan 29, 2021

Choose a reason for hiding this comment

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

I like this option, allowing it to bypass the templating by adding dex in front of the arguments. 👍
Maybe mention it in the "Usage" comment, so it's more obvious.

Copy link

@heidemn heidemn Jan 31, 2021

Choose a reason for hiding this comment

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

You should also adapt the section "Does this PR introduce a user-facing change?":

  • By default, Gomplate is now applied on the config file for docker run quay.io/dexidp/dex serve ....
  • To opt out, one can either adapt the command: docker run quay.io/dexidp/dex dex serve ...
    or change the entrypoint: docker run --entrypoint dex quay.io/dexidp/dex serve ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you are right! Whole description has to be rewritten.

;;
esac