# syntax=docker/dockerfile:1

### Seafowl https://github.com/splitgraph/seafowl/blob/main/Dockerfile
# Assumes Seafowl binary is already present
# Download from https://github.com/splitgraph/seafowl/releases

FROM debian:bullseye-slim

COPY ./seafowl /usr/local/bin/seafowl

# Make sure to install ca-certificates so that we can use HTTPS
# https://github.com/debuerreotype/docker-debian-artifacts/issues/15
RUN \
    apt-get update -qq && \
    apt-get install -y --no-install-recommends ca-certificates curl gnupg && \
    update-ca-certificates && \
    mkdir -p /seafowl-data && \
    mkdir -p /etc/seafowl

# TODO: probably OK to remove this since we're on object_store anyway
# Make /seafowl-data a volume
# This is not required for bind mounting, but will create an anonymous volume
# on startup for persistence
# https://docs.docker.com/engine/reference/builder/#volume
VOLUME [ "/seafowl-data" ]

### gcsfuse https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/run/filesystem/Dockerfile
# Install system dependencies
RUN set -e; \
    apt-get install -y \
    tini \
    lsb-release; \
    gcsFuseRepo=gcsfuse-`lsb_release -c -s`; \
    echo "deb http://packages.cloud.google.com/apt $gcsFuseRepo main" | \
    tee /etc/apt/sources.list.d/gcsfuse.list; \
    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | \
    apt-key add -; \
    apt-get update; \
    apt-get install -y gcsfuse \
    && apt-get clean

# Set fallback mount directory
ENV MNT_DIR /mnt/gcs

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Ensure the script is executable
RUN chmod +x /app/gcsfuse_run.sh

# Use tini to manage zombie processes and signal forwarding
# https://github.com/krallin/tini
ENTRYPOINT ["/usr/bin/tini", "--"]

# Pass the startup script as arguments to Tini
CMD ["/app/gcsfuse_run.sh"]