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

Fix Integration Tests #472

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions .dockerignore
Expand Up @@ -10,3 +10,16 @@ stories
.prettier*
LICENSE
README.md
__mocks__
e2e-test-results
.env.local.sample
dev
tsconfig.tsbuildinfo
.worktrees
.husky
.idea
.gitignore
.prettierrc.json
.vitest
Dockerfile*
docker*
13 changes: 13 additions & 0 deletions .env.local.sample
@@ -1,6 +1,19 @@
BASE_CANONICAL_URL=
API_HOST_CLIENT=
API_HOST_SERVER=
NEXT_PUBLIC_API_HOST_CLIENT=
COOKIE_SECRET=
ADS_SESSION_COOKIE_NAME=
SCIX_SESSION_COOKIE_NAME=
NEXT_PUBLIC_ORCID_CLIENT_ID=
NEXT_PUBLIC_ORCID_API_URL=
NEXT_PUBLIC_ORCID_REDIRECT_URI=
REDIS_HOST=
REDIS_PORT=
REDIS_PASSWORD=
VERIFIED_BOTS_ACCESS_TOKEN=
UNVERIFIABLE_BOTS_ACCESS_TOKEN=
MALICIOUS_BOTS_ACCESS_TOKEN=
NEXT_PUBLIC_GTM_ID=
NEXT_PUBLIC_RECAPTCHA_SITE_KEY=
MAILSLURP_API_TOKEN=
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,11 @@
name: CI
on: [push, pull_request]

jobs:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build and Run Unit Tests
run: ./nectar.sh --unit

102 changes: 51 additions & 51 deletions .github/workflows/pull-request.yml
Expand Up @@ -71,55 +71,55 @@ jobs:
name: codecov-nectar
path_to_write_report: ./coverage/codecov_report.txt
verbose: true

e2e-tests:
timeout-minutes: 60
runs-on: ubuntu-latest
env:
CI: true
BASE_CANONICAL_URL: ${{ vars.BASE_CANONICAL_URL }}
API_HOST_CLIENT: ${{ vars.API_HOST_CLIENT }}
API_HOST_SERVER: ${{ vars.API_HOST_SERVER }}
COOKIE_SECRET: ${{ vars.COOKIE_SECRET }}
strategy:
matrix:
node-version: [ 18 ]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
- uses: actions/cache@v3
name: restore/setup pnpm cache
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Install dependencies
if: steps.pnpm-cache.outputs.cache-hit != 'true'
run: pnpm install

- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps

- name: setup environment variables
run: |
touch .env.local
echo "CI=${{ env.CI }}" >> .env.local
echo "BASE_CANONICAL_URL=${{ env.BASE_CANONICAL_URL }}" >> .env.local
echo "API_HOST_CLIENT=${{ env.API_HOST_CLIENT }}" >> .env.local
echo "API_HOST_SERVER=${{ env.API_HOST_SERVER }}" >> .env.local
echo "COOKIE_SECRET=${{ env.COOKIE_SECRET }}" >> .env.local

- name: Run integration tests
run: pnpm integration

- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
# e2e-tests:
# timeout-minutes: 60
# runs-on: ubuntu-latest
# env:
# CI: true
# BASE_CANONICAL_URL: ${{ vars.BASE_CANONICAL_URL }}
# API_HOST_CLIENT: ${{ vars.API_HOST_CLIENT }}
# API_HOST_SERVER: ${{ vars.API_HOST_SERVER }}
# COOKIE_SECRET: ${{ vars.COOKIE_SECRET }}
# strategy:
# matrix:
# node-version: [ 18 ]
# steps:
# - uses: actions/checkout@v3
# - uses: pnpm/action-setup@v2
# name: Install pnpm
# id: pnpm-install
# with:
# version: 8
# run_install: false
# - uses: actions/cache@v3
# name: restore/setup pnpm cache
# with:
# path: ~/.pnpm-store
# key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
#
# - name: Install dependencies
# if: steps.pnpm-cache.outputs.cache-hit != 'true'
# run: pnpm install
#
# - name: Install Playwright Browsers
# run: pnpm exec playwright install --with-deps
#
# - name: setup environment variables
# run: |
# touch .env.local
# echo "CI=${{ env.CI }}" >> .env.local
# echo "BASE_CANONICAL_URL=${{ env.BASE_CANONICAL_URL }}" >> .env.local
# echo "API_HOST_CLIENT=${{ env.API_HOST_CLIENT }}" >> .env.local
# echo "API_HOST_SERVER=${{ env.API_HOST_SERVER }}" >> .env.local
# echo "COOKIE_SECRET=${{ env.COOKIE_SECRET }}" >> .env.local
#
# - name: Run integration tests
# run: pnpm integration
#
# - uses: actions/upload-artifact@v3
# if: always()
# with:
# name: playwright-report
# path: playwright-report/
# retention-days: 30
16 changes: 7 additions & 9 deletions .gitignore
Expand Up @@ -120,17 +120,15 @@ dist
dev/
storybook-static/
.DS_Store
.idea
.idea/
.env.development
.env.production
/.vitest/
/.vitest-preview/
/test-results/
/playwright-report/
/playwright/.cache/

# Sentry Config File
.sentryclirc
.vitest/
.vitest-preview/
e2e-test-results/
playwright-report/
playwright/.cache/
playwright/.auth/

# Sentry Config File
.sentryclirc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
117 changes: 69 additions & 48 deletions Dockerfile
@@ -1,62 +1,83 @@
FROM node:18-alpine AS base

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

ENV NODE_ENV=production

RUN npm install -g pnpm

# Files required by pnpm install
COPY .npmrc.* package.json pnpm-lock.yaml .pnpmfile.cjs.* ./

# install deps
RUN pnpm add sharp
RUN pnpm install --frozen-lockfile --ignore-scripts --no-optional

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

FROM node:20-bookworm AS base
ARG USER_UID=1001
ARG USER_GID=1001
ARG USERNAME=node
ENV PNPM_HOME=/pnpm
ENV DIST_DIR="dist"
ENV STANDALONE=1
ENV NEXT_TELEMETRY_DISABLED=1
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
ENV STANDALONE=1
ENV DIST_DIR="dist"
ENV NODE_ENV=production
ENV PLAYWRIGHT_BROWSERS_PATH="/app/.browsers"
ENV PATH="$PNPM_HOME:/app/.bin:/app/node_modules/.bin:$PATH"
ENV PORT=8000
ENV SENTRYCLI_SKIP_DOWNLOAD=1
ENV HOSTNAME="0.0.0.0"

# ensure pnpm is available in the builder
RUN corepack enable
RUN pnpm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > \
/etc/apt/apt.conf.d/keep-cache;

ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt update && apt-get --no-install-recommends install -y libc6;

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
WORKDIR /app

COPY --from=builder /app/public ./public
COPY --from=builder /app/.env.local ./
RUN groupmod --gid $USER_GID $USERNAME \
&& usermod --uid $USER_UID --gid $USER_GID $USERNAME \
&& chown -R $USER_UID:$USER_GID /app;

FROM base as dev
COPY --link package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --ignore-scripts --no-optional
USER $USERNAME
COPY --link . ./
ENTRYPOINT ["pnpm", "run", "dev"]

FROM base as unit
USER root
COPY --link package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install vitest
USER $USERNAME
COPY --link vitest-setup.ts vitest.config.js tsconfig.json ./
COPY --link logger /app/logger
COPY --link src /app/src
ENTRYPOINT ["vitest"]

FROM base AS build_prod
RUN mkdir -p ./dist/cache
COPY --link package.json pnpm-lock.yaml ./
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --ignore-scripts --no-optional --prod
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm add sharp
COPY --link . .
RUN --mount=type=cache,id=nextjs,target=./dist/cache pnpm run build

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder /app/dist/standalone ./
COPY --from=builder /app/dist/static ./dist/static
COPY --from=builder --chown=nextjs:nodejs /app/dist/cache ./dist/cache
# Production image, copy all the files and run next
FROM base AS prod
ENV NODE_ENV=production

USER nextjs
USER $USERNAME
COPY --link --from=build_prod /app/dist/standalone ./
COPY --link --from=build_prod /app/node_modules ./node_modules
COPY --link --from=build_prod /app/dist/static ./dist/static
COPY --link --from=build_prod /app/public ./public
COPY --link --from=build_prod --chown="$USERNAME":"$USERNAME" /app/dist/cache ./dist/cache

EXPOSE 8000
ENTRYPOINT ["node", "server.js"]

FROM base as e2e-browsers
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install @playwright/test playwright @faker-js/faker
RUN playwright install --with-deps

ENV PORT 8000
FROM e2e-browsers as e2e
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=0

CMD ["node", "server.js"]
USER $USERNAME
COPY --link src ./src
COPY --link e2e ./e2e
COPY --link playwright.config.ts ./
COPY --link tsconfig.json ./

ENTRYPOINT ["playwright"]
CMD ["test"]