Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"account-scoped": { "development": ["us-east-1"], "staging": ["us-east-1", "eu-west-1"], "production": ["us-east-1", "eu-west-1", "ca-central-1"] },
"e2eTestRunner": { "development": ["us-east-1"], "staging": ["us-east-1", "eu-west-1"], "production": ["us-east-1", "eu-west-1", "ca-central-1"] },
"facebookCallback": { "development": ["us-east-1"], "staging": [], "production": ["us-east-1"] },
"facebookSignin": { "development": ["us-east-1"], "staging": [], "production": ["us-east-1"] },
"instagramWebhook": { "development": ["us-east-1"], "staging": [], "production": ["us-east-1"] },
Expand Down
19 changes: 5 additions & 14 deletions .github/workflows/e2e-lambda-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.

name: 'Deploy E2E Lambda'
name: 'Deploy E2E Lambda [DEPRECATED]'
# DEPRECATED: The e2e lambda is now deployed via the 'Deploy Twilio Lambda' and
# 'Deploy All Twilio Lambdas' workflows using the standard lambda deployment pipeline.
# This workflow is kept for reference only and will be removed in a future cleanup.
on:
workflow_dispatch:
inputs:
environment:
description: Environment to deploy.
default: development
required: true
type: choice
options:
- development
- staging
- production

workflow_call:
secrets:
AWS_ACCESS_KEY_ID:
Expand Down Expand Up @@ -75,7 +66,7 @@ jobs:
uses: docker/build-push-action@v7
with:
context: ./
file: ./e2e-tests/Dockerfile
file: ./lambdas/e2eTestRunner/Dockerfile
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:live,${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
provenance: false
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/twilio-lambda-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
matrix:
lambda_path:
- account-scoped
- e2eTestRunner
- facebookCallback
- facebookSignin
- instagramWebhook
Expand Down Expand Up @@ -122,6 +123,7 @@ jobs:
echo "ref_name_for_docker=${ref_name//\//_-}" >> $GITHUB_ENV
shell: bash
- name: Build and Push Docker Image
if: ${{ matrix.lambda_path != 'e2eTestRunner' }}
uses: docker/build-push-action@v7
with:
context: ./lambdas
Expand All @@ -133,3 +135,13 @@ jobs:
# 'latest' is never used, but it keeps terraform happy
tags: ${{ env.ECR_URL }}:${{ github.ref_type }}.${{ env.ref_name_for_docker }},${{ env.ECR_URL }}:${{ github.sha }},${{ env.ECR_URL }}:latest
provenance: false
- name: Build and Push Docker Image (e2eTestRunner)
if: ${{ matrix.lambda_path == 'e2eTestRunner' }}
uses: docker/build-push-action@v7
with:
context: ./
file: ./lambdas/e2eTestRunner/Dockerfile
push: true
# 'latest' is never used, but it keeps terraform happy
tags: ${{ env.ECR_URL }}:${{ github.ref_type }}.${{ env.ref_name_for_docker }},${{ env.ECR_URL }}:${{ github.sha }},${{ env.ECR_URL }}:latest
provenance: false
1 change: 1 addition & 0 deletions .github/workflows/twilio-lambda-deploy-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
matrix:
lambda_path:
- account-scoped
- e2eTestRunner
- facebookCallback
- facebookSignin
- instagramWebhook
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/twilio-lambda-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ on:
type: choice
options:
- account-scoped
- e2eTestRunner
- facebookCallback
- facebookSignin
- instagramWebhook
Expand Down
112 changes: 112 additions & 0 deletions lambdas/e2eTestRunner/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Copyright (C) 2021-2023 Technology Matters
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.

# We start with a large official playwright base image to build the dependencies.
FROM mcr.microsoft.com/playwright:v1.30.0-jammy AS build

WORKDIR /app

ARG TARGETARCH

RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
apt-get install -y \
nodejs \
autoconf \
g++ \
libtool \
make \
cmake \
unzip \
xz-utils \
ca-certificates \
libcurl4-openssl-dev && \
# aws-lambda-ric provides the scaffolding to run the lambda in a container
npm install aws-lambda-ric -g && \
#aws-lambda-rie provides emulation of the aws runtime interface for local development
if [ "$TARGETARCH" = "arm64" ]; then export REI_FILE="aws-lambda-rie-arm64"; else export REI_FILE="aws-lambda-rie"; fi && \
curl -Lo /usr/local/bin/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/${REI_FILE} && \
chmod +x /usr/local/bin/aws-lambda-rie

# Install e2e-tests dependencies (includes Playwright and all test dependencies)
COPY lambdas/packages/hrm-form-definitions/package*.json /app/hrm-form-definitions/
COPY e2e-tests/package*.json /app/e2e-tests/

RUN cd hrm-form-definitions && \
npm ci && \
cd ../e2e-tests && \
npm ci && \
# We clean the base image browsers and only install the one we need to reduce the final image size
rm -rf /ms-playwright/* && \
npm run postinstall

# Install and build the lambda handler from the lambdas workspace
COPY lambdas/e2eTestRunner/package*.json /app/lambdas/e2eTestRunner/
COPY lambdas/packages /app/lambdas/packages/
COPY lambdas/tsconfig.base.json /app/lambdas/
COPY lambdas/e2eTestRunner/tsconfig.json /app/lambdas/e2eTestRunner/

RUN cd /app/lambdas && npm ci -w e2eTestRunner -w packages/* --verbose

COPY lambdas/e2eTestRunner/src /app/lambdas/e2eTestRunner/src/
COPY lambdas/e2eTestRunner/tsconfig.build.json /app/lambdas/

RUN cd /app/lambdas && npx tsc -b e2eTestRunner/tsconfig.build.json --verbose

# After initial build, we switch to a smaller base image and only copy the necessary files to reduce the final image size.
FROM ubuntu:jammy

WORKDIR /app

RUN apt-get update && \
apt-get install -y curl wget gpg && \
curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
apt-get install -y nodejs && \
# move npm cache to /tmp for use in lambda
npm config set cache /tmp --global && \
rm -rf /root/.npm/* && \
apt-get install -y --no-install-recommends git openssh-client && \
npm install -g yarn && \
# clean apt cache
rm -rf /var/lib/apt/lists/*

COPY --from=build /usr/local/bin/aws-lambda-rie /usr/local/bin/aws-lambda-rie
COPY --from=build /usr/bin /usr/bin
COPY --from=build /usr/lib/node_modules /usr/lib/node_modules
COPY --from=build /app/hrm-form-definitions /app/hrm-form-definitions
COPY --from=build /app/e2e-tests /app/e2e-tests
COPY --from=build /ms-playwright /ms-playwright

WORKDIR /app/e2e-tests

RUN npx playwright install-deps

COPY lambdas/packages/hrm-form-definitions /app/hrm-form-definitions
COPY e2e-tests /app/e2e-tests

# Copy the compiled lambda handler and its dependencies
COPY --from=build /app/lambdas/e2eTestRunner/dist /app/e2eTestRunner
COPY --from=build /app/lambdas/node_modules /app/e2eTestRunner/node_modules

COPY --chmod=0755 lambdas/e2eTestRunner/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh

# AWS Lambda always sets LAMBDA_TASK_ROOT=/var/task at runtime, overriding any Dockerfile ENV.
# Symlinking /var/task -> /app/e2eTestRunner ensures aws-lambda-ric finds index.js at the expected path.
RUN ln -sf /app/e2eTestRunner /var/task

ENV TEST_IN_LAMBDA=true
ENV XDG_CONFIG_HOME=/tmp/.config
ENV PLAYWRIGHT_BROWSERS_PATH=/tmp

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["index.handler"]
36 changes: 36 additions & 0 deletions lambdas/e2eTestRunner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# E2E Test Runner Lambda

This lambda runs the Playwright E2E tests defined in `/e2e-tests` via an AWS Lambda function.

## Overview

The handler spawns `npm run test` (or a custom npm script) in the `/app/e2e-tests` directory
inside the container, then uploads the test artifacts (screenshots, videos, junit results) to S3.

## Event Parameters

| Parameter | Type | Required | Description |
|-------------|--------|----------|----------------------------------------------------------------|
| `testName` | string | No | Name of a specific test to run (sets `TEST_NAME` env var) |
| `npmScript` | string | No | npm script to run (defaults to `test`) |

## Docker

The lambda uses a custom Dockerfile (`Dockerfile`) that is based on the Microsoft Playwright
base image in order to include the Playwright browser dependencies. The E2E test code from
`/e2e-tests` is pulled into the container at build time.

To build the Docker image locally from the repository root:

```bash
cd lambdas/e2eTestRunner
npm run docker:build
```

## Environment Variables

The following environment variables are set in the container:

- `TEST_IN_LAMBDA=true` — indicates the tests are running inside a Lambda
- `XDG_CONFIG_HOME=/tmp/.config` — redirects browser config to writable `/tmp`
- `PLAYWRIGHT_BROWSERS_PATH=/tmp` — redirects Playwright browser binaries to writable `/tmp`
27 changes: 27 additions & 0 deletions lambdas/e2eTestRunner/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env sh
# Copyright (C) 2021-2023 Technology Matters
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.

# Nothing is writable on a lambda except /tmp. We need to copy the browser there and set it as our home directory
# so that chromium can write to it.
cp -r /ms-playwright/* /tmp/

# Some chromium startup writes to ~/some/directory. We need to set the home directory to /tmp so that it can write
export HOME=/tmp

if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
exec /usr/local/bin/aws-lambda-rie /usr/bin/aws-lambda-ric $@
else
exec /usr/bin/aws-lambda-ric $@
fi
23 changes: 23 additions & 0 deletions lambdas/e2eTestRunner/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@tech-matters/e2e-test-runner",
"version": "1.0.0",
"description": "Lambda for running Playwright E2E tests",
"main": "index.js",
"scripts": {
"docker:build": "docker build -t e2etestrunner -f Dockerfile ../../../"
},
"author": "Tech Matters",
"license": "AGPL",
"devDependencies": {
"@tsconfig/node22": "^22.0.0",
"@types/aws-lambda": "^8.10.108",
"@types/node": "^22.18.0",
"ts-node": "^10.9.1",
"typescript": "^5.8.2"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.993.0",
"@aws-sdk/client-ssm": "^3.993.0",
"date-fns": "^2.28.0"
}
}
Loading
Loading