Skip to content

Commit

Permalink
Use runit for all-in-one Docker image (#2203)
Browse files Browse the repository at this point in the history
Horrible hacks 😬, but good enough for all-in-one Docker image that
should not be used for anything serious.

Closes #1987.
  • Loading branch information
AlekSi committed Mar 15, 2023
1 parent 22f67ec commit aca0952
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**

# Go code
!build/version
!cmd
!internal
Expand All @@ -8,3 +9,6 @@

# so `go build` could set `vcs.revision`, etc.
!.git

# additional files for Docker images
!build/docker
9 changes: 3 additions & 6 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ tasks:
DOCKER_IMAGES: ferretdb-local
OUTPUT: type=docker

# TODO set annotations,
# see https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#adding-a-description-to-multi-arch-images
# TODO https://github.com/FerretDB/FerretDB/issues/2212
docker-all-in-one-push:
cmds:
- echo 'docker-all-in-one' > build/version/package.txt
Expand All @@ -466,8 +465,7 @@ tasks:
PLATFORM: linux/amd64,linux/arm64 # no mongosh for arm/v7
OUTPUT: type=image,push=true

# TODO set annotations,
# see https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#adding-a-description-to-multi-arch-images
# TODO https://github.com/FerretDB/FerretDB/issues/2212
docker-development-push:
cmds:
- echo 'docker' > build/version/package.txt
Expand All @@ -477,8 +475,7 @@ tasks:
PLATFORM: linux/amd64,linux/arm64,linux/arm/v7
OUTPUT: type=image,push=true

# TODO set annotations,
# see https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#adding-a-description-to-multi-arch-images
# TODO https://github.com/FerretDB/FerretDB/issues/2212
docker-production-push:
cmds:
- echo 'docker' > build/version/package.txt
Expand Down
19 changes: 17 additions & 2 deletions build/docker/all-in-one.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ ARG LABEL_COMMIT

COPY --from=all-in-one-build /src/bin/ferretdb /ferretdb

# all-in-one hacks start there

COPY --from=all-in-one-build /src/build/docker/all-in-one/ferretdb.sh /etc/service/ferretdb/run
COPY --from=all-in-one-build /src/build/docker/all-in-one/postgresql.sh /etc/service/postgresql/run
COPY --from=all-in-one-build /src/build/docker/all-in-one/entrypoint.sh /entrypoint.sh

RUN <<EOF
set -ex

Expand All @@ -95,17 +101,26 @@ apt update
apt install -y mongodb-mongosh
EOF

ENV FERRETDB_POSTGRESQL_URL=postgres://username:password@127.0.0.1:5432/ferretdb
ENV POSTGRES_USER=username
ENV POSTGRES_PASSWORD=password
ENV POSTGRES_DB=ferretdb

STOPSIGNAL SIGKILL

WORKDIR /
ENTRYPOINT [ "/ferretdb" ]
ENTRYPOINT [ "/entrypoint.sh" ]
EXPOSE 27017 27018 8080

# all-in-one hacks stop there

# don't forget to update documentation if you change defaults
ENV FERRETDB_LISTEN_ADDR=:27017
# ENV FERRETDB_LISTEN_TLS=:27018
ENV FERRETDB_DEBUG_ADDR=:8080
ENV FERRETDB_STATE_DIR=/state

# https://github.com/opencontainers/image-spec/blob/main/annotations.md
# TODO https://github.com/FerretDB/FerretDB/issues/2212
LABEL org.opencontainers.image.description="A truly Open Source MongoDB alternative"
LABEL org.opencontainers.image.licenses="Apache-2.0"
LABEL org.opencontainers.image.revision="${LABEL_COMMIT}"
Expand Down
7 changes: 7 additions & 0 deletions build/docker/all-in-one/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -ex

# Don't use `exec` so ctrl+c / SIGINT stops bash and not runsvdir (which ignores SIGINT).
# That's a hack, but good enough for all-in-one container.
/usr/bin/runsvdir /etc/service
5 changes: 5 additions & 0 deletions build/docker/all-in-one/ferretdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -ex

exec /ferretdb
5 changes: 5 additions & 0 deletions build/docker/all-in-one/postgresql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -ex

exec /usr/local/bin/docker-entrypoint.sh postgres
2 changes: 1 addition & 1 deletion build/docker/development.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ ENV FERRETDB_LISTEN_ADDR=:27017
ENV FERRETDB_DEBUG_ADDR=:8080
ENV FERRETDB_STATE_DIR=/state

# https://github.com/opencontainers/image-spec/blob/main/annotations.md
# TODO https://github.com/FerretDB/FerretDB/issues/2212
LABEL org.opencontainers.image.description="A truly Open Source MongoDB alternative"
LABEL org.opencontainers.image.licenses="Apache-2.0"
LABEL org.opencontainers.image.revision="${LABEL_COMMIT}"
Expand Down
2 changes: 1 addition & 1 deletion build/docker/production.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ENV FERRETDB_LISTEN_ADDR=:27017
ENV FERRETDB_DEBUG_ADDR=:8080
ENV FERRETDB_STATE_DIR=/state

# https://github.com/opencontainers/image-spec/blob/main/annotations.md
# TODO https://github.com/FerretDB/FerretDB/issues/2212
LABEL org.opencontainers.image.description="A truly Open Source MongoDB alternative"
LABEL org.opencontainers.image.licenses="Apache-2.0"
LABEL org.opencontainers.image.revision="${LABEL_COMMIT}"
Expand Down

0 comments on commit aca0952

Please sign in to comment.