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

test migrating to pnpm; fix a lot typing stuff #1213

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e3986cb
test migrating to pnpm; fix a lot typing stuff
mipyykko Jun 15, 2023
5a3898d
remove patch-package
mipyykko Jun 15, 2023
1b9cdde
fix pnpm install command in backend dockerfile
mipyykko Jun 15, 2023
0c3c36c
pnpm install for codestyle
mipyykko Jun 15, 2023
67bdd31
setup pnpm in backend build
mipyykko Jun 15, 2023
458dd0a
fix typo in pnpm generate
mipyykko Jun 15, 2023
46f60e0
setup pnpm in frontend build
mipyykko Jun 15, 2023
9e109f4
use npm to install pnpm
mipyykko Jun 15, 2023
9db9130
fix invalid cache keys
mipyykko Jun 15, 2023
91b94bf
try to set client output from env
mipyykko Jun 15, 2023
cfa8787
client output in env example
mipyykko Jun 15, 2023
aad3675
fix frontend build script
mipyykko Jun 15, 2023
71704aa
specifically install @prisma/internals
mipyykko Jun 15, 2023
068a685
fix dockerfile store-dir
mipyykko Jun 15, 2023
41d381b
add debug log to nexus-plugin-prisma
mipyykko Jun 15, 2023
b5bf6ec
set store in separate step in dockerfiles
mipyykko Jun 15, 2023
5117fbc
change prisma client require in schema
mipyykko Jun 15, 2023
9cbfb17
resolve prisma_path in schema
mipyykko Jun 15, 2023
731a1f1
try again with output specified
mipyykko Jun 15, 2023
8e51b19
add download env back to backend dockerfile
mipyykko Jun 15, 2023
6741767
remove debug patch; don't use ts-node in package.json scripts
mipyykko Jun 15, 2023
21e3da6
remove patch from package.json
mipyykko Jun 15, 2023
da1ab2c
update pnpm-lock
mipyykko Jun 15, 2023
4b545e2
fix createExports, try to resolve prisma symlink
mipyykko Jun 16, 2023
4778004
finally fix missing schema in nexus generate
mipyykko Jun 16, 2023
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
72 changes: 51 additions & 21 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@ jobs:
- image: cimg/node:18.16.0
steps:
- checkout
- node/install-packages
- run:
name: "Setup pnpm store"
command: |
pnpm config set store-dir ~/.pnpm-store
- restore_cache:
keys:
- root-cache-{{ checksum "package.json" }}-{{ checksum "pnpm-lock.yaml" }}
- root-cache-{{ checksum "package.json" }}
- run:
name: "Install packages"
command: |
pnpm i --prefer-offline --frozen-lockfile
- save_cache:
key: root-cache-{{ checksum "package.json" }}-{{ checksum "pnpm-lock.yaml" }}
paths:
- ~/.pnpm-store
- run:
name: "Check code style"
command: "bin/check-code-style.sh"
Expand All @@ -41,9 +56,14 @@ jobs:
- setup_remote_docker:
version: "20.10.18"
docker_layer_caching: true
- run:
name: "Setup pnpm"
command: |
npm i --prefix=~/.local -g pnpm
pnpm config set store-dir ~/.pnpm-store
- restore_cache:
keys:
- frontend-cache-{{ checksum "frontend/package.json" }}-checksum "frontend/package-lock.json" }}
- frontend-cache-{{ checksum "frontend/package.json" }}-{{ checksum "frontend/pnpm-lock.yaml" }}
- frontend-cache-{{ checksum "frontend/package.json" }}
- run:
name: Install Docker Buildx
Expand All @@ -59,9 +79,9 @@ jobs:
name: "Build frontend image"
command: "bin/build-docker-frontend.sh"
- save_cache:
key: frontend-cache-{{ checksum "frontend/package.json" }}-{{ checksum "frontend/package-lock.json" }}
key: frontend-cache-{{ checksum "frontend/package.json" }}-{{ checksum "frontend/pnpm-lock.yaml" }}
paths:
- ~/.npm
- ~/.pnpm-store
- ./frontend/.next/cache
- when:
condition:
Expand All @@ -82,29 +102,33 @@ jobs:
path: ~/project
- jq/install
- run:
name: patch-package hash
name: Hash patches
command: md5sum patches/* > patches.hash
- run:
name: "Setup pnpm store"
command: |
pnpm config set store-dir ~/.pnpm-store
- restore_cache:
keys:
- backend-cache-{{ checksum "package-lock.json" }}-{{ checksum "prisma/schema.prisma" }}-{{ checksum "patches.hash" }}
- backend-cache-{{ checksum "package-lock.json" }}-{{ checksum "prisma/schema.prisma" }}
- backend-cache-{{ checksum "package-lock.json" }}
- backend-cache-{{ checksum "pnpm-lock.yaml" }}-{{ checksum "prisma/schema.prisma" }}-{{ checksum "patches.hash" }}
- backend-cache-{{ checksum "pnpm-lock.yaml" }}-{{ checksum "prisma/schema.prisma" }}
- backend-cache-{{ checksum "pnpm-lock.yaml" }}
- run:
name: "Install dependencies"
command: npm ci --prefer-offline --no-audit
command: pnpm install --prefer-offline --frozen-lockfile
- run:
name: "Set environment"
command: |
npm run download-env
pnpm download-env
cp .env.example .env
- run:
name: "Set up Prisma"
command: |
npm run generate
pnpm generate
- save_cache:
key: backend-cache-{{ checksum "package-lock.json" }}-{{ checksum "prisma/schema.prisma" }}-{{ checksum "patches.hash" }}
key: backend-cache-{{ checksum "pnpm-lock.yaml" }}-{{ checksum "prisma/schema.prisma" }}-{{ checksum "patches.hash" }}
paths:
- ~/.npm
- ~/.pnpm-store
- persist_to_workspace:
root: ~/project
paths:
Expand Down Expand Up @@ -139,7 +163,7 @@ jobs:
command: |
TEST=$(circleci tests glob ./**/*.test.ts | grep -v node_modules | circleci tests split --split-by=timings)
echo $TEST
npm run test:ci -- --runTestsByPath $TEST
pnpm test:ci -- --runTestsByPath $TEST
- run:
name: "Process test reports"
command: |
Expand Down Expand Up @@ -202,13 +226,19 @@ jobs:
docker_layer_caching: true
- jq/install
- run:
name: patch-package hash
name: Hash patches
command: md5sum backend/patches/* > backend/patches.hash
- run:
name: "Setup pnpm"
command: |
npm i --prefix=~/.local -g pnpm
pnpm config set store-dir ~/.pnpm-store
pnpm config set global-dir ~/.local
- restore_cache:
keys:
- backend-cache-{{ checksum "backend/package-lock.json" }}-{{ checksum "backend/prisma/schema.prisma" }}-{{ checksum "backend/patches.hash" }}
- backend-cache-{{ checksum "backend/package-lock.json" }}-{{ checksum "backend/prisma/schema.prisma" }}
- backend-cache-{{ checksum "backend/package-lock.json" }}
- backend-cache-{{ checksum "backend/pnpm-lock.yaml" }}-{{ checksum "backend/prisma/schema.prisma" }}-{{ checksum "backend/patches.hash" }}
- backend-cache-{{ checksum "backend/pnpm-lock.yaml" }}-{{ checksum "backend/prisma/schema.prisma" }}
- backend-cache-{{ checksum "backend/pnpm-lock.yaml" }}
- run:
name: Install Docker Buildx
command: |
Expand All @@ -223,9 +253,9 @@ jobs:
name: "Build backend image"
command: "bin/build-docker-backend.sh"
- save_cache:
key: backend-cache-{{ checksum "backend/package-lock.json" }}-{{ checksum "backend/prisma/schema.prisma" }}-{{ checksum "backend/patches.hash" }}
key: backend-cache-{{ checksum "backend/pnpm-lock.yaml" }}-{{ checksum "backend/prisma/schema.prisma" }}-{{ checksum "backend/patches.hash" }}
paths:
- ~/.npm
- ~/.pnpm-store
- when:
condition:
or:
Expand All @@ -234,7 +264,7 @@ jobs:
steps:
- run:
name: "Install Sentry client"
command: npm i --prefix=$HOME/.local -g @sentry/cli
command: pnpm add -g @sentry/cli
- run:
name: "Push image"
command: "bin/push-docker-backend-image.sh"
Expand Down
2 changes: 2 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
semi: false,
trailingComma: "all",
bracketSpacing: true,
plugins: ["@ianvs/prettier-plugin-sort-imports"],
importOrder: [
"<BUILTIN_MODULES>",
"^react(-dom)?$",
Expand All @@ -23,4 +24,5 @@ module.exports = {
"classProperties",
"decorators-legacy",
],
importOrderTypeScriptVersion: "5.0.0",
}
4 changes: 3 additions & 1 deletion backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ KAFKA_BRIDGE_SECRET=x
KAFKA_HOST=x

DATABASE_URL=postgres://a:b@localhost:12345/fake?schema=nonexistent
CONNECTION_LIMIT=x
CONNECTION_LIMIT=1
SENTRY_DSN=x
NEW_RELIC_NO_CONFIG_FILE=x
NEW_RELIC_LICENSE_KEY=x
Expand All @@ -30,5 +30,7 @@ GOOGLE_CLOUD_STORAGE_KEYFILE=x

HY_ORGANIZATION_ID=x

PRISMA_CLIENT_OUTPUT=${PWD}/node_modules/.prisma/client

UPDATE_USER_SECRET=secret
BACKEND_URL=http://localhost:4000
42 changes: 19 additions & 23 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18.16.0-alpine
FROM node:18.16.0-alpine3.18

RUN apk update && \
apk add \
Expand All @@ -10,50 +10,46 @@ RUN apk update && \
git \
jq \
bash \
python3

RUN wget https://github.com/edenhill/librdkafka/archive/v2.1.1.tar.gz -O - | tar -xz \
&& cd librdkafka-2.1.1 \
&& ./configure --prefix=/usr \
&& make && make install \
&& cd ..
# when node image incorporates alpine 3.18
# RUN apk add \
# librdkafka=2.1.1-r0 \
# librdkafka-dev=2.1.1-r0
python3 \
librdkafka=2.1.1-r0 \
librdkafka-dev=2.1.1-r0

RUN rm -rf /var/cache/apk/*

RUN mkdir -p /app && chown -R node /app

RUN corepack enable \
&& corepack prepare pnpm@latest-8 --activate

USER node

RUN pnpm config set store-dir ~/.pnpm-store

WORKDIR /app

COPY --chown=node package.json /app/
COPY --chown=node package-lock.json /app/
COPY --chown=node package.json pnpm-lock.yaml /app/
COPY --chown=node patches /app/patches
COPY --chown=node prisma /app/prisma

ARG BUILD_LIBRDKAFKA=0
RUN npm ci --prefer-offline --no-audit
# when node image incorporates alpine 3.18
# RUN rm -rf /node_modules/node-rdkafka/deps
RUN pnpm i --prefer-offline --frozen-lockfile

COPY --chown=node . /app

RUN cp .env.example .env \
&& cp tsconfig.production.json tsconfig.json \
&& npm run download-env \
&& npm run generate \
&& env NODE_ENV=production GOOGLE_CLOUD_STORAGE_BUCKET=x npm run build
RUN npm run build-sourcemap
RUN npm run copy-env
&& pnpm download-env \
&& pnpm generate
RUN env NODE_ENV=production GOOGLE_CLOUD_STORAGE_BUCKET=x pnpm build
RUN pnpm build-sourcemap
RUN pnpm copy-env

ENV NODE_ENV=production

EXPOSE 4000
EXPOSE 7001

CMD [ "npm", "run", "start" ]
CMD [ "pnpm", "start" ]

ARG GIT_COMMIT=""
LABEL GIT_COMMIT=${GIT_COMMIT}
Expand Down
2 changes: 1 addition & 1 deletion backend/api/routes/storedData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request, Response } from "express-serve-static-core"
import { Request, Response } from "express"
import { omit } from "lodash"

import { requireCourseOwnership } from "../../util/server-functions"
Expand Down
16 changes: 8 additions & 8 deletions backend/bin/createExports.ts → backend/bin/createExports.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as fs from "fs"
import * as path from "path"
const fs = require("fs")
const path = require("path")

const DIRECTORY = "graphql"
const IGNORED_FILES: string[] = ["__test__"]
const IGNORED_FILES = ["__test__"]
const OUTPUT_FILE = "index.ts"

// @ts-ignore: not used for now
const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
const capitalize = (str) => str[0].toUpperCase() + str.slice(1)

const createExports = (dir: string): string[] => {
const createExports = (dir) => {
const files = fs.readdirSync(dir)

return files
Expand All @@ -20,16 +20,16 @@ const createExports = (dir: string): string[] => {
const fullname = `${dir ? dir + "/" : ""}${filename}`

if (fs.statSync(fullname).isDirectory()) {
const exports = createExports(fullname)
outputExports(exports, fullname)
const res = createExports(fullname)
outputExports(res, fullname)
}

const basename = path.parse(filename).name
return `export * from "./${basename}"`
})
}

const outputExports = (exports: string[], dir: string) => {
const outputExports = (exports, dir) => {
const exportFileContents = `// generated ${new Date()}\n\n${exports.join(
"\n",
)}`
Expand Down
2 changes: 1 addition & 1 deletion backend/graphql/Completion/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// generated Fri May 26 2023 14:24:46 GMT+0300 (Itä-Euroopan kesäaika)
// generated Fri Jun 16 2023 01:56:02 GMT+0300 (Itä-Euroopan kesäaika)

export * from "./input"
export * from "./model"
Expand Down
2 changes: 1 addition & 1 deletion backend/graphql/Course/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// generated Fri May 26 2023 14:24:46 GMT+0300 (Itä-Euroopan kesäaika)
// generated Fri Jun 16 2023 01:56:02 GMT+0300 (Itä-Euroopan kesäaika)

export * from "./input"
export * from "./model"
Expand Down
6 changes: 5 additions & 1 deletion backend/graphql/Exercise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
stringArg,
} from "nexus"

import { Prisma } from "@prisma/client"

import { isAdmin, Role } from "../accessControl"
import { GraphQLAuthenticationError } from "../lib/errors"
import { filterNullRecursive } from "../util/db-functions"
Expand Down Expand Up @@ -64,7 +66,9 @@ export const Exercise = objectType({
{ timestamp: "desc" },
{ updated_at: "desc" },
filterNullRecursive(orderBy),
].filter(notEmpty),
].filter(
notEmpty,
) as Prisma.Enumerable<Prisma.ExerciseCompletionOrderByWithRelationAndSearchRelevanceInput>,
})
},
})
Expand Down
2 changes: 1 addition & 1 deletion backend/graphql/StudyModule/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// generated Fri May 26 2023 14:24:46 GMT+0300 (Itä-Euroopan kesäaika)
// generated Fri Jun 16 2023 01:56:02 GMT+0300 (Itä-Euroopan kesäaika)

export * from "./input"
export * from "./model"
Expand Down
2 changes: 1 addition & 1 deletion backend/graphql/User/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// generated Fri May 26 2023 14:24:46 GMT+0300 (Itä-Euroopan kesäaika)
// generated Fri Jun 16 2023 01:56:02 GMT+0300 (Itä-Euroopan kesäaika)

export * from "./input"
export * from "./model"
Expand Down
2 changes: 1 addition & 1 deletion backend/graphql/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// generated Fri May 26 2023 14:24:46 GMT+0300 (Itä-Euroopan kesäaika)
// generated Fri Jun 16 2023 01:56:02 GMT+0300 (Itä-Euroopan kesäaika)

export * from "./ABEnrollment"
export * from "./ABStudy"
Expand Down
Loading