Skip to content

Commit 935ca45

Browse files
dmerrickclaude
andauthored
build: bake postgresql-client + seed files into tripbot image (#473)
* build(tripbot): bake postgresql-client + seed files into the image Adds postgresql-client to the runtime apt install, copies infra/docker/bin/seed-db.sh to /usr/local/bin/seed-db, and copies db/seed/ to /seed — prerequisites for the k8s seed Job that runs the script in-cluster without a volume mount. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(seed-db): remove runtime apt-install; add idempotency check postgresql-client is now baked into the image, so the runtime apt install is removed. The CSV path moves from the volume-mounted repo path to /seed (in-image). Adds a row-count check so re-runs against a non-empty videos table exit cleanly instead of failing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * build(tripbot): install postgresql-client on-demand in seed script Removes postgresql-client from the image's base apt install — it's only needed by the one-time seed Job, so baking it into every tripbot container is wasteful. The seed script installs it at runtime with --no-install-recommends instead (leaner than the original full postgresql package). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * build: un-exclude infra/docker/bin from .dockerignore The .dockerignore excluded all of infra/ (with only infra/docker/obs carved back out). seed-db.sh lives in infra/docker/bin/ and needs to be reachable by the COPY in the Dockerfile. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent af45f0f commit 935ca45

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.env.*
22
infra
33
!infra/docker/obs
4+
!infra/docker/bin
45
assets/video
56
log

infra/docker/bin/seed-db.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
set -ex
44

5-
apt update
6-
apt install -y postgresql
7-
psql "postgres://$DATABASE_USER:$DATABASE_PASS@$DATABASE_HOST/$DATABASE_DB" \
8-
-c "\copy videos FROM 'db/seed/videos.csv' DELIMITER ',' CSV HEADER;"
5+
apt-get install -y --no-install-recommends postgresql-client
6+
7+
DSN="postgres://$DATABASE_USER:$DATABASE_PASS@$DATABASE_HOST/$DATABASE_DB"
8+
9+
COUNT=$(psql "$DSN" -tAc "SELECT COUNT(*) FROM videos;")
10+
if [ "$COUNT" -gt 0 ]; then
11+
echo "videos table already has $COUNT rows — skipping seed"
12+
exit 0
13+
fi
14+
15+
psql "$DSN" -c "\copy videos FROM '/seed/videos.csv' DELIMITER ',' CSV HEADER;"

infra/docker/tripbot/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ COPY --from=builder /out/tripbot /usr/local/bin/tripbot
2828
COPY --from=migrate/migrate:4 /usr/local/bin/migrate /usr/local/bin/migrate
2929
COPY db/migrate /migrations
3030

31+
# Bundle seed script + data so the k8s seed Job is self-contained.
32+
COPY infra/docker/bin/seed-db.sh /usr/local/bin/seed-db
33+
COPY db/seed /seed
34+
3135
ARG VERSION=dev
3236
ARG SHA=unknown
3337
RUN mkdir -p /etc/tripbot \

0 commit comments

Comments
 (0)