From 5cc310384e498d68a02e5eb343f63208f0dbb3cf Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 5 Mar 2025 18:42:56 +0100 Subject: [PATCH] Move stored data to a volume Fix the silly data wipe on re-deployment by writing the data to a volume instead of the ephemeral container filesystem. --- .dockerignore | 2 +- .gitignore | 2 +- Dockerfile | 6 ++-- schedule.json | 90 ---------------------------------------------- server/database.ts | 4 +-- 5 files changed, 7 insertions(+), 97 deletions(-) delete mode 100644 schedule.json diff --git a/.dockerignore b/.dockerignore index 6ad4181..df8dd50 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,5 +2,5 @@ node_modules .nuxt/ .output/ dist +data env* -push-subscriptions.json diff --git a/.gitignore b/.gitignore index b2ebe6f..4531e4e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,4 @@ logs !.env.example # Data -push-subscriptions.json +data diff --git a/Dockerfile b/Dockerfile index 1dfde30..1b3b6d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,15 +17,15 @@ COPY . . RUN corepack enable pnpm && pnpm run build -# Production image, copy all the files and run next +# Production image, copy all the files and run Nuxt FROM base AS runner WORKDIR /app ENV NODE_ENV=production COPY --from=builder /app/.output ./ -COPY --chown=node:node schedule.json . -RUN echo '[]' > push-subscriptions.json && chown node:node push-subscriptions.json +RUN install --owner=node --group=node --directory data +VOLUME [ "/app/data" ] USER node diff --git a/schedule.json b/schedule.json deleted file mode 100644 index f936f2b..0000000 --- a/schedule.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "locations": [ - { - "name": "House", - "id": "house", - "description": "Blue building east of the camping" - }, - { - "name": "Common House", - "id": "common-house", - "description": "That big red building in the middle" - }, - { - "name": "Info Desk", - "id": "info-desk", - "description": "Found at the entrance" - }, - { - "name": "Camping Fireplace", - "id": "camping-fireplace", - "description": "Next to the big tree" - } - ], - "events": [ - { - "name": "Arcade", - "id": "arcade", - "description": "Play retro games!", - "slots": [ - { - "id": "arcade-1", - "start": "2025-07-18T10:00Z", - "end": "2025-07-19T01:30Z", - "locations": ["house"] - }, - { - "id": "arcade-2", - "start": "2025-07-19T10:00Z", - "end": "2025-07-20T01:00Z", - "locations": ["house"] - }, - { - "id": "arcade-3", - "start": "2025-07-20T10:00Z", - "end": "2025-07-20T18:00Z", - "locations": ["house"] - } - ] - }, - { - "name": "Bonfire Stories", - "description": "Share your stories as we sit cosily around the bonfire.", - "id": "bonfire", - "slots": [ - { - "id": "bonfire-1", - "start": "2025-07-19T20:00Z", - "end": "2025-07-20T01:00Z", - "locations": ["camping-fireplace"] - } - ] - }, - { - "name": "Fursuit Games", - "description": "Playful time for the suiters.", - "id": "fursuit-games", - "slots": [ - { - "id": "fursuit-games-1", - "start": "2025-07-19T19:00Z", - "end": "2025-07-19T20:00Z", - "locations": ["common-house"] - } - ] - }, - { - "name": "Late Stragglers", - "description": "Wait a minute, why are you still here?.", - "id": "too-late", - "slots": [ - { - "id": "too-late-1", - "start": "2025-07-22T20:00Z", - "end": "2025-07-23T01:00Z", - "locations": ["camping-fireplace"] - } - ] - } - ] -} diff --git a/server/database.ts b/server/database.ts index 276cf1d..f730cdd 100644 --- a/server/database.ts +++ b/server/database.ts @@ -4,8 +4,8 @@ import { Schedule } from "~/shared/types/schedule"; // For this demo I'm just storing the runtime data in JSON files. When making // this into proper application this should be replaced with an actual database. -const schedulePath = "schedule.json" -const subscriptionsPath = "push-subscriptions.json" +const schedulePath = "data/schedule.json" +const subscriptionsPath = "data/subscriptions.json" export async function readSchedule() { let schedule: Schedule;