From d5f9b33f66c99103c0687f3adb08b1396d6dd1b7 Mon Sep 17 00:00:00 2001 From: Jeremy Lin Date: Sun, 5 Jul 2020 15:26:20 -0700 Subject: [PATCH] Add startup script to support init operations This is useful for making local customizations upon container start. To use this feature, mount a script into the container as `/etc/bitwarden_rs.sh` and/or a directory of scripts as `/etc/bitwarden_rs.d`. In the latter case, only files with an `.sh` extension are sourced, so files with other extensions (e.g., data/config files) can reside in the same dir. Note that the init scripts are run each time the container starts (not just the first time), so these scripts should be idempotent. --- docker/Dockerfile.j2 | 3 ++- docker/aarch64/mysql/Dockerfile | 3 ++- docker/aarch64/sqlite/Dockerfile | 3 ++- docker/amd64/mysql/Dockerfile | 3 ++- docker/amd64/mysql/Dockerfile.alpine | 3 ++- docker/amd64/postgresql/Dockerfile | 3 ++- docker/amd64/postgresql/Dockerfile.alpine | 3 ++- docker/amd64/sqlite/Dockerfile | 3 ++- docker/amd64/sqlite/Dockerfile.alpine | 3 ++- docker/armv6/mysql/Dockerfile | 3 ++- docker/armv6/sqlite/Dockerfile | 3 ++- docker/armv7/mysql/Dockerfile | 3 ++- docker/armv7/sqlite/Dockerfile | 3 ++- docker/start.sh | 15 +++++++++++++++ 14 files changed, 41 insertions(+), 13 deletions(-) create mode 100755 docker/start.sh diff --git a/docker/Dockerfile.j2 b/docker/Dockerfile.j2 index e67218c9..691f5fb3 100644 --- a/docker/Dockerfile.j2 +++ b/docker/Dockerfile.j2 @@ -288,9 +288,10 @@ COPY --from=build app/target/release/bitwarden_rs . {% endif %} COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/aarch64/mysql/Dockerfile b/docker/aarch64/mysql/Dockerfile index f8eac46f..8cd92867 100644 --- a/docker/aarch64/mysql/Dockerfile +++ b/docker/aarch64/mysql/Dockerfile @@ -125,9 +125,10 @@ COPY --from=vault /web-vault ./web-vault COPY --from=build /app/target/aarch64-unknown-linux-gnu/release/bitwarden_rs . COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/aarch64/sqlite/Dockerfile b/docker/aarch64/sqlite/Dockerfile index 8b5dbcba..449df5ec 100644 --- a/docker/aarch64/sqlite/Dockerfile +++ b/docker/aarch64/sqlite/Dockerfile @@ -119,9 +119,10 @@ COPY --from=vault /web-vault ./web-vault COPY --from=build /app/target/aarch64-unknown-linux-gnu/release/bitwarden_rs . COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/amd64/mysql/Dockerfile b/docker/amd64/mysql/Dockerfile index dbf6ffee..88e289fa 100644 --- a/docker/amd64/mysql/Dockerfile +++ b/docker/amd64/mysql/Dockerfile @@ -93,9 +93,10 @@ COPY --from=vault /web-vault ./web-vault COPY --from=build app/target/release/bitwarden_rs . COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/amd64/mysql/Dockerfile.alpine b/docker/amd64/mysql/Dockerfile.alpine index d7991090..f0733c37 100644 --- a/docker/amd64/mysql/Dockerfile.alpine +++ b/docker/amd64/mysql/Dockerfile.alpine @@ -96,9 +96,10 @@ COPY --from=vault /web-vault ./web-vault COPY --from=build /app/target/x86_64-unknown-linux-musl/release/bitwarden_rs . COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/amd64/postgresql/Dockerfile b/docker/amd64/postgresql/Dockerfile index 5e45a90b..3a51b048 100644 --- a/docker/amd64/postgresql/Dockerfile +++ b/docker/amd64/postgresql/Dockerfile @@ -93,9 +93,10 @@ COPY --from=vault /web-vault ./web-vault COPY --from=build app/target/release/bitwarden_rs . COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/amd64/postgresql/Dockerfile.alpine b/docker/amd64/postgresql/Dockerfile.alpine index cdc2d029..984a8a7b 100644 --- a/docker/amd64/postgresql/Dockerfile.alpine +++ b/docker/amd64/postgresql/Dockerfile.alpine @@ -96,9 +96,10 @@ COPY --from=vault /web-vault ./web-vault COPY --from=build /app/target/x86_64-unknown-linux-musl/release/bitwarden_rs . COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/amd64/sqlite/Dockerfile b/docker/amd64/sqlite/Dockerfile index 8bd2f7fc..fe9cecb1 100644 --- a/docker/amd64/sqlite/Dockerfile +++ b/docker/amd64/sqlite/Dockerfile @@ -87,9 +87,10 @@ COPY --from=vault /web-vault ./web-vault COPY --from=build app/target/release/bitwarden_rs . COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/amd64/sqlite/Dockerfile.alpine b/docker/amd64/sqlite/Dockerfile.alpine index 7b0d03bf..2dce0cf7 100644 --- a/docker/amd64/sqlite/Dockerfile.alpine +++ b/docker/amd64/sqlite/Dockerfile.alpine @@ -90,9 +90,10 @@ COPY --from=vault /web-vault ./web-vault COPY --from=build /app/target/x86_64-unknown-linux-musl/release/bitwarden_rs . COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/armv6/mysql/Dockerfile b/docker/armv6/mysql/Dockerfile index 7599cd5c..fad45f33 100644 --- a/docker/armv6/mysql/Dockerfile +++ b/docker/armv6/mysql/Dockerfile @@ -125,9 +125,10 @@ COPY --from=vault /web-vault ./web-vault COPY --from=build /app/target/arm-unknown-linux-gnueabi/release/bitwarden_rs . COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/armv6/sqlite/Dockerfile b/docker/armv6/sqlite/Dockerfile index 935e2d6e..1bc37aff 100644 --- a/docker/armv6/sqlite/Dockerfile +++ b/docker/armv6/sqlite/Dockerfile @@ -119,9 +119,10 @@ COPY --from=vault /web-vault ./web-vault COPY --from=build /app/target/arm-unknown-linux-gnueabi/release/bitwarden_rs . COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/armv7/mysql/Dockerfile b/docker/armv7/mysql/Dockerfile index fd242aaa..89da407a 100644 --- a/docker/armv7/mysql/Dockerfile +++ b/docker/armv7/mysql/Dockerfile @@ -124,9 +124,10 @@ COPY --from=vault /web-vault ./web-vault COPY --from=build /app/target/armv7-unknown-linux-gnueabihf/release/bitwarden_rs . COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/armv7/sqlite/Dockerfile b/docker/armv7/sqlite/Dockerfile index 08d46cf7..cf20a39e 100644 --- a/docker/armv7/sqlite/Dockerfile +++ b/docker/armv7/sqlite/Dockerfile @@ -118,9 +118,10 @@ COPY --from=vault /web-vault ./web-vault COPY --from=build /app/target/armv7-unknown-linux-gnueabihf/release/bitwarden_rs . COPY docker/healthcheck.sh /healthcheck.sh +COPY docker/start.sh /start.sh HEALTHCHECK --interval=60s --timeout=10s CMD ["/healthcheck.sh"] # Configures the startup! WORKDIR / -CMD ["/bitwarden_rs"] +CMD ["/start.sh"] diff --git a/docker/start.sh b/docker/start.sh new file mode 100755 index 00000000..39f591c2 --- /dev/null +++ b/docker/start.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +if [ -r /etc/bitwarden_rs.sh ]; then + . /etc/bitwarden_rs.sh +fi + +if [ -d /etc/bitwarden_rs.d ]; then + for f in /etc/bitwarden_rs.d/*.sh; do + if [ -r $f ]; then + . $f + fi + done +fi + +exec /bitwarden_rs "${@}"