-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update docker setup to include migrations #189
base: main
Are you sure you want to change the base?
Changes from all commits
2278ec7
c15948c
15929ce
f933f17
11bab70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
.gitignore | ||
node_modules | ||
prisma/generated | ||
.github | ||
.vscode | ||
docs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
FROM node:16.13.1-alpine3.15 | ||
# syntax=docker/dockerfile:1 | ||
FROM node:lts-alpine3.17 as builder | ||
|
||
WORKDIR /usr/src/app | ||
WORKDIR /app | ||
|
||
COPY package*.json ./ | ||
COPY prisma ./prisma | ||
|
||
RUN npm install | ||
|
||
COPY . . | ||
RUN npx prisma generate && npx prisma migrate dev --name init && npm run build | ||
|
||
CMD ["npm", "run", "serve"] | ||
RUN npm run build && npx prisma generate | ||
|
||
FROM node:lts-alpine3.17 | ||
|
||
WORKDIR /app | ||
|
||
RUN addgroup -S twiggy && adduser -S twiggy -G twiggy | ||
|
||
COPY --from=builder /app/node_modules ./node_modules | ||
COPY --from=builder /app/assets ./assets | ||
COPY --from=builder /app/package*.json ./ | ||
COPY --from=builder /app/build ./build | ||
COPY --from=builder /app/prisma ./prisma | ||
COPY --from=builder /app/prisma/database.empty ./prisma/db/main.db | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of doing this type of renames instead of having the same filename inside and outside, so I would suggest having the same name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However since this is for a production Dockerfile only for now is not as bad. |
||
|
||
RUN chown -R twiggy:twiggy /app/prisma/db /app/assets/NFD/images | ||
This comment was marked as resolved.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only want to have specific paths accessible for the twiggy user. |
||
|
||
USER twiggy | ||
|
||
CMD ["npm", "run", "migrate:serve"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
-- CreateTable | ||
CREATE TABLE "GuildOptions" ( | ||
"guildId" TEXT NOT NULL PRIMARY KEY, | ||
"gambleChance" DECIMAL NOT NULL DEFAULT 33.33, | ||
"globalDuelCD" INTEGER NOT NULL DEFAULT 60000, | ||
"lastDuel" DATETIME NOT NULL DEFAULT 0, | ||
"lastRPG" DATETIME NOT NULL DEFAULT 0 | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "User" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"favColor" TEXT, | ||
"lastRandom" DATETIME NOT NULL DEFAULT 0, | ||
"lastLoss" DATETIME NOT NULL DEFAULT 0 | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Duels" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"userId" TEXT NOT NULL, | ||
"losses" INTEGER NOT NULL DEFAULT 0, | ||
"wins" INTEGER NOT NULL DEFAULT 0, | ||
"draws" INTEGER NOT NULL DEFAULT 0, | ||
"winStreak" INTEGER NOT NULL DEFAULT 0, | ||
"lossStreak" INTEGER NOT NULL DEFAULT 0, | ||
"winStreakMax" INTEGER NOT NULL DEFAULT 0, | ||
"lossStreakMax" INTEGER NOT NULL DEFAULT 0, | ||
CONSTRAINT "Duels_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "BestMixu" ( | ||
"id" TEXT NOT NULL DEFAULT '1', | ||
"owner" TEXT NOT NULL DEFAULT '', | ||
"tiles" TEXT NOT NULL DEFAULT '', | ||
"score" INTEGER NOT NULL DEFAULT 0 | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "RPGCharacter" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"wins" INTEGER NOT NULL DEFAULT 0, | ||
"losses" INTEGER NOT NULL DEFAULT 0, | ||
"draws" INTEGER NOT NULL DEFAULT 0, | ||
"lastLoss" DATETIME NOT NULL DEFAULT 0, | ||
"eloRank" INTEGER NOT NULL DEFAULT 1000, | ||
"peakElo" INTEGER NOT NULL DEFAULT 1000, | ||
"floorElo" INTEGER NOT NULL DEFAULT 1000 | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "NFDItem" ( | ||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
"name" TEXT NOT NULL, | ||
"code" TEXT NOT NULL, | ||
"filename" TEXT NOT NULL, | ||
"owner" TEXT NOT NULL, | ||
"discordUrl" TEXT NOT NULL DEFAULT '', | ||
"mintDate" DATETIME NOT NULL DEFAULT 0, | ||
"previousOwners" TEXT NOT NULL DEFAULT '', | ||
"coveters" TEXT NOT NULL DEFAULT '', | ||
"shunners" TEXT NOT NULL DEFAULT '', | ||
"hotness" INTEGER NOT NULL DEFAULT 0 | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "NFDEnjoyer" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"mintCount" INTEGER NOT NULL DEFAULT 0, | ||
"lastMint" DATETIME NOT NULL DEFAULT 0, | ||
"lastGiftGiven" DATETIME NOT NULL DEFAULT 0, | ||
"lastSlurp" DATETIME NOT NULL DEFAULT 0, | ||
"consecutiveFails" INTEGER NOT NULL DEFAULT 4, | ||
"successfulMints" INTEGER NOT NULL DEFAULT 0, | ||
"failedMints" INTEGER NOT NULL DEFAULT 0 | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "NFDEnthusiasts" ( | ||
"dinoId" INTEGER NOT NULL, | ||
"enjoyerId" TEXT NOT NULL, | ||
|
||
PRIMARY KEY ("dinoId", "enjoyerId"), | ||
CONSTRAINT "NFDEnthusiasts_dinoId_fkey" FOREIGN KEY ("dinoId") REFERENCES "NFDItem" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
CONSTRAINT "NFDEnthusiasts_enjoyerId_fkey" FOREIGN KEY ("enjoyerId") REFERENCES "NFDEnjoyer" ("id") ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "GuildOptions_guildId_key" ON "GuildOptions"("guildId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_id_key" ON "User"("id"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "BestMixu_id_key" ON "BestMixu"("id"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "RPGCharacter_id_key" ON "RPGCharacter"("id"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "NFDItem_name_key" ON "NFDItem"("name"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "NFDItem_code_key" ON "NFDItem"("code"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "NFDItem_filename_key" ON "NFDItem"("filename"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "NFDEnjoyer_id_key" ON "NFDEnjoyer"("id"); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to specify the exact version so if someone else pulls the dockerfile later on doesn't get a different minor version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, what were the benefits of having a builder stage? Wouldn't it mean that the builder stage is not cached and every release would have to reinstall the node modules part even if it's just a change in a string in our code?