-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompose.yaml
More file actions
85 lines (78 loc) · 3.3 KB
/
Copy pathcompose.yaml
File metadata and controls
85 lines (78 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: sjf-dev
# Local S3 for development, using Garage (the same object store the cluster
# runs). `docker compose up -d` leaves you with a ready-to-use bucket at
# http://localhost:3900 - no manual `garage` commands needed.
#
# Postgres is not included here: it is expected to be running on the host, see
# DATABASE_URL in .env.
services:
garage:
image: dxflrs/garage:v2.1.0
container_name: sjf-garage
restart: unless-stopped
ports:
- "3900:3900" # S3 API -> OBJECT_STORAGE_URI
- "3903:3903" # admin API
volumes:
- ./garage.toml:/etc/garage.toml:ro
- garage-meta:/var/lib/garage/meta
- garage-data:/var/lib/garage/data
healthcheck:
# The image has no shell and no curl, so probe with garage's own binary.
test: ["CMD", "/garage", "status"]
interval: 3s
timeout: 5s
retries: 20
start_period: 5s
# One-shot bootstrap: assigns the node a layout role, installs the fixed
# dev credentials from .env, and creates the bucket the app expects.
# Idempotent - safe to re-run, and re-runs on every `compose up`.
garage-init:
build:
# The garage image is distroless, so graft its binary onto alpine to get
# a shell for the bootstrap script.
dockerfile_inline: |
FROM alpine:3.22
COPY --from=dxflrs/garage:v2.1.0 /garage /usr/local/bin/garage
container_name: sjf-garage-init
depends_on:
garage:
condition: service_healthy
volumes:
- ./garage.toml:/etc/garage.toml:ro
# The CLI derives the target node id from node_key in the metadata dir,
# then reaches the daemon over RPC at rpc_public_addr (garage:3901).
- garage-meta:/var/lib/garage/meta
environment:
BUCKET: sjf-images-bucket
KEY_NAME: sjf-local
ACCESS_KEY_ID: GK68fbc0ed4a920bd677e192ad
SECRET_ACCESS_KEY: 01844be76de1fdc087adde1da1022d642ea07264cf6eb39b06bb183480f0f3cf
entrypoint: ["/bin/sh", "-euc"]
command:
- |
# A node with no layout role reports "NO ROLE ASSIGNED" in `status`.
if garage status | grep -q "NO ROLE ASSIGNED"; then
NODE_ID=$$(garage node id -q | cut -d@ -f1)
echo "==> assigning layout role to $$NODE_ID"
garage layout assign -z dc1 -c 1G "$$NODE_ID"
# Committing bumps the layout version; take whichever one is staged.
VERSION=$$(garage layout show | sed -n 's/.*layout apply --version \([0-9]*\).*/\1/p' | tail -1)
garage layout apply --version "$$VERSION"
sleep 2
else
echo "==> layout already assigned"
fi
echo "==> installing access key $$ACCESS_KEY_ID"
garage key import --yes -n "$$KEY_NAME" "$$ACCESS_KEY_ID" "$$SECRET_ACCESS_KEY" \
> /dev/null 2>&1 || echo " key already present"
# The app calls CreateBucket when the bucket is missing, so the key
# needs this even though we pre-create the bucket below.
garage key allow --create-bucket "$$KEY_NAME" > /dev/null
echo "==> creating bucket $$BUCKET"
garage bucket create "$$BUCKET" > /dev/null 2>&1 || echo " bucket already exists"
garage bucket allow --read --write --owner "$$BUCKET" --key "$$KEY_NAME" > /dev/null
echo "==> garage ready: s3://$$BUCKET at http://localhost:3900"
volumes:
garage-meta:
garage-data: