From 98fc5598a82c9015fa8e4f84a8bc4d59af1f0b21 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 21 Jul 2024 21:28:52 +0000 Subject: [PATCH] build: Add an all-in-one container --- .github/workflows/docker.yml | 2 +- docker/Dockerfile | 34 +++++++++++++++++++ .../s6-overlay/s6-rc.d/init-db-migration/run | 6 ++++ .../s6-overlay/s6-rc.d/init-db-migration/type | 1 + .../s6-overlay/s6-rc.d/init-db-migration/up | 1 + .../svc-web/dependencies.d/init-db-migration | 0 .../root/etc/s6-overlay/s6-rc.d/svc-web/run | 5 +++ .../root/etc/s6-overlay/s6-rc.d/svc-web/type | 1 + .../dependencies.d/init-db-migration | 0 .../etc/s6-overlay/s6-rc.d/svc-workers/run | 5 +++ .../etc/s6-overlay/s6-rc.d/svc-workers/type | 1 + .../s6-rc.d/user/contents.d/init-db-migration | 0 .../s6-rc.d/user/contents.d/svc-web | 0 .../s6-rc.d/user/contents.d/svc-workers | 0 14 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 docker/root/etc/s6-overlay/s6-rc.d/init-db-migration/run create mode 100644 docker/root/etc/s6-overlay/s6-rc.d/init-db-migration/type create mode 100644 docker/root/etc/s6-overlay/s6-rc.d/init-db-migration/up create mode 100644 docker/root/etc/s6-overlay/s6-rc.d/svc-web/dependencies.d/init-db-migration create mode 100644 docker/root/etc/s6-overlay/s6-rc.d/svc-web/run create mode 100644 docker/root/etc/s6-overlay/s6-rc.d/svc-web/type create mode 100644 docker/root/etc/s6-overlay/s6-rc.d/svc-workers/dependencies.d/init-db-migration create mode 100644 docker/root/etc/s6-overlay/s6-rc.d/svc-workers/run create mode 100644 docker/root/etc/s6-overlay/s6-rc.d/svc-workers/type create mode 100644 docker/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-db-migration create mode 100644 docker/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-web create mode 100644 docker/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-workers diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 128532a2..52a14d95 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - package: [web, workers, cli] + package: [web, workers, cli, aio] runs-on: ubuntu-latest permissions: packages: write diff --git a/docker/Dockerfile b/docker/Dockerfile index 95d23f8d..592c4cfd 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -111,3 +111,37 @@ ARG SERVER_VERSION=nightly ENV SERVER_VERSION=${SERVER_VERSION} ENTRYPOINT ["node", "index.mjs"] + + +################# All-in-one ############## + +# Start from the web container as its the one with the most configuration +FROM web AS aio + +WORKDIR /app + +ARG S6_OVERLAY_VERSION=3.2.0.0 +ARG TARGETARCH + +# Install s6-overlay +ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp +RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz +RUN case ${TARGETARCH} in \ + "amd64") S6_ARCH=x86_64 ;; \ + "arm64") S6_ARCH=aarch64 ;; \ + esac \ + && echo https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_ARCH}.tar.xz -O /tmp/s6-overlay-${S6_ARCH}.tar.xz \ + && wget https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_ARCH}.tar.xz -O /tmp/s6-overlay-${S6_ARCH}.tar.xz \ + && tar -C / -Jxpf /tmp/s6-overlay-${S6_ARCH}.tar.xz \ + && rm -f /tmp/s6-overlay-${S6_ARCH}.tar.xz + +# Install runtime deps +RUN apk add --no-cache monolith + +# Copy workers code +COPY --from=workers_builder /prod /app/apps/workers +RUN corepack enable + +COPY --chmod=755 ./docker/root/etc/s6-overlay /etc/s6-overlay + +ENTRYPOINT ["/init"] diff --git a/docker/root/etc/s6-overlay/s6-rc.d/init-db-migration/run b/docker/root/etc/s6-overlay/s6-rc.d/init-db-migration/run new file mode 100644 index 00000000..f8cfe71b --- /dev/null +++ b/docker/root/etc/s6-overlay/s6-rc.d/init-db-migration/run @@ -0,0 +1,6 @@ +#!/command/with-contenv sh +# shellcheck shell=bash + +echo "Running db migration script"; +cd /db_migrations; +exec node index.js; diff --git a/docker/root/etc/s6-overlay/s6-rc.d/init-db-migration/type b/docker/root/etc/s6-overlay/s6-rc.d/init-db-migration/type new file mode 100644 index 00000000..bdd22a18 --- /dev/null +++ b/docker/root/etc/s6-overlay/s6-rc.d/init-db-migration/type @@ -0,0 +1 @@ +oneshot diff --git a/docker/root/etc/s6-overlay/s6-rc.d/init-db-migration/up b/docker/root/etc/s6-overlay/s6-rc.d/init-db-migration/up new file mode 100644 index 00000000..3a14babb --- /dev/null +++ b/docker/root/etc/s6-overlay/s6-rc.d/init-db-migration/up @@ -0,0 +1 @@ +/etc/s6-overlay/s6-rc.d/init-db-migration/run diff --git a/docker/root/etc/s6-overlay/s6-rc.d/svc-web/dependencies.d/init-db-migration b/docker/root/etc/s6-overlay/s6-rc.d/svc-web/dependencies.d/init-db-migration new file mode 100644 index 00000000..e69de29b diff --git a/docker/root/etc/s6-overlay/s6-rc.d/svc-web/run b/docker/root/etc/s6-overlay/s6-rc.d/svc-web/run new file mode 100644 index 00000000..83e9b9f1 --- /dev/null +++ b/docker/root/etc/s6-overlay/s6-rc.d/svc-web/run @@ -0,0 +1,5 @@ +#!/command/with-contenv sh +# shellcheck shell=bash + +cd /app/apps/web; +exec node server.js; diff --git a/docker/root/etc/s6-overlay/s6-rc.d/svc-web/type b/docker/root/etc/s6-overlay/s6-rc.d/svc-web/type new file mode 100644 index 00000000..5883cff0 --- /dev/null +++ b/docker/root/etc/s6-overlay/s6-rc.d/svc-web/type @@ -0,0 +1 @@ +longrun diff --git a/docker/root/etc/s6-overlay/s6-rc.d/svc-workers/dependencies.d/init-db-migration b/docker/root/etc/s6-overlay/s6-rc.d/svc-workers/dependencies.d/init-db-migration new file mode 100644 index 00000000..e69de29b diff --git a/docker/root/etc/s6-overlay/s6-rc.d/svc-workers/run b/docker/root/etc/s6-overlay/s6-rc.d/svc-workers/run new file mode 100644 index 00000000..249b8a52 --- /dev/null +++ b/docker/root/etc/s6-overlay/s6-rc.d/svc-workers/run @@ -0,0 +1,5 @@ +#!/command/with-contenv sh +# shellcheck shell=bash + +cd /app/apps/workers; +exec pnpm run start:prod; diff --git a/docker/root/etc/s6-overlay/s6-rc.d/svc-workers/type b/docker/root/etc/s6-overlay/s6-rc.d/svc-workers/type new file mode 100644 index 00000000..5883cff0 --- /dev/null +++ b/docker/root/etc/s6-overlay/s6-rc.d/svc-workers/type @@ -0,0 +1 @@ +longrun diff --git a/docker/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-db-migration b/docker/root/etc/s6-overlay/s6-rc.d/user/contents.d/init-db-migration new file mode 100644 index 00000000..e69de29b diff --git a/docker/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-web b/docker/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-web new file mode 100644 index 00000000..e69de29b diff --git a/docker/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-workers b/docker/root/etc/s6-overlay/s6-rc.d/user/contents.d/svc-workers new file mode 100644 index 00000000..e69de29b