Skip to content

Commit

Permalink
feat: add sh entrypoint to allow MEMOS_DSN_FILE to load variable from…
Browse files Browse the repository at this point in the history
… secret (#4236)

Add sh entrypoint to allow MEMOS_DSN_FILE to load variable from secret
  • Loading branch information
hadleyrich authored Dec 30, 2024
1 parent 7817ad0 commit 82b5c8a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ RUN apk add --no-cache tzdata
ENV TZ="UTC"

COPY --from=backend /backend-build/memos /usr/local/memos/
COPY entrypoint.sh /usr/local/memos/

EXPOSE 5230

Expand All @@ -37,4 +38,4 @@ VOLUME /var/opt/memos
ENV MEMOS_MODE="prod"
ENV MEMOS_PORT="5230"

ENTRYPOINT ["./memos"]
ENTRYPOINT ["./entrypoint.sh", "./memos"]
27 changes: 27 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env sh

file_env() {
var="$1"
fileVar="${var}_FILE"

val_var="$(printenv "$var")"
val_fileVar="$(printenv "$fileVar")"

if [ -n "$val_var" ] && [ -n "$val_fileVar" ]; then
echo "error: both $var and $fileVar are set (but are exclusive)" >&2
exit 1
fi

if [ -n "$val_var" ]; then
val="$val_var"
elif [ -n "$val_fileVar" ]; then
val="$(cat "$val_fileVar")"
fi

export "$var"="$val"
unset "$fileVar"
}

file_env "MEMOS_DSN"

exec "$@"

0 comments on commit 82b5c8a

Please sign in to comment.