Skip to content

Commit

Permalink
feat(supabase-all-in-one): add docker image for test supabase instance
Browse files Browse the repository at this point in the history
- 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 <michal.bajer@fujitsu.com>
  • Loading branch information
outSH authored and petermetz committed Mar 20, 2023
1 parent 703d56a commit 89dbcef
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tools/docker/supabase-all-in-one/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
36 changes: 36 additions & 0 deletions tools/docker/supabase-all-in-one/README.md
Original file line number Diff line number Diff line change
@@ -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
```
15 changes: 15 additions & 0 deletions tools/docker/supabase-all-in-one/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tools/docker/supabase-all-in-one/script-start-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo "[process] Start docker environment for Supabase DB"
docker-compose build && docker-compose up -d
21 changes: 21 additions & 0 deletions tools/docker/supabase-all-in-one/src/freeze-images.sh
Original file line number Diff line number Diff line change
@@ -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."
11 changes: 11 additions & 0 deletions tools/docker/supabase-all-in-one/src/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions tools/docker/supabase-all-in-one/src/run-supabase.sh
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions tools/docker/supabase-all-in-one/src/supervisord.conf
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 89dbcef

Please sign in to comment.