Skip to content

Commit 89dbcef

Browse files
outSHpetermetz
authored andcommitted
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 <[email protected]>
1 parent 703d56a commit 89dbcef

File tree

8 files changed

+167
-0
lines changed

8 files changed

+167
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM docker:20.10.21-dind
2+
3+
ARG SUPABSE_TAG="v0.22.10"
4+
5+
ENV FREEZE_TMP_DIR="/opt/docker-freeze"
6+
7+
# Install package dependencies
8+
RUN apk update \
9+
&& apk add --no-cache \
10+
git \
11+
curl \
12+
jq \
13+
bash \
14+
supervisor
15+
16+
WORKDIR /home
17+
RUN git clone --depth 1 --branch "${SUPABSE_TAG}" "https://github.com/supabase/supabase"
18+
19+
WORKDIR /home/supabase/docker
20+
RUN cp .env.example .env
21+
22+
# Freeze docker images
23+
COPY ./src/freeze-images.sh /usr/bin/freeze-images.sh
24+
RUN bash /usr/bin/freeze-images.sh
25+
26+
# Setup healtcheck
27+
COPY ./src/healthcheck.sh /bin/healthcheck
28+
RUN chmod +x /bin/healthcheck
29+
HEALTHCHECK --interval=5s --timeout=5s --start-period=45s --retries=90 CMD /bin/healthcheck
30+
31+
# Expose ledger ports
32+
EXPOSE 3000
33+
EXPOSE 8000
34+
EXPOSE 5432
35+
36+
# Setup supervisor entrypoint
37+
COPY ./src/run-supabase.sh /usr/bin/run-supabase.sh
38+
COPY ./src/supervisord.conf /etc/supervisord.conf
39+
ENTRYPOINT ["/usr/bin/supervisord"]
40+
CMD ["--configuration", "/etc/supervisord.conf", "--nodaemon"]
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# supabase-all-in-one
2+
3+
An all in one supabase image that can be used as Cactus GUI backend.
4+
- This docker image is for `testing` and `development` only.
5+
- **Do NOT use in production!**
6+
7+
## Usage
8+
- Password: `your-super-secret-and-long-postgres-password`
9+
10+
### Docker Compose
11+
``` bash
12+
./script-start-docker.sh
13+
```
14+
15+
or manually:
16+
17+
``` bash
18+
docker-compose build && docker-compose up -d
19+
```
20+
21+
### Docker
22+
> Excute from the cactus root or adjust the paths accordingly.
23+
24+
``` bash
25+
# Build
26+
DOCKER_BUILDKIT=1 docker build ./tools/docker/supabase-all-in-one -t cactus-supabase-all-in-one
27+
28+
# Run
29+
docker run --name supabase_all_in_one_gui \
30+
--detach \
31+
--privileged \
32+
-p 3000:3000 \
33+
-p 8000:8000 \
34+
-p 5432:5432 \
35+
cactus-supabase-all-in-one
36+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: "3.5"
2+
3+
services:
4+
supabase-all-in-one-db:
5+
container_name: cactus-supabase-all-in-one-db
6+
image: cactus-supabase-all-in-one
7+
privileged: true
8+
build:
9+
context: ./
10+
dockerfile: Dockerfile
11+
ports:
12+
- "3000:3000" # Supabase Studio
13+
- "8000:8000" # Supabase API
14+
- "5432:5432" # Postgres
15+
network_mode: host
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
echo "[process] Start docker environment for Supabase DB"
2+
docker-compose build && docker-compose up -d
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
FREEZE_SCRIPT_NAME="download-frozen-image-v2.sh"
6+
FREEZE_SCRIPT_PATH="/usr/bin/${FREEZE_SCRIPT_NAME}"
7+
8+
echo "Download freeze script..."
9+
curl -sSL https://raw.githubusercontent.com/moby/moby/dedf8528a51c6db40686ed6676e9486d1ed5f9c0/contrib/download-frozen-image-v2.sh > "${FREEZE_SCRIPT_PATH}"
10+
chmod +x "${FREEZE_SCRIPT_PATH}"
11+
12+
# Get list of images from docker-compose
13+
for img in `grep 'image:' docker-compose.yml | tr -d ' ' | cut -d':' -f2,3`
14+
do
15+
img_path="${FREEZE_TMP_DIR}/${img/\//-}"
16+
echo "Freeze image '${img}' in '${img_path}"
17+
mkdir -p "${img_path}"
18+
bash "${FREEZE_SCRIPT_PATH}" "${img_path}" "${img}"
19+
done
20+
21+
echo "Image freeze done."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Check if supabase schemas has been added
6+
schema_count=$(docker exec supabase-db psql -U postgres -c '\du' | grep supabase | wc -l)
7+
if [ $schema_count -lt 3 ]; then exit 2; fi
8+
9+
# TODO - can be improved by checking endpoints (if current one causes troubles)
10+
11+
exit 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
while ! docker ps &> /dev/null
4+
do
5+
echo "Wait for dockerd to start..."
6+
sleep 3
7+
done
8+
9+
# Get list of images from docker-compose
10+
for img in `ls ${FREEZE_TMP_DIR}`
11+
do
12+
echo "Load frozen image '${img}'"
13+
tar -cC "${FREEZE_TMP_DIR}/${img}" . | docker load
14+
done
15+
16+
echo "Frozen images loaded"
17+
18+
docker compose -f /home/supabase/docker/docker-compose.yml up
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[supervisord]
2+
logfile = /var/log/supervisord.log
3+
logfile_maxbytes = 50MB
4+
logfile_backups=10
5+
loglevel = info
6+
7+
[program:dockerd]
8+
command=dockerd-entrypoint.sh
9+
autostart=true
10+
autorestart=true
11+
stderr_logfile=/dev/stderr
12+
stderr_logfile_maxbytes=0
13+
stdout_logfile=/dev/stdout
14+
stdout_logfile_maxbytes=0
15+
priority=1
16+
17+
[program:supabase]
18+
command=/usr/bin/run-supabase.sh
19+
autostart=true
20+
autorestart=unexpected
21+
stderr_logfile=/dev/stderr
22+
stderr_logfile_maxbytes=0
23+
stdout_logfile=/dev/stdout
24+
stdout_logfile_maxbytes=0

0 commit comments

Comments
 (0)