Skip to content

Commit

Permalink
fix: pvc/sqlite/prisma fix (#11)
Browse files Browse the repository at this point in the history
* create ammo.db if not exist

* use database url from env

* custom npm start script

* update script

* update README, remove comments from Dockerfile
  • Loading branch information
fredrikmonsen authored Nov 11, 2024
1 parent 1b3f761 commit 9b4b3cb
Show file tree
Hide file tree
Showing 10 changed files with 431 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env.example
.env.local
Dockerfile
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
NEXT_PUBLIC_BASE_PATH=/ammo
NEXT_PUBLIC_IMAGE_API_PATH=http://localhost:3000
CATALOG_API_PATH=http://localhost:3000
CATALOG_API_PATH=http://localhost:3000
DATABASE_URL=file:../db/ammo.db
1 change: 1 addition & 0 deletions .github/workflows/ci_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ jobs:
echo "NEXT_PUBLIC_KEYCLOAK_REALM=${{ steps.import-secrets.outputs.KEYCLOAK_REALM }}" >> .env.production
echo "AUTH_API_PATH=${{ steps.import-secrets.outputs.AUTH_API_PATH }}" >> .env.production
echo "CATALOG_API_PATH=${{ steps.import-secrets.outputs.CATALOG_API_PATH }}" >> .env.production
echo "DATABASE_URL=file:/app/db/ammo.db" >> .env.production
- name: Extract metadata (tags, labels) for Docker
id: meta
Expand Down
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,5 @@ next-env.d.ts
# IDE
/.idea

# local dev files
dummy-data.json

# PVC k8s
/db/ammo.db
/db/ammo.db*
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ COPY . .
ENV NEXT_TELEMETRY_DISABLED=1

RUN npx prisma generate
RUN npx prisma migrate deploy
COPY prisma ./prisma/

RUN npm run build
Expand All @@ -33,20 +32,25 @@ WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1

RUN npm install [email protected]

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

RUN mkdir .next
RUN mkdir .next && mkdir db
RUN chown nextjs:nodejs .next
RUN chown nextjs:nodejs db

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
COPY --from=builder --chown=nextjs:nodejs /app/db ./db
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules

USER nextjs

EXPOSE 3000

ENV PORT=3000


CMD HOSTNAME="0.0.0.0" node server.js
CMD ["npm", "run", "start:production"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cp .env.example .env.local
| NEXT_PUBLIC_IMAGE_API_PATH | _N/A_ | Sti til bilde-APIet |
| AUTH_API_PATH | _N/A_ | Sti til autentiserings-APIet |
| CATALOG_API_PATH | http://localhost:8087/bikube | Sti til [katalog APIet ](https://github.com/NationalLibraryOfNorway/bikube)<br/>Må starte med `http://` eller `https://` |
| DATABASE_URL | file:../db/ammo.db | Sti til databasefil (SQLite database) |

Appen bruker SQLite for å holde orden på hvilke objekter som er låst til ulike brukere.
AMMO bruker Prisma som ORM for å kommunisere med databasen.
Expand Down
2 changes: 1 addition & 1 deletion k8s/stage/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
imagePullPolicy: Always
volumeMounts:
- name: ammo-sqlite
mountPath: /db
mountPath: /app/db
volumes:
- name: ammo-sqlite
persistentVolumeClaim:
Expand Down
Loading

0 comments on commit 9b4b3cb

Please sign in to comment.