chore: add prisma migration, fly deploy files

This commit is contained in:
Nicola Zambello 2022-02-11 13:08:45 +01:00
parent f02bf26ec4
commit dffaaa8acc
6 changed files with 107 additions and 2 deletions

1
.dockerignore Normal file
View file

@ -0,0 +1 @@
node_modules

57
Dockerfile Normal file
View file

@ -0,0 +1,57 @@
# base node image
FROM node:16-bullseye-slim as base
# Install openssl for Prisma
RUN apt-get update && apt-get install -y openssl
# set for base and all that inherit from it
ENV NODE_ENV=production
# Install all node_modules, including dev dependencies
FROM base as deps
RUN mkdir /app
WORKDIR /app
ADD package.json package-lock.json ./
RUN npm install --production=false
# Setup production node_modules
FROM base as production-deps
RUN mkdir /app
WORKDIR /app
COPY --from=deps /app/node_modules /app/node_modules
ADD package.json package-lock.json ./
RUN npm prune --production
# Build the app
FROM base as build
RUN mkdir /app
WORKDIR /app
COPY --from=deps /app/node_modules /app/node_modules
ADD prisma .
RUN npx prisma generate
ADD . .
RUN npm run build
# Finally, build the production image with minimal footprint
FROM base
ENV NODE_ENV=production
RUN mkdir /app
WORKDIR /app
COPY --from=production-deps /app/node_modules /app/node_modules
COPY --from=build /app/node_modules/.prisma /app/node_modules/.prisma
COPY --from=build /app/build /app/build
COPY --from=build /app/public /app/public
ADD . .
CMD ["npm", "run", "start"]

View file

@ -7,10 +7,17 @@ kill_timeout = 5
processes = []
[env]
DATABASE_URL = "file:/data/sqlite.db"
PORT = "8080"
NODE_ENV = "production"
[experimental]
allowed_public_ports = []
auto_rollback = true
cmd = "start_with_migrations.sh"
entrypoint = "sh"
[[mounts]]
destination = "/data"
source = "data"
[[services]]
http_checks = []

View file

@ -0,0 +1,32 @@
-- CreateTable
CREATE TABLE "Team" (
"id" TEXT NOT NULL PRIMARY KEY,
"icon" TEXT NOT NULL,
"description" TEXT
);
-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL PRIMARY KEY,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
"username" TEXT NOT NULL,
"icon" TEXT NOT NULL,
"passwordHash" TEXT NOT NULL,
"teamId" TEXT NOT NULL,
CONSTRAINT "User_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "Expense" (
"id" TEXT NOT NULL PRIMARY KEY,
"userId" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
"description" TEXT NOT NULL,
"amount" REAL NOT NULL,
CONSTRAINT "Expense_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateIndex
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");

View file

@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"

5
start_with_migrations.sh Normal file
View file

@ -0,0 +1,5 @@
#!/bin/sh
set -ex
npx prisma migrate deploy
npm run start