From 89dbcef0ef6cbb33b831c0edf9ab65317ec15ff1 Mon Sep 17 00:00:00 2001 From: Michal Bajer Date: Mon, 9 Jan 2023 15:26:24 +0000 Subject: [PATCH] feat(supabase-all-in-one): add docker image for test supabase instance - Add a new docker image `supabase-all-in-one` that will setup supabase instance for tests. - Supabase is used as a backend for Cactus GUI. Closes: #2253 Signed-off-by: Michal Bajer --- tools/docker/supabase-all-in-one/Dockerfile | 40 +++++++++++++++++++ tools/docker/supabase-all-in-one/README.md | 36 +++++++++++++++++ .../supabase-all-in-one/docker-compose.yml | 15 +++++++ .../script-start-docker.sh | 2 + .../supabase-all-in-one/src/freeze-images.sh | 21 ++++++++++ .../supabase-all-in-one/src/healthcheck.sh | 11 +++++ .../supabase-all-in-one/src/run-supabase.sh | 18 +++++++++ .../supabase-all-in-one/src/supervisord.conf | 24 +++++++++++ 8 files changed, 167 insertions(+) create mode 100644 tools/docker/supabase-all-in-one/Dockerfile create mode 100644 tools/docker/supabase-all-in-one/README.md create mode 100644 tools/docker/supabase-all-in-one/docker-compose.yml create mode 100755 tools/docker/supabase-all-in-one/script-start-docker.sh create mode 100755 tools/docker/supabase-all-in-one/src/freeze-images.sh create mode 100755 tools/docker/supabase-all-in-one/src/healthcheck.sh create mode 100755 tools/docker/supabase-all-in-one/src/run-supabase.sh create mode 100644 tools/docker/supabase-all-in-one/src/supervisord.conf diff --git a/tools/docker/supabase-all-in-one/Dockerfile b/tools/docker/supabase-all-in-one/Dockerfile new file mode 100644 index 0000000000..1e9b24984d --- /dev/null +++ b/tools/docker/supabase-all-in-one/Dockerfile @@ -0,0 +1,40 @@ +FROM docker:20.10.21-dind + +ARG SUPABSE_TAG="v0.22.10" + +ENV FREEZE_TMP_DIR="/opt/docker-freeze" + +# Install package dependencies +RUN apk update \ + && apk add --no-cache \ + git \ + curl \ + jq \ + bash \ + supervisor + +WORKDIR /home +RUN git clone --depth 1 --branch "${SUPABSE_TAG}" "https://github.com/supabase/supabase" + +WORKDIR /home/supabase/docker +RUN cp .env.example .env + +# Freeze docker images +COPY ./src/freeze-images.sh /usr/bin/freeze-images.sh +RUN bash /usr/bin/freeze-images.sh + +# Setup healtcheck +COPY ./src/healthcheck.sh /bin/healthcheck +RUN chmod +x /bin/healthcheck +HEALTHCHECK --interval=5s --timeout=5s --start-period=45s --retries=90 CMD /bin/healthcheck + +# Expose ledger ports +EXPOSE 3000 +EXPOSE 8000 +EXPOSE 5432 + +# Setup supervisor entrypoint +COPY ./src/run-supabase.sh /usr/bin/run-supabase.sh +COPY ./src/supervisord.conf /etc/supervisord.conf +ENTRYPOINT ["/usr/bin/supervisord"] +CMD ["--configuration", "/etc/supervisord.conf", "--nodaemon"] diff --git a/tools/docker/supabase-all-in-one/README.md b/tools/docker/supabase-all-in-one/README.md new file mode 100644 index 0000000000..946788cea2 --- /dev/null +++ b/tools/docker/supabase-all-in-one/README.md @@ -0,0 +1,36 @@ +# supabase-all-in-one + +An all in one supabase image that can be used as Cactus GUI backend. +- This docker image is for `testing` and `development` only. +- **Do NOT use in production!** + +## Usage +- Password: `your-super-secret-and-long-postgres-password` + +### Docker Compose +``` bash +./script-start-docker.sh +``` + +or manually: + +``` bash +docker-compose build && docker-compose up -d +``` + +### Docker +> Excute from the cactus root or adjust the paths accordingly. + +``` bash +# Build +DOCKER_BUILDKIT=1 docker build ./tools/docker/supabase-all-in-one -t cactus-supabase-all-in-one + +# Run +docker run --name supabase_all_in_one_gui \ + --detach \ + --privileged \ + -p 3000:3000 \ + -p 8000:8000 \ + -p 5432:5432 \ + cactus-supabase-all-in-one +``` diff --git a/tools/docker/supabase-all-in-one/docker-compose.yml b/tools/docker/supabase-all-in-one/docker-compose.yml new file mode 100644 index 0000000000..4e2607e8fd --- /dev/null +++ b/tools/docker/supabase-all-in-one/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3.5" + +services: + supabase-all-in-one-db: + container_name: cactus-supabase-all-in-one-db + image: cactus-supabase-all-in-one + privileged: true + build: + context: ./ + dockerfile: Dockerfile + ports: + - "3000:3000" # Supabase Studio + - "8000:8000" # Supabase API + - "5432:5432" # Postgres + network_mode: host diff --git a/tools/docker/supabase-all-in-one/script-start-docker.sh b/tools/docker/supabase-all-in-one/script-start-docker.sh new file mode 100755 index 0000000000..febbc8643f --- /dev/null +++ b/tools/docker/supabase-all-in-one/script-start-docker.sh @@ -0,0 +1,2 @@ +echo "[process] Start docker environment for Supabase DB" +docker-compose build && docker-compose up -d diff --git a/tools/docker/supabase-all-in-one/src/freeze-images.sh b/tools/docker/supabase-all-in-one/src/freeze-images.sh new file mode 100755 index 0000000000..144607ecde --- /dev/null +++ b/tools/docker/supabase-all-in-one/src/freeze-images.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e + +FREEZE_SCRIPT_NAME="download-frozen-image-v2.sh" +FREEZE_SCRIPT_PATH="/usr/bin/${FREEZE_SCRIPT_NAME}" + +echo "Download freeze script..." +curl -sSL https://raw.githubusercontent.com/moby/moby/dedf8528a51c6db40686ed6676e9486d1ed5f9c0/contrib/download-frozen-image-v2.sh > "${FREEZE_SCRIPT_PATH}" +chmod +x "${FREEZE_SCRIPT_PATH}" + +# Get list of images from docker-compose +for img in `grep 'image:' docker-compose.yml | tr -d ' ' | cut -d':' -f2,3` +do + img_path="${FREEZE_TMP_DIR}/${img/\//-}" + echo "Freeze image '${img}' in '${img_path}" + mkdir -p "${img_path}" + bash "${FREEZE_SCRIPT_PATH}" "${img_path}" "${img}" +done + +echo "Image freeze done." \ No newline at end of file diff --git a/tools/docker/supabase-all-in-one/src/healthcheck.sh b/tools/docker/supabase-all-in-one/src/healthcheck.sh new file mode 100755 index 0000000000..ca290aa0f5 --- /dev/null +++ b/tools/docker/supabase-all-in-one/src/healthcheck.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +# Check if supabase schemas has been added +schema_count=$(docker exec supabase-db psql -U postgres -c '\du' | grep supabase | wc -l) +if [ $schema_count -lt 3 ]; then exit 2; fi + +# TODO - can be improved by checking endpoints (if current one causes troubles) + +exit 0 diff --git a/tools/docker/supabase-all-in-one/src/run-supabase.sh b/tools/docker/supabase-all-in-one/src/run-supabase.sh new file mode 100755 index 0000000000..6f94a5c7bf --- /dev/null +++ b/tools/docker/supabase-all-in-one/src/run-supabase.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +while ! docker ps &> /dev/null +do + echo "Wait for dockerd to start..." + sleep 3 +done + +# Get list of images from docker-compose +for img in `ls ${FREEZE_TMP_DIR}` +do + echo "Load frozen image '${img}'" + tar -cC "${FREEZE_TMP_DIR}/${img}" . | docker load +done + +echo "Frozen images loaded" + +docker compose -f /home/supabase/docker/docker-compose.yml up \ No newline at end of file diff --git a/tools/docker/supabase-all-in-one/src/supervisord.conf b/tools/docker/supabase-all-in-one/src/supervisord.conf new file mode 100644 index 0000000000..7ae73c05c6 --- /dev/null +++ b/tools/docker/supabase-all-in-one/src/supervisord.conf @@ -0,0 +1,24 @@ +[supervisord] +logfile = /var/log/supervisord.log +logfile_maxbytes = 50MB +logfile_backups=10 +loglevel = info + +[program:dockerd] +command=dockerd-entrypoint.sh +autostart=true +autorestart=true +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +priority=1 + +[program:supabase] +command=/usr/bin/run-supabase.sh +autostart=true +autorestart=unexpected +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0