From 2ff9da9e5e05ebd993811fdd25831278770a076a Mon Sep 17 00:00:00 2001 From: Hugo Tiburtino Date: Tue, 16 Jul 2024 14:38:19 +0200 Subject: [PATCH 1/3] refactor!(api): remove automatic migration while locally developing --- packages/db-migrations/index.ts | 12 ------------ packages/server/Dockerfile | 4 ---- packages/server/src/internals/server/index.ts | 2 -- 3 files changed, 18 deletions(-) delete mode 100644 packages/db-migrations/index.ts diff --git a/packages/db-migrations/index.ts b/packages/db-migrations/index.ts deleted file mode 100644 index 6cbdf63eb..000000000 --- a/packages/db-migrations/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -import * as DBMigrate from 'db-migrate' -import * as path from 'path' - -export async function migrateDB() { - const packagesDir = path.join(process.cwd(), 'packages') - const migrationsDir = path.join(packagesDir, 'db-migrations') - - const dbMigrate = DBMigrate.getInstance(true, { - cwd: migrationsDir, - }) - await dbMigrate.up() -} diff --git a/packages/server/Dockerfile b/packages/server/Dockerfile index 827853de8..031acf52a 100644 --- a/packages/server/Dockerfile +++ b/packages/server/Dockerfile @@ -6,7 +6,6 @@ COPY .yarnrc.yml . COPY scripts/build.ts scripts/build.ts COPY tsconfig.json . COPY packages/authorization/package.json packages/authorization/package.json -COPY packages/db-migrations/package.json packages/db-migrations/package.json COPY packages/server/package.json packages/server/package.json COPY package.json . COPY lerna.json . @@ -15,7 +14,6 @@ COPY yarn.lock . FROM base as build_dist RUN yarn --immutable --immutable-cache --silent COPY packages/authorization packages/authorization -COPY packages/db-migrations packages/db-migrations COPY packages/server packages/server RUN yarn build:${image} @@ -27,8 +25,6 @@ ARG image WORKDIR /usr/src/app COPY --from=build_dist /usr/src/app/dist dist COPY --from=build_node_modules /usr/src/app/node_modules node_modules -COPY packages/db-migrations/database.json packages/db-migrations/database.json -RUN mkdir packages/db-migrations/migrations RUN cp dist/${image}.cjs dist/entrypoint.cjs 2>/dev/null ENTRYPOINT ["node", "dist/entrypoint.cjs"] # for server and swr queue worker respectively, but EXPOSE is anyway just for documentation diff --git a/packages/server/src/internals/server/index.ts b/packages/server/src/internals/server/index.ts index 493321286..8acaa7ca6 100644 --- a/packages/server/src/internals/server/index.ts +++ b/packages/server/src/internals/server/index.ts @@ -21,8 +21,6 @@ export { getGraphQLOptions } from './graphql-middleware' export async function start() { dotenv.config() - if (process.env.ENVIRONMENT === 'local') await migrateDB() - initializeSentry({ context: 'server' }) const timer = createTimer() const cache = From ccb94f6c02dc7c583cb67363db0b905627efb1d4 Mon Sep 17 00:00:00 2001 From: Hugo Tiburtino Date: Tue, 16 Jul 2024 14:45:24 +0200 Subject: [PATCH 2/3] refactor: remove unused import and minor styling changes --- packages/server/Dockerfile | 8 ++++---- packages/server/src/internals/server/index.ts | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/server/Dockerfile b/packages/server/Dockerfile index 031acf52a..8283d6ae9 100644 --- a/packages/server/Dockerfile +++ b/packages/server/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20 as base +FROM node:20 AS base ARG image WORKDIR /usr/src/app COPY .yarn .yarn @@ -11,16 +11,16 @@ COPY package.json . COPY lerna.json . COPY yarn.lock . -FROM base as build_dist +FROM base AS build_dist RUN yarn --immutable --immutable-cache --silent COPY packages/authorization packages/authorization COPY packages/server packages/server RUN yarn build:${image} -FROM base as build_node_modules +FROM base AS build_node_modules RUN yarn workspaces focus --all --production -FROM node:20-alpine as release +FROM node:20-alpine AS release ARG image WORKDIR /usr/src/app COPY --from=build_dist /usr/src/app/dist dist diff --git a/packages/server/src/internals/server/index.ts b/packages/server/src/internals/server/index.ts index 8acaa7ca6..2610e461b 100644 --- a/packages/server/src/internals/server/index.ts +++ b/packages/server/src/internals/server/index.ts @@ -1,4 +1,3 @@ -import { migrateDB } from '@serlo/db-migrations' import cors from 'cors' import dotenv from 'dotenv' import createApp from 'express' From 8722f1eba2088b83e231d37edacd0cd9ca4d33f6 Mon Sep 17 00:00:00 2001 From: Hugo Tiburtino Date: Tue, 16 Jul 2024 14:48:45 +0200 Subject: [PATCH 3/3] chore(docker): fix remove with yarn install immutable cache --- packages/server/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/server/Dockerfile b/packages/server/Dockerfile index 8283d6ae9..c5e8abe15 100644 --- a/packages/server/Dockerfile +++ b/packages/server/Dockerfile @@ -7,6 +7,7 @@ COPY scripts/build.ts scripts/build.ts COPY tsconfig.json . COPY packages/authorization/package.json packages/authorization/package.json COPY packages/server/package.json packages/server/package.json +COPY packages/db-migrations/package.json packages/db-migrations/package.json COPY package.json . COPY lerna.json . COPY yarn.lock .