Skip to content

Commit

Permalink
Merge pull request #1133 from serlo/docker-test
Browse files Browse the repository at this point in the history
chore: Add yarn + CI commands to test the docker build
  • Loading branch information
hugotiburtino authored Nov 27, 2023
2 parents 0c7c473 + 29dba42 commit f12b8a5
Show file tree
Hide file tree
Showing 24 changed files with 439 additions and 93 deletions.
9 changes: 9 additions & 0 deletions .env-docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
REDIS_URL=redis://host.docker.internal:6379
SERLO_ORG_DATABASE_LAYER_HOST=host.docker.internal:8080

SERVER_HYDRA_HOST=http://host.docker.internal:4445
SERVER_KRATOS_PUBLIC_HOST=http://host.docker.internal:4433
SERVER_KRATOS_ADMIN_HOST=http://host.docker.internal:4434
SERVER_KRATOS_DB_URI=postgres://serlo:secret@host.docker.internal:5432/kratos?sslmode=disable\&max_conns=20\&max_idle_conns=4

ENMESHED_SERVER_HOST="http://host.docker.internal:8081/"
13 changes: 0 additions & 13 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,6 @@
"import/no-cycle": "error",
"import/no-default-export": "error",
"import/no-deprecated": "error",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": [
"packages/server/scripts/**/*",
"scripts/**/*",
"jest.config.cjs",
"jest.config-pacts-*.js",
"__config__/*.ts"
],
"optionalDependencies": false
}
],
"import/no-internal-modules": [
"error",
{
Expand Down
21 changes: 13 additions & 8 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ name: Docker
on:
pull_request:
merge_group:
env:
PR_NUMBER: ${{ github.event.number }}
jobs:
build-docker-images:
name: Build docker images
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
image: [api-server, api-swr-queue-worker]
image: [server, swr-queue-worker]
include:
- image: api-server
- image: server
dockerfile: packages/server/docker/server/Dockerfile
- image: api-swr-queue-worker
- image: swr-queue-worker
dockerfile: packages/server/docker/swr-queue-worker/Dockerfile
steps:
- uses: actions/checkout@v4
Expand All @@ -27,6 +25,13 @@ jobs:
push: false
load: true
file: ${{ matrix.dockerfile }}
tags: ${{ matrix.image }}:PR-${{ env.PR_NUMBER }}
- name: Test for node in the ${{ matrix.image }} image
run: docker run --entrypoint='' --rm ${{ matrix.image }}:PR-${{ env.PR_NUMBER }} node --version
tags: api-${{ matrix.image }}-local-build:latest
- uses: serlo/configure-repositories/actions/setup-node@main
- name: Start redis
run: yarn start:redis
- name: Run the ${{ matrix.image }} docker image
run: yarn docker:run:${{ matrix.image }}
- name: Wait a little bit until the container was started
run: sleep 3
- name: Test the docker container ${{ matrix.image }}
run: yarn test:docker:${{ matrix.image }}
13 changes: 5 additions & 8 deletions .github/workflows/js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,36 @@ jobs:
- uses: actions/checkout@v4
- uses: serlo/configure-repositories/actions/setup-node@main
- run: yarn --check-cache
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: serlo/configure-repositories/actions/setup-node@main
- run: yarn build
- run: yarn build:server
- run: yarn build:swr-queue-worker

eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: serlo/configure-repositories/actions/setup-node@main
- run: yarn lint:eslint

prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: serlo/configure-repositories/actions/setup-node@main
- run: yarn lint:prettier

tsc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: serlo/configure-repositories/actions/setup-node@main
- run: yarn lint:tsc

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: serlo/configure-repositories/actions/setup-node@main
- run: yarn start:redis
- run: yarn test

codegen:
runs-on: ubuntu-latest
steps:
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
28 changes: 28 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ plugins:
spec: '@yarnpkg/plugin-interactive-tools'
- path: .yarn/plugins/@yarnpkg/plugin-outdated.cjs
spec: 'https://mskelton.dev/yarn-outdated/v2'
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'

supportedArchitectures:
libc:
Expand Down
23 changes: 20 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,27 @@
"_eslint": "eslint \"{{__fixtures__,__tests-pacts__,__tests__,scripts,packages/*/src}/**/*,*}.{js,jsx,ts,tsx}\"",
"_prettier": "prettier .",
"auth": "scripts/authenticate.sh",
"build": "lerna run --stream build",
"build:server": "lerna run --stream build:server",
"build:swr-queue-worker": "lerna run --stream build:swr-queue-worker",
"_build": "ts-node --experimental-specifier-resolution=node scripts/build",
"build:server": "yarn _build packages/server/src/server.ts server.cjs",
"build:swr-queue-worker": "yarn _build packages/server/src/swr-queue-worker.ts swr-queue-worker.cjs",
"changelog": "ts-node-esm scripts/changelog.ts",
"check:all": "scripts/run_all_checks.sh",
"check:unused-dependencies": "depcheck",
"check:unused-exports": "ts-unused-exports tsconfig.json --excludePathsFromReport=packages/types/ --excludePathsFromReport=packages/server/src/types.ts --ignoreFiles=/dist/",
"codegen": "lerna run --stream codegen",
"deploy:images": "lerna run --stream deploy:image",
"docker:build": "run-s \"docker:build:*\"",
"docker:build:server": "docker build -f packages/server/docker/server/Dockerfile -t api-server-local-build:latest .",
"docker:build:swr-queue-worker": "docker build -f packages/server/docker/swr-queue-worker/Dockerfile -t api-swr-queue-worker-local-build:latest .",
"docker:rm": "run-p --continue-on-error --print-label \"docker:rm:*\" ",
"docker:rm:server": "docker image rm api-server-local-build",
"docker:rm:swr-queue-worker": "docker image rm api-swr-queue-worker-local-build",
"docker:run": "run-p --print-label \"docker:run:*\"",
"docker:run:server": "docker run -p 3001:3001 -d --env-file .env --env-file .env-docker --add-host=host.docker.internal:host-gateway --name api-server-from-local-build api-server-local-build",
"docker:run:swr-queue-worker": "docker run -p 3030:3000 -d --env-file .env --env-file .env-docker --add-host=host.docker.internal:host-gateway --name api-swr-queue-worker-from-local-build api-swr-queue-worker-local-build",
"docker:stop": "run-p --continue-on-error --print-label \"docker:stop:*\"",
"docker:stop:server": "docker stop api-server-from-local-build && docker container rm api-server-from-local-build",
"docker:stop:swr-queue-worker": "docker stop api-swr-queue-worker-from-local-build && docker container rm api-swr-queue-worker-from-local-build",
"format": "npm-run-all -c \"format:*\"",
"format:eslint": "yarn _eslint --fix",
"format:prettier": "yarn _prettier --write",
Expand All @@ -48,21 +60,26 @@
"stop:enmeshed": "docker-compose -f enmeshed/docker-compose.yml down",
"stop:redis": "docker-compose stop",
"test": "jest --config jest.config.cjs --runInBand --forceExit",
"test:docker:server": "curl -X POST -H 'Content-type: application/json' --data '{\"query\": \"query { version }\" }' http://localhost:3001/graphql",
"test:docker:swr-queue-worker": "curl -s http://localhost:3030/.well-known/health | grep OK",
"update-version": "./scripts/update_version.sh"
},
"dependencies": {
"graphql": "^16.8.1"
},
"devDependencies": {
"@inyono/changelog": "^0.5.2",
"@luckycatfactory/esbuild-graphql-loader": "^3.8.1",
"@pact-foundation/pact": "^11.0.2",
"@pact-foundation/pact-node": "^10.17.7",
"@sentry/node": "^7.82.0",
"@types/jest": "^29.5.10",
"@types/node": "^18.18.13",
"@typescript-eslint/eslint-plugin": "^6.13.0",
"@typescript-eslint/parser": "^6.13.0",
"default-import": "^1.1.5",
"depcheck": "^1.4.7",
"esbuild": "^0.19.7",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.29.0",
Expand Down
34 changes: 18 additions & 16 deletions packages/server/docker/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
FROM node:18 as dependencies
FROM node:18 as base
WORKDIR /usr/src/app
COPY .yarn .yarn
COPY .yarnrc.yml .
COPY scripts/build.ts scripts/build.ts
COPY tsconfig.json .
COPY tsconfig.prod.json .
COPY packages/authorization/package.json packages/authorization/package.json
COPY packages/graphql-modules/package.json packages/graphql-modules/package.json
COPY packages/server/package.json packages/server/package.json
COPY packages/types/package.json packages/types/package.json
COPY .yarnrc.yml .
COPY package.json .
COPY lerna.json .
COPY yarn.lock .
RUN yarn --immutable --immutable-cache --silent

FROM dependencies as build
FROM base as build_dist
RUN yarn --immutable --immutable-cache --silent
COPY packages/authorization packages/authorization
COPY packages/graphql-modules packages/graphql-modules
COPY packages/server packages/server
COPY packages/graphql-modules packages/graphql-modules
COPY packages/types packages/types
COPY lerna.json .
COPY tsconfig.json .
COPY tsconfig.prod.json .
RUN yarn lerna run --include-dependencies --scope @serlo/authorization build
RUN yarn lerna run --scope @serlo/api.serlo.org build:server
RUN yarn build:server

FROM base as build_node_modules
RUN yarn workspaces focus @serlo/api.serlo.org --production

FROM dependencies as release
COPY --from=build /usr/src/app/packages/authorization/dist packages/authorization/dist
COPY --from=build /usr/src/app/packages/server/dist packages/server/dist
COPY --from=build /usr/src/app/packages/types/dist packages/types/dist
WORKDIR /usr/src/app/packages/server
ENTRYPOINT ["node", "dist"]
FROM node:18-alpine as release
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
ENTRYPOINT ["node", "dist/server.cjs"]
EXPOSE 3000
34 changes: 18 additions & 16 deletions packages/server/docker/swr-queue-worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
FROM node:18 as dependencies
FROM node:18 as base
WORKDIR /usr/src/app
COPY .yarn .yarn
COPY .yarnrc.yml .
COPY scripts/build.ts scripts/build.ts
COPY tsconfig.json .
COPY tsconfig.prod.json .
COPY packages/authorization/package.json packages/authorization/package.json
COPY packages/graphql-modules/package.json packages/graphql-modules/package.json
COPY packages/server/package.json packages/server/package.json
COPY packages/types/package.json packages/types/package.json
COPY .yarnrc.yml .
COPY package.json .
COPY lerna.json .
COPY yarn.lock .
RUN yarn --immutable --immutable-cache --silent

FROM dependencies as build
FROM base as build_dist
RUN yarn --immutable --immutable-cache --silent
COPY packages/authorization packages/authorization
COPY packages/graphql-modules packages/graphql-modules
COPY packages/server packages/server
COPY packages/graphql-modules packages/graphql-modules
COPY packages/types packages/types
COPY lerna.json .
COPY tsconfig.json .
COPY tsconfig.prod.json .
RUN yarn lerna run --include-dependencies --scope @serlo/authorization build
RUN yarn lerna run --scope @serlo/api.serlo.org build:swr-queue-worker
RUN yarn build:swr-queue-worker

FROM base as build_node_modules
RUN yarn workspaces focus @serlo/api.serlo.org --production

FROM dependencies as release
COPY --from=build /usr/src/app/packages/authorization/dist packages/authorization/dist
COPY --from=build /usr/src/app/packages/server/dist packages/server/dist
COPY --from=build /usr/src/app/packages/types/dist packages/types/dist
WORKDIR /usr/src/app/packages/server
ENTRYPOINT ["node", "dist"]
FROM node:18-alpine as release
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
ENTRYPOINT ["node", "dist/swr-queue-worker.cjs"]
EXPOSE 3000
40 changes: 20 additions & 20 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,33 @@
"start:swr-queue-worker": "tsdx watch --transpileOnly --format cjs --target node --entry src/swr-queue-worker.ts --tsconfig tsconfig.prod.json --onSuccess \"node dist\""
},
"dependencies": {
"bee-queue": "^1.7.0"
},
"devDependencies": {
"@apollo/server": "^4.9.5",
"@google-cloud/storage": "^7.6.0",
"@graphql-codegen/add": "^5.0.0",
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/typescript": "^4.0.1",
"@graphql-codegen/typescript-resolvers": "^4.0.1",
"@nmshd/connector-sdk": "^2.2.4",
"@ory/client": "^1.4.3",
"@sentry/node": "^7.82.0",
"@serlo/authorization": "^0.58.0",
"@types/basic-auth": "^1.1.6",
"@types/bull-arena": "^3.0.10",
"@types/graphql-modules": "^0.58.0",
"@types/jsonwebtoken": "^9.0.5",
"@types/pg": "^8.10.9",
"@types/ramda": "^0.29.9",
"@types/redlock": "^4.0.7",
"@types/semver": "^7.5.6",
"@types/uuid": "^9.0.7",
"@zerollup/ts-transform-paths": "^1.7.18",
"apollo-datasource-rest": "^3.7.0",
"babel-plugin-import-graphql": "^2.8.1",
"babel-plugin-module-resolver": "^5.0.0",
"basic-auth": "^2.0.1",
"bee-queue": "^1.7.1",
"bull-arena": "^4.1.0",
"dotenv": "^16.3.1",
"express": "^4.18.2",
Expand All @@ -48,26 +66,8 @@
"pg": "^8.11.3",
"ramda": "^0.29.1",
"redlock": "^5.0.0-beta2",
"semver": "^7.5.4",
"ts-toolbelt": "^9.6.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@graphql-codegen/add": "^5.0.0",
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/typescript": "^4.0.1",
"@graphql-codegen/typescript-resolvers": "^4.0.1",
"@types/basic-auth": "^1.1.6",
"@types/bull-arena": "^3.0.10",
"@types/graphql-modules": "^0.58.0",
"@types/jsonwebtoken": "^9.0.5",
"@types/pg": "^8.10.9",
"@types/ramda": "^0.29.9",
"@types/redlock": "^4.0.7",
"@types/semver": "^7.5.6",
"@types/uuid": "^9.0.7",
"@zerollup/ts-transform-paths": "^1.7.18",
"babel-plugin-import-graphql": "^2.8.1",
"babel-plugin-module-resolver": "^5.0.0",
"semver": "^7.5.4"
}
}
2 changes: 1 addition & 1 deletion packages/server/src/internals/error-event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { array as A } from 'fp-ts'
import * as F from 'fp-ts/lib/function'
import R from 'ramda'
import * as R from 'ramda'

import { Sentry } from '~/internals/sentry'

Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/internals/graphql/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DocumentNode } from 'graphql'
import R from 'ramda'
import * as R from 'ramda'
import { A, O } from 'ts-toolbelt'

import { Context } from './context'
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/internals/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
GraphQLRequestContextDidEncounterErrors,
} from '@apollo/server'
import * as Sentry from '@sentry/node'
import R from 'ramda'
import * as R from 'ramda'

import { InvalidValueFromListener } from './data-source'
import { InvalidCurrentValueError } from './data-source-helper'
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/schema/instance/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import R from 'ramda'
import * as R from 'ramda'

import { Instance, InstanceAware } from '~/types'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { array as A, function as F, number as N, ord } from 'fp-ts'
import * as t from 'io-ts'
import R from 'ramda'
import * as R from 'ramda'

import {
Model,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/schema/uuid/course/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import R from 'ramda'
import * as R from 'ramda'

import { TypeResolvers } from '~/internals/graphql'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/schema/uuid/user/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as serloAuth from '@serlo/authorization'
import { instanceToScope, Scope } from '@serlo/authorization'
import { array as A, either as E, function as F, option as O } from 'fp-ts'
import * as t from 'io-ts'
import R from 'ramda'
import * as R from 'ramda'

import { UserInputError } from '~/errors'
import { ModelDataSource } from '~/internals/data-source'
Expand Down
Loading

0 comments on commit f12b8a5

Please sign in to comment.