Skip to content

Commit

Permalink
Allow optional secrets.json during Docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
afwolfe committed Aug 21, 2024
1 parent 61a1ac1 commit 3ce3626
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## Docker ##
Dockerfile-x
secrets.json


## FoundryVTT ##
cookiejar.json
Expand Down
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ ARG FOUNDRY_USERNAME
ARG FOUNDRY_VERSION
ENV ARCHIVE="foundryvtt-${FOUNDRY_VERSION}.zip"

# Need jq for reading secret during build
RUN apk --update --no-cache add \
jq

WORKDIR /root
COPY --from=compile-typescript-stage \
/root/package.json \
Expand All @@ -37,7 +41,12 @@ COPY --from=compile-typescript-stage \
./
# .placeholder file to mitigate https://github.com/moby/moby/issues/37965
RUN mkdir dist && touch dist/.placeholder
RUN \
RUN --mount=type=secret,id=config_json,target="/run/secrets/config.json",required=false \
secret_file="/run/secrets/config.json" && \
secret_password=$(jq --exit-status --raw-output .foundry_password ${secret_file} || echo) && \
secret_username=$(jq --exit-status --raw-output .foundry_username ${secret_file} || echo) && \
FOUNDRY_PASSWORD=${secret_password:-${FOUNDRY_PASSWORD:-}} && \
FOUNDRY_USERNAME=${secret_username:-${FOUNDRY_USERNAME:-}} && \
if [ -n "${FOUNDRY_USERNAME}" ] && [ -n "${FOUNDRY_PASSWORD}" ]; then \
npm install && \
./authenticate.js "${FOUNDRY_USERNAME}" "${FOUNDRY_PASSWORD}" cookiejar.json && \
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ resulting in a faster startup. It also moves the user authentication to
build-time instead of start-time. **Note**: Credentials are only used to fetch
a distribution, and are not stored in the resulting image.

### Credentials ###

Build the image with credentials:

```console
Expand All @@ -383,6 +385,20 @@ docker build \
https://github.com/felddy/foundryvtt-docker.git#develop
```

### Secrets file ###

Follow the [Using secrets](#using-secrets) section to create a secrets.json file and then add the secret to the build with the `--secret` argument. The Dockerfile expects the file to use `id=config_json`.

```console
docker build \
--build-arg VERSION=12.331.0 \
--secret id=config_json,src=secrets.json \
--tag felddy/foundryvtt:12.331.0 \
https://github.com/felddy/foundryvtt-docker.git#develop
```

### Temporary URL ###

Or build the image using a temporary URL:

```console
Expand Down

0 comments on commit 3ce3626

Please sign in to comment.