Skip to main content

Storage bridge: copy your bucket files into Google Drive

storage-bridge

storage-bridge watches a folder of an object storage bucket (S3, CWCloud object storage, minio, Scaleway...) and copies every new file into a Google Drive folder. A typical use case is an application generating invoices or reports in a bucket, that your accountant or your team only reads in Google Drive.

It's written in Go (since the 2.0.0 version, it was previously a Python/Flask app: the environment variables, the healthcheck and manifest endpoints and the Redis cache didn't change, so upgrading is transparent) and comes with:

  • a Swagger UI and an OpenAPI documentation
  • Prometheus metrics
  • logs, traces and metrics through OpenTelemetry
  • Discord (or Slack) notifications
  • a correlation id (X-Cid) in every response, log line and notification

Git repositories​

Image on the dockerhub​

The image is available and versioned here: https://hub.docker.com/r/comworkio/storage-bridge (x86/amd64 only, tags latest, <version> such as 2.0.0, latest-x86, <version>-x86).

How it works​

Every WAIT_TIME seconds, storage-bridge lists the files of the BUCKET_FOLDER folder (recursively) and uploads each file which wasn't uploaded yet into the Google Drive folder.

The uploaded files are kept in Redis (key: the file name, value: the Google Drive file id) during REDIS_TTL seconds, so they're not uploaded twice. A file which failed to upload isn't cached, so it's retried on the next scan.

BUCKET_FOLDER can be dynamic: with YYYY-MM, the current month folder is scanned (i.e. 2026-12/).

Prepare the Google Drive access​

  1. Enable the Google Drive API in your Google Cloud project
  2. Go to credentials, then click Create Credentials > Service Account

service account

  1. Create a key for this service account, choose the JSON format, and encode the downloaded file in base64:
base64 -w0 key.json # on macOS: base64 -i key.json

json key

  1. Copy-paste the base64 content in the GOOGLE_SA_B64 environment variable
  2. Create a folder on Google Drive and share it with the service account email as editor:

share

  1. Copy-paste the folder id (the last part of the folder URL, https://drive.google.com/drive/folders/<folder id>) into the GOOGLE_DRIVE_FOLDER_ID environment variable

Run it with docker compose​

Create a storage_bridge.env file:

LOG_LEVEL=INFO
WAIT_TIME=3600
DISCORD_TRIGGER=on
DISCORD_TOKEN=changeit
DISCORD_USERNAME=storage-bridge
BUCKET_URL=s3.fr-par.scw.cloud
BUCKET_REGION=fr-par
BUCKET_ACCESS_KEY=changeit
BUCKET_SECRET_KEY=changeit
BUCKET_NAME=invoices
BUCKET_FOLDER=YYYY-MM
GOOGLE_SA_B64=changeit
GOOGLE_DRIVE_FOLDER_ID=changeit
REDIS_HOST=storage-bridge-redis
REDIS_PORT=6379
REDIS_TTL=2678400

And a docker-compose.yml file:

services:
storage-bridge:
image: comworkio/storage-bridge:latest
restart: always
container_name: storage-bridge
env_file:
- storage_bridge.env
networks:
- storage-bridge
ports:
- 8080:8080
storage-bridge-redis:
image: redis:6.2.6
restart: always
container_name: storage-bridge-redis
networks:
- storage-bridge
volumes:
- storage-bridge-redis:/data

volumes:
storage-bridge-redis:

networks:
storage-bridge:
driver: bridge

Then:

docker compose up -d

Environment variables​

VariableDescription
LOG_LEVELlog level (DEBUG, INFO, WARN, ERROR), also the minimum level of the notifications
LOG_FORMATjson (default) or text
WAIT_TIMEwait time between two scans in seconds (i.e: 3600 for one hour)
BUCKET_URLobject storage endpoint (host[:port], HTTPS by default, prefix it with http:// to disable TLS)
BUCKET_REGIONobject storage region code
BUCKET_ACCESS_KEYobject storage access key
BUCKET_SECRET_KEYobject storage secret key
BUCKET_NAMEbucket name
BUCKET_FOLDERfolder to scan; YYYY-MM for the current month folder; empty for the whole bucket
BUCKET_TMP_DIRdownload directory (default: /tmp/bucket_files)
GOOGLE_SA_B64google service account JSON key encoded in base64
GOOGLE_DRIVE_FOLDER_IDid of the Google Drive target folder
REDIS_HOST / REDIS_PORTredis server
REDIS_TTLretention of the uploaded files in the cache, in seconds (i.e: 2678400 for 31 days)
DISCORD_TRIGGERenable/disable the notifications (on or off)
DISCORD_TOKENDiscord webhook token (the part after https://discord.com/api/webhooks/)
DISCORD_TOKEN_PUBLICoptional second Discord webhook for the public notifications
DISCORD_USERNAMEDiscord username
SLACK_TRIGGER, SLACK_TOKEN, SLACK_TOKEN_PUBLIC, SLACK_CHANNEL, SLACK_USERNAME, SLACK_EMOJIsame for Slack
STORAGE_BRIDGE_VERSIONthe deployed version, displayed in the deployment notification
LISTEN_ADDR / LISTEN_PORTHTTP listening address and port (default: 0.0.0.0:8080)

Notifications​

When DISCORD_TRIGGER is on, storage-bridge sends a Discord message for each log at least at the LOG_LEVEL level: the deployment, the bucket listings, every uploaded file, the warnings (bucket or Google Drive misconfigured) and the errors. Each message ends with the correlation id (cid) of the scan, which you can search in the logs.

API​

The Swagger UI is served on the root endpoint (http://localhost:8080/) and the OpenAPI document on /openapi.json.

$ curl localhost:8080/v1/health
{"status":"ok","alive":true}
$ curl localhost:8080/v1/manifest
{"arch":"x86","sha":"1c7cb1f","version":"2.0.0"}

The /health and /manifest routes are also available without the /v1 prefix and with a trailing slash.

Every response carries an X-Cid header: the one you sent, or a generated one. On a server error, the API only answers a generic reason with this cid; the real cause is in the logs and in the Discord notification with the same cid.

Observability​

Prometheus​

The metrics are exposed on /v1/metrics (and /metrics):

  • storage_bridge_scans_total{status}: bucket scans (ok or error)
  • storage_bridge_files_uploaded_total: files uploaded to Google Drive
  • storage_bridge_files_skipped_total: files skipped because already uploaded
  • storage_bridge_upload_errors_total{step}: failures per step (download, upload, cache)
  • storage_bridge_last_scan_timestamp_seconds: unix time of the last finished scan
  • http_server_requests_total and http_server_request_duration_seconds per route, method and status
  • the Go runtime and process metrics

A simple alert to know the bridge is stuck:

time() - storage_bridge_last_scan_timestamp_seconds > 2 * 3600

OpenTelemetry​

Logs, traces and metrics can be pushed to an OpenTelemetry collector (for example the Quickwit as a service one):

VariableDescription
OTEL_COLLECTOR_ENDPOINTcollector endpoint (host:port or URL, i.e: otel-collector:4317); disabled when empty
OTEL_COLLECTOR_PROTOotlp/grpc (default) or otlp/http
OTEL_COLLECTOR_TLS_CHECKtrue to use TLS (default: false)
OTEL_COLLECTOR_USERNAME / OTEL_COLLECTOR_PASSWORDoptional basic authentication
OTEL_COLLECTOR_AUTH_HEADERoptional raw Authorization header (i.e: Bearer xxx)

Each scan is a trace (storage-bridge-scan) with a span per file (storage-bridge-file) and the S3 / Google Drive HTTP calls as children, and every log line carries the cid, trace_id and span_id.