From d61d16e7520c080e20b381384d6777dceff7fcbd Mon Sep 17 00:00:00 2001 From: Rainer Killinger Date: Wed, 14 Jun 2023 16:04:44 +0200 Subject: [PATCH] ci: include backend integration tests --- .gitlab-ci.yml | 11 +++++++++-- Dockerfile | 12 +++--------- backend/backend/.gitlab-ci.yml | 15 +++++++++++++++ backend/backend/Dockerfile | 6 +----- backend/backend/integration-test.yml | 6 +++--- backend/backend/package.json | 4 ++-- backend/backend/turbo.json | 2 +- packages/api-cli/Dockerfile | 8 ++------ 8 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 backend/backend/.gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7e74d578..791badb0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,5 @@ +include: '/backend/backend/.gitlab-ci.yml' + default: image: registry.gitlab.com/openstapps/projectmanagement/builder:v18 tags: @@ -7,12 +9,14 @@ default: - echo TURBO_TOKEN=$TURBO_TOKEN >> .env.local - echo TURBO_TEAM=$TURBO_TEAM >> .env.local - pnpm config set store-dir .pnpm-store - cache: + cache: &pnpm_cache key: files: - pnpm-lock.yaml paths: - - .pnpm-store + - .pnpm-store/ + - node-modules/ + policy: pull stages: - build @@ -29,6 +33,9 @@ build: artifacts: paths: - www + cache: + <<: *pnpm_cache + policy: pull-push # rules: # - if: $CI_COMMIT_BRANCH == "develop" # when: never diff --git a/Dockerfile b/Dockerfile index 8ac3c448..6335660c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,16 +3,10 @@ FROM registry.gitlab.com/openstapps/projectmanagement/node:v18 as workspace USER root RUN apk add --update python3 py3-pip make g++ gcompat -WORKDIR app/ -COPY pnpm-lock.yaml \ - package.json \ - pnpm-workspace.yaml ./ +WORKDIR /build +COPY pnpm-lock.yaml ./ RUN pnpm fetch --prod -COPY backend/ backend/ -COPY configuration/ configuration/ -COPY examples/ examples/ -COPY frontend/ frontend/ -COPY packages/ packages/ +ADD . ./ RUN pnpm install -r --offline --prod diff --git a/backend/backend/.gitlab-ci.yml b/backend/backend/.gitlab-ci.yml new file mode 100644 index 00000000..017bfe99 --- /dev/null +++ b/backend/backend/.gitlab-ci.yml @@ -0,0 +1,15 @@ +integration:backend: + image: registry.gitlab.com/openstapps/projectmanagement/builder:v18 + stage: test + dependencies: + - build + variables: + DOCKER_DRIVER: overlay2 + services: + - docker:dind + script: + - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY + - pnpm install --offline + - pnpm test:integration + tags: + - secrecy diff --git a/backend/backend/Dockerfile b/backend/backend/Dockerfile index 661bba42..cfda96a2 100644 --- a/backend/backend/Dockerfile +++ b/backend/backend/Dockerfile @@ -1,12 +1,8 @@ -FROM openstapps:workspace as pruned - -USER root -RUN pnpm --filter @openstapps/backend --prod deploy /pruned - FROM registry.gitlab.com/openstapps/projectmanagement/node:v18 USER node ENV NODE_ENV=production +WORKDIR /app COPY --chown=node:node --from=pruned pruned . diff --git a/backend/backend/integration-test.yml b/backend/backend/integration-test.yml index 594ad99d..240ae620 100644 --- a/backend/backend/integration-test.yml +++ b/backend/backend/integration-test.yml @@ -1,7 +1,7 @@ version: '3' services: backend: - image: openstapps:backend + build: . ports: - '3000:3000' environment: @@ -13,12 +13,12 @@ services: ES_ADDR: 'http://elasticsearch:9200' elasticsearch: - image: openstapps:database + build: ../database ports: - '9200:9200' api-cli: - image: openstapps:api-cli + build: ../../packages/api-cli environment: STAPPS_LOG_LEVEL: '31' STAPPS_EXIT_LEVEL: '8' diff --git a/backend/backend/package.json b/backend/backend/package.json index 4754357c..f2395320 100644 --- a/backend/backend/package.json +++ b/backend/backend/package.json @@ -26,16 +26,16 @@ ], "scripts": { "build": "tsup-node", - "build:docker": "docker build -t openstapps:backend .", "dev": "tsup --watch --onSuccess \"pnpm run start\"", "format": "prettier . -c --ignore-path ../../.gitignore", "format:fix": "prettier --write . --ignore-path ../../.gitignore", "lint": "tsc --noEmit && eslint --ext .ts src/", "lint:fix": "eslint --fix --ext .ts src/", + "prune:integration": "pnpm --filter=backend --prod deploy pruned && pnpm --filter=api-cli --prod deploy ../../packages/api-cli/pruned", "start": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true node app.js", "start:debug": "cross-env STAPPS_LOG_LEVEL=31 NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true node app.js", "test": "pnpm run test:unit", - "test:integration": "docker-compose -f integration-test.yml up --abort-on-container-exit --exit-code-from api-cli", + "test:integration": "pnpm prune:integration && docker-compose -f integration-test.yml up --abort-on-container-exit --exit-code-from api-cli", "test:unit": "cross-env NODE_CONFIG_ENV=elasticsearch ALLOW_NO_TRANSPORT=true STAPPS_LOG_LEVEL=0 mocha --exit" }, "dependencies": { diff --git a/backend/backend/turbo.json b/backend/backend/turbo.json index 6c91b508..9705a8e4 100644 --- a/backend/backend/turbo.json +++ b/backend/backend/turbo.json @@ -1,7 +1,7 @@ { "extends": ["//"], "pipeline": { - "test:integration": { + "TODO:test:integration": { "dependsOn": [ "@openstapps/database#build:docker", "@openstapps/backend#build:docker", diff --git a/packages/api-cli/Dockerfile b/packages/api-cli/Dockerfile index b1a36523..7ae85f02 100644 --- a/packages/api-cli/Dockerfile +++ b/packages/api-cli/Dockerfile @@ -1,14 +1,10 @@ -FROM openstapps:workspace as pruned - -USER root -RUN pnpm --filter @openstapps/api-cli --prod deploy /pruned - FROM registry.gitlab.com/openstapps/projectmanagement/node:v18 USER node ENV NODE_ENV=production +WORKDIR /app -COPY --chown=node:node --from=pruned pruned . +COPY --chown=node:node pruned . ENTRYPOINT ["node", "app.js"] CMD ["--help"]