Skip to content

Commit

Permalink
CI test
Browse files Browse the repository at this point in the history
  • Loading branch information
Svana committed Dec 12, 2024
1 parent ad64565 commit 743692e
Show file tree
Hide file tree
Showing 20 changed files with 887 additions and 104 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
**/*.log
**/tmp/
**/temp/
**/.next/

# Outputs
**/dist/
Expand Down
63 changes: 58 additions & 5 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ jobs:

outputs:
TEST_CHUNKS: ${{ steps.test_projects.outputs.CHUNKS }}
E2E_CI_CHUNKS: ${{ steps.e2e_ci_projects.outputs.CHUNKS }}
E2E_CHUNKS: ${{ steps.e2e_projects.outputs.CHUNKS }}
E2E_CI_BUILD_ID: ${{ steps.e2e_ci_projects.outputs.BUILD_ID }}
E2E_BUILD_ID: ${{ steps.e2e_projects.outputs.BUILD_ID }}
LINT_CHUNKS: ${{ steps.lint_projects.outputs.CHUNKS }}
BUILD_CHUNKS: ${{ steps.build_projects.outputs.CHUNKS }}
Expand Down Expand Up @@ -141,13 +143,25 @@ jobs:
echo "CHUNKS={\"projects\":$CHUNKS}" >> "$GITHUB_OUTPUT"
fi
- name: Prepare e2e-ci targets
id: e2e_ci_projects
env:
CHUNK_SIZE: 1
run: |
set -euo pipefail
CHUNKS="$(./scripts/ci/generate-chunks.sh e2e-ci)"
if [[ "$CHUNKS" != "[]" ]]; then
echo "CHUNKS={\"projects\":$CHUNKS}" >> "$GITHUB_OUTPUT"
fi
echo BUILD_ID="$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER-$(uuidgen)" >> "$GITHUB_OUTPUT"
- name: Prepare e2e targets
id: e2e_projects
env:
CHUNK_SIZE: 1
run: |
set -euo pipefail
CHUNKS="$(./scripts/ci/generate-chunks.sh e2e-ci)"
CHUNKS="$(./scripts/ci/generate-chunks.sh e2e)"
if [[ "$CHUNKS" != "[]" ]]; then
echo "CHUNKS={\"projects\":$CHUNKS}" >> "$GITHUB_OUTPUT"
fi
Expand Down Expand Up @@ -213,10 +227,10 @@ jobs:
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
docker-registry: 821090935708.dkr.ecr.eu-west-1.amazonaws.com/

e2e:
e2e-ci:
needs:
- prepare
if: needs.prepare.outputs.E2E_CHUNKS
if: needs.prepare.outputs.E2E_CI_CHUNKS
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
Expand All @@ -227,10 +241,10 @@ jobs:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
API_MOCKS: 'true'
NODE_OPTIONS: --max-old-space-size=4096
E2E_BUILD_ID: '${{ needs.prepare.outputs.E2E_BUILD_ID }}-${{ github.run_attempt }}'
E2E_CI_BUILD_ID: '${{ needs.prepare.outputs.E2E_CI_BUILD_ID }}-${{ github.run_attempt }}'
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare.outputs.E2E_CHUNKS) }}
matrix: ${{ fromJson(needs.prepare.outputs.E2E_CI_CHUNKS) }}
steps:
- uses: actions/checkout@v4

Expand All @@ -252,6 +266,42 @@ jobs:
- name: Running e2e tests
run: ./scripts/ci/40_e2e.sh "${AFFECTED_PROJECT}"

e2e:
needs:
- prepare
if: needs.prepare.outputs.E2E_CHUNKS
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
timeout-minutes: 35
env:
AFFECTED_PROJECT: ${{ matrix.projects }}
NODE_OPTIONS: --max-old-space-size=4096
E2E_BUILD_ID: '${{ needs.prepare.outputs.E2E_BUILD_ID }}-${{ github.run_attempt }}'
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare.outputs.E2E_CHUNKS) }}
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version-file: 'package.json'

- name: Setup yarn
run: corepack enable

- name: Get cache
id: get-cache
uses: ./.github/actions/get-cache
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
keys: ${{ needs.prepare.outputs.CACHE_KEYS }}
enable-cache: 'node_modules,generated-files'

- name: Running e2e tests
run: yarn e2e "${AFFECTED_PROJECT}"

linting-workspace:
needs:
- prepare
Expand Down Expand Up @@ -410,12 +460,15 @@ jobs:
- run-shellcheck
- formatting
- e2e
- e2e-ci
- build
steps:
- name: Check prepare success
run: '[[ ${{ needs.prepare.result }} == "success" ]] || exit 1'
- name: Check tests success
run: '[[ ${{ needs.tests.result }} != "failure" ]] || exit 1'
- name: Check e2e-ci success
run: '[[ ${{ needs.e2e-ci.result }} != "failure" ]] || exit 1'
- name: Check e2e success
run: '[[ ${{ needs.e2e.result }} != "failure" ]] || exit 1'
- name: Check linting success
Expand Down
87 changes: 87 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
ARG NODE_IMAGE_TAG=20.15.0-alpine3.20

# Stage 1: Install dependencies
FROM node:${NODE_IMAGE_TAG} AS dependencies

# Set working directory
WORKDIR /app

# Install Python3 and build tools
RUN apk add --no-cache python3 py3-pip make g++ && ln -sf /usr/bin/python3 /usr/bin/python

# Copy only package management files
COPY package.json yarn.lock ./
COPY .yarn/ .yarn
COPY .yarnrc.yml .yarnrc.yml
COPY ./apps/native/app/package.json ./apps/native/app/package.json

# Install dependencies
RUN --mount=type=cache,target=/app/.yarn/cache \
yarn install --immutable && yarn cache clean

# Stage 2: Final runtime image
FROM node:${NODE_IMAGE_TAG}

# Install Python (runtime requirement if needed)
RUN apk add --no-cache python3 py3-pip && ln -sf /usr/bin/python3 /usr/bin/python

# Enable Corepack and Yarn 3.2.3
RUN corepack enable && corepack prepare yarn@3.2.3 --activate

# Set working directory
WORKDIR /app

# Copy from dependencies stage
COPY --from=dependencies /app/node_modules ./node_modules
COPY --from=dependencies /app/yarn.lock ./yarn.lock
COPY --from=dependencies /app/.yarn/ ./.yarn
COPY --from=dependencies /app/.yarnrc.yml ./.yarnrc.yml

# Copy source code and necessary configuration files
COPY ./apps ./apps
COPY ./libs ./libs
COPY ./infra ./infra
COPY ./tools ./tools
COPY ./tsconfig.base.json ./
COPY ./tsconfig.shared.json ./
COPY ./package.json ./

# Verify Yarn version in runtime container
RUN yarn --version

# Default command to run the app
CMD ["yarn", "nx", "serve"]

# ARG NODE_IMAGE_TAG=20.15.0-alpine3.20
# FROM node:${NODE_IMAGE_TAG} AS build

# WORKDIR /app

# # Install build dependencies
# RUN apk add --no-cache \
# python3 \
# py3-pip \
# make \
# g++

# # Set Python symlink
# RUN ln -sf /usr/bin/python3 /usr/bin/python

# # Install dependencies
# COPY package.json yarn.lock ./
# COPY .yarn/ .yarn
# COPY .yarnrc.yml .yarnrc.yml
# COPY ./apps/native/app/package.json ./apps/native/app/package.json

# # Run yarn install
# RUN --mount=type=cache,target=/app/.yarn/cache \
# yarn install --immutable

# # Copy source code
# COPY . .

# # Verify installation
# RUN yarn nx --version

# # Set default entrypoint
# CMD ["yarn", "nx"]
17 changes: 17 additions & 0 deletions apps/consultation-portal/e2e/setup-local-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { logger } from '@island.is/logging'
import { setupE2EEnvironment } from '@island.is/testing/e2e'

const initializeLocalEnvironment = () => {
logger.info('initializeLocalEnvironment is being called')
try {
setupE2EEnvironment({ app: 'consultation-portal' })
} catch (error) {
logger.error('Error while setting up environment: ', error)
throw error
}
}

export default initializeLocalEnvironment

// Add this line to invoke the function
initializeLocalEnvironment()
14 changes: 12 additions & 2 deletions apps/consultation-portal/infra/samradsgatt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,24 @@ export const serviceSetup = (services: {
.env({
BASEPATH: '/consultation-portal',
ENVIRONMENT: ref((h) => h.env.type),
API_URL: ref((h) => `http://${h.svc(services.api)}`),
API_URL: {
local: ref((h) => {
const url = `http://${h.svc(services.api)}`
const port = new URL(url).port
console.log(`http://api:${port}`)
return `http://api:${port}`
}),
dev: ref((h) => `http://${h.svc(services.api)}`),
staging: ref((h) => `http://${h.svc(services.api)}`),
prod: ref((h) => `http://${h.svc(services.api)}`),
},
IDENTITY_SERVER_ISSUER_DOMAIN: {
dev: 'identity-server.dev01.devland.is',
staging: 'identity-server.staging01.devland.is',
prod: 'innskra.island.is',
},
NEXTAUTH_URL: {
local: 'http://localhost:4200/samradsgatt/api/auth',
local: 'http://api:4200/samradsgatt/api/auth',
dev: 'https://beta.dev01.devland.is/samradsgatt/api/auth',
staging: 'https://beta.staging01.devland.is/samradsgatt/api/auth',
prod: 'https://island.is/samradsgatt/api/auth',
Expand Down
4 changes: 1 addition & 3 deletions apps/consultation-portal/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { createPlaywrightConfig } from '@island.is/testing/e2e'

const consultationPortalConfig = createPlaywrightConfig({
webServerUrl: 'http://localhost:4200/',
app: 'consultation-portal',
dependencies: ['api'],
webServerUrl: 'http://localhost:4200/samradsgatt',
})

export default consultationPortalConfig
18 changes: 17 additions & 1 deletion apps/consultation-portal/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,28 @@
"jestConfig": "apps/consultation-portal/jest.config.ts"
}
},
"e2e": {
"setup-env": {
"executor": "nx:run-commands",
"options": {
"command": "yarn ts-node -P apps/consultation-portal/tsconfig.json apps/consultation-portal/e2e/setup-local-env.ts"
}
},
"run-e2e-tests": {
"executor": "@nx/playwright:playwright",
"options": {
"config": "{projectRoot}/playwright.config.ts"
}
},
"e2e": {
"executor": "nx:run-commands",
"options": {
"commands": [
{ "command": "nx run consultation-portal:setup-env" },
{ "command": "nx run consultation-portal:run-e2e-tests" }
],
"parallel": false
}
},
"lint": {
"executor": "@nx/eslint:lint"
},
Expand Down
Loading

0 comments on commit 743692e

Please sign in to comment.