From 35a1af78526c132cf16833c136952c13887a61a6 Mon Sep 17 00:00:00 2001 From: itsamejms Date: Thu, 4 Jun 2026 18:50:02 +0100 Subject: [PATCH] adding the config files for deploying this remote --- .gitignore | 1 + Dockerfile | 18 ++++++++++++++++ README.md | 20 ++++++++++++++++++ entrypoint.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ litestream.yml | 6 ++++++ 5 files changed, 101 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 entrypoint.sh create mode 100644 litestream.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ca3c37b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +# Step 1: Grab the official Litestream binary +FROM litestream/litestream:0.3.13 AS litestream + +# Step 2: Build our actual runtime container using official Gitea +FROM gitea/gitea:1.22.0 + +# Copy Litestream binary into the Gitea container +COPY --from=litestream /usr/local/bin/litestream /usr/local/bin/litestream + +# Copy our custom configuration files +COPY litestream.yml /etc/litestream.yml +COPY entrypoint.sh /usr/local/bin/litestream-entrypoint.sh + +# Make sure our script is executable by the container +RUN chmod +x /usr/local/bin/litestream-entrypoint.sh + +# Re-route the container's entrypoint to use our custom script +ENTRYPOINT ["/usr/local/bin/litestream-entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4372da9 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +## GCP deploy +- `gcloud auth login` +- `gcloud config set project itsamejms` +- `gcloud auth application-default set-quota-project itsamejms` +- `gcloud run services list` +- `gcloud services enable run.googleapis.com artifactregistry.googleapis.com storage.googleapis.com` +- `gcloud storage buckets create gs://jms-git-bucket --location=europe-west1` + +``` +gcloud run deploy gitea-serverless \ + --source . \ + --region europe-west1 \ + --allow-unauthenticated \ + --max-instances 1 \ + --memory 512Mi \ + --port 3000 \ + --set-env-vars="GCS_BUCKET_NAME=jms-git-bucket" \ + --set-env-vars="GITEA_WORK_DIR=/data/gitea" \ + --set-env-vars="GITEA_CUSTOM=/data/gitea" +``` \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..4122b5a --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,56 @@ +#!/bin/bash +set -e + +# Define standard storage paths inside our writeable volume +DB_PATH="/data/gitea/gitea.db" +CONF_DIR="/data/gitea/conf" +CONF_PATH="$CONF_DIR/app.ini" + +# 1. Initialize writeable working directories and hand ownership to the 'git' user +mkdir -p "$CONF_DIR" +mkdir -p /data/gitea/app_data +chown -R git:git /data + +# 2. Restore SQLite database if it exists in Cloud Storage +if [ ! -f "$DB_PATH" ]; then + echo "[Litestream] SQLite database not found locally. Checking GCS for replica..." + if litestream restore -config /etc/litestream.yml "$DB_PATH"; then + echo "[Litestream] Database successfully restored from GCS." + chown git:git "$DB_PATH" + else + echo "[Litestream] No backup replica found. Initializing new database." + fi +fi + +# 3. Launch the Litestream background replication process +echo "[Litestream] Starting replication backend process..." +litestream replicate -config /etc/litestream.yml & + +# 4. MANUALLY WRITE THE APP.INI CONFIG FILE (Bypasses all Gitea wizards) +echo "[Gitea] Writing configuration profile to app.ini..." +cat < "$CONF_PATH" +APP_NAME = Serverless Git +RUN_MODE = prod +RUN_USER = git + +[database] +DB_TYPE = sqlite3 +PATH = $DB_PATH + +[security] +INSTALL_LOCK = true + +[server] +HTTP_PORT = 3000 +PROTOCOL = http + +[repository] +ROOT = /data/gitea/app_data/repositories +EOF + +# Ensure the config file is fully readable and writeable by the git user +chown git:git "$CONF_PATH" + +# 5. Drop Root Privileges and boot the Gitea Web server pointing to our manual config +echo "[Gitea] Dropping privileges to 'git' user and booting web service core..." +exec su git -c "/app/gitea/gitea web --config $CONF_PATH --port 3000" \ No newline at end of file diff --git a/litestream.yml b/litestream.yml new file mode 100644 index 0000000..48f5478 --- /dev/null +++ b/litestream.yml @@ -0,0 +1,6 @@ +dbs: + - path: /data/gitea/gitea.db + replicas: + - type: gcs + bucket: "${GCS_BUCKET_NAME}" + path: "database" \ No newline at end of file