Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.gitignore
node_modules
prisma/generated
.github
.vscode
docs
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ dist
.tern-port

# Prisma
prisma/
!prisma/schema.prisma
prisma/generated
prisma/db/*.db*

# Generated "NFD" images
src/assets/NFD/images
assets/NFD/images/*
!assets/NFD/images/.gitkeep
29 changes: 25 additions & 4 deletions Dockerfile
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
Copy link
Contributor

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?

Copy link
Contributor

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?


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
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"]
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Empty file added assets/NFD/images/.gitkeep
Empty file.
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"serve": "node build/main.js",
"lint": "eslint -c .eslintrc.cjs src .eslintrc.cjs",
"lint:fix": "eslint -c .eslintrc.cjs src .eslintrc.cjs --fix",
"eloDecay": " node ./build/standalones/eloDecay.js"
"migrate:serve": "prisma migrate deploy && npm run serve"
},
"repository": {
"type": "git",
Expand Down
Binary file added prisma/database.empty
Binary file not shown.
Empty file added prisma/db/.gitkeep
Empty file.
111 changes: 111 additions & 0 deletions prisma/migrations/20230330024630_init/migration.sql
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");
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
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"
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ generator client {

datasource db {
provider = "sqlite"
url = "file:./dev.db"
url = "file:./db/main.db"
}

model GuildOptions {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/NFD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class NFD {

private MAX_NFD_PRICE_EXPONENT = 30

private FRAGMENT_PATH = path.join(__dirname, '../../src/assets/NFD/fragments')
private OUTPUT_PATH = path.join(__dirname, '../../src/assets/NFD/images')
private FRAGMENT_PATH = path.join(__dirname, '../../assets/NFD/fragments')
private OUTPUT_PATH = path.join(__dirname, '../../assets/NFD/images')

private MAX_NFD_LISTED = 25
private MAX_COLLAGE_ITEMS = 25
Expand Down
2 changes: 1 addition & 1 deletion src/events/CallResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type CallResponse = {

@Discord()
abstract class CallAndResponder {
private BasePath = '../../src/assets'
private BasePath = '../../assets'

// todo: Move these into a json obj and serialize and cache the obj at runtime
// Would allow us to add triggers via a mod command should we choose to
Expand Down