Skip to content

Commit

Permalink
feat(supabase-all-in-one): update versions, use skopeo
Browse files Browse the repository at this point in the history
- Use latest supabase and container base versions.
- Use skopeo to freeze images, fetch the containers in separate build phase.
- Add anonymous volume definitions in dockerfile to speedup default runtime.

Closes #3099

Signed-off-by: Michal Bajer <michal.bajer@fujitsu.com>
  • Loading branch information
outSH committed Apr 19, 2024
1 parent 514dc68 commit df6f6b3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 38 deletions.
65 changes: 48 additions & 17 deletions tools/docker/supabase-all-in-one/Dockerfile
@@ -1,40 +1,71 @@
FROM docker:24.0.2-dind
################################
# Common Args
################################

ARG SUPABSE_TAG="v0.22.10"
ARG supabase_tag="v0.24.03"
ARG freeze_tmp_dir="/opt/docker-freeze"

ENV FREEZE_TMP_DIR="/opt/docker-freeze"
################################
# Build phase
################################

# Install package dependencies
RUN apk update \
&& apk add --no-cache \
git \
curl \
jq \
bash \
supervisor
FROM alpine:3.19.1 as builder

ARG supabase_tag
ARG freeze_tmp_dir
ENV SUPABSE_TAG=$supabase_tag
ENV FREEZE_TMP_DIR=$freeze_tmp_dir

WORKDIR /home
RUN apk update && apk add --no-cache skopeo git curl

WORKDIR "/build"
RUN git clone --depth 1 --branch "${SUPABSE_TAG}" "https://github.com/supabase/supabase"

WORKDIR /home/supabase/docker
RUN cp .env.example .env
WORKDIR "/build/supabase/docker"
RUN mv .env.example .env

# Freeze docker images
COPY ./src/freeze-images.sh /usr/bin/freeze-images.sh
RUN bash /usr/bin/freeze-images.sh
RUN sh /usr/bin/freeze-images.sh

################################
# Runtime phase
################################

FROM docker:25.0.5-dind

ARG freeze_tmp_dir
ENV FREEZE_TMP_DIR=$freeze_tmp_dir
ENV APP_ROOT="/home/supabase/docker"

# Install package dependencies
RUN apk update \
&& apk add --no-cache \
git \
curl \
jq \
bash \
supervisor

COPY --from=builder $freeze_tmp_dir $freeze_tmp_dir
COPY --from=builder "/build/supabase/docker/" "$APP_ROOT"

# 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
# Supabase
EXPOSE 8000
# Postgres
EXPOSE 5432

# Setup supervisor entrypoint
COPY ./src/run-supabase.sh /usr/bin/run-supabase.sh
COPY ./src/supervisord.conf /etc/supervisord.conf

VOLUME /home/supabase/docker/volumes/db/data
VOLUME /home/supabase/docker/volumes/storage

ENTRYPOINT ["/usr/bin/supervisord"]
CMD ["--configuration", "/etc/supervisord.conf", "--nodaemon"]
21 changes: 16 additions & 5 deletions tools/docker/supabase-all-in-one/README.md
@@ -1,35 +1,46 @@
# 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

### Dashboard credentials:

- http://127.0.0.1:8000/
- Username: supabase
- Password: this_password_is_insecure_and_should_be_updated

### Postgress ccredentials:

- Password: `your-super-secret-and-long-postgres-password`

### Docker Compose
``` bash

```bash
./script-start-docker.sh
```

or manually:

``` bash
```bash
docker-compose build && docker-compose up -d
```

### Docker

> Excute from the cactus root or adjust the paths accordingly.
``` bash
```bash
# Build
DOCKER_BUILDKIT=1 docker build ./tools/docker/supabase-all-in-one -t cactus-supabase-all-in-one
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
Expand Down
21 changes: 9 additions & 12 deletions tools/docker/supabase-all-in-one/src/freeze-images.sh
@@ -1,21 +1,18 @@
#!/bin/bash
#!/bin/sh

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}"
img_dir=$(echo "$img" | sed 's/[:\/]/-/g') # replace '\' and ':' with '-'
img_path="${FREEZE_TMP_DIR}/${img_dir}"
echo "Freeze image '${img}' in '${img_path}'"
mkdir -p "${img_path}"
bash "${FREEZE_SCRIPT_PATH}" "${img_path}" "${img}"

skopeo copy "docker://${img}" "docker-archive:${img_path}/archive.tar:${img}"
tar -zcf "${img_path}/archive.tar.gz" "${img_path}/archive.tar"
rm -fr "${img_path}/archive.tar"
done

echo "Image freeze done."
echo "Image freeze done."
11 changes: 7 additions & 4 deletions tools/docker/supabase-all-in-one/src/run-supabase.sh
@@ -1,18 +1,21 @@
#!/bin/bash

# Wait for docker
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}`
# Load frozen images

for img in `find "${FREEZE_TMP_DIR}" -name "*.tar.gz"`
do
echo "Load frozen image '${img}'"
tar -cC "${FREEZE_TMP_DIR}/${img}" . | docker load
tar -zxf "${img}" -O | docker load
done

echo "Frozen images loaded"

docker compose -f /home/supabase/docker/docker-compose.yml up
# Run
docker compose -f "${APP_ROOT}/docker-compose.yml" up

0 comments on commit df6f6b3

Please sign in to comment.