Skip to content

Commit

Permalink
Refactor e2e to increase speed and reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
zdeveloper committed Jul 5, 2023
1 parent 6651a4e commit 8881dfc
Show file tree
Hide file tree
Showing 123 changed files with 504 additions and 337 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#Ignore the following directories
backend/build/
backend/.gradle/
frontend/build/
frontend/node_modules/
nginx/
ops/
docs/
.github/
.run/
node_modules/
wiremock/
cypress/node_modules/
cypress/screenshots/
cypress/videos/
3 changes: 2 additions & 1 deletion .github/workflows/buildBackendImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: backend
context: ./
file: ./backend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/buildFrontendImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,19 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: frontend
context: ./
file: ./frontend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
"REACT_APP_OKTA_URL=http://wiremock:8088"
"REACT_APP_OKTA_CLIENT_ID=0oa1k0163nAwfVxNW1d7"
"REACT_APP_BASE_URL=https://localhost.simplereport.gov"
"REACT_APP_BACKEND_URL=https://localhost.simplereport.gov/api"
"PUBLIC_URL=/app/"
"REACT_APP_OKTA_ENABLED=true"
"REACT_APP_DISABLE_MAINTENANCE_BANNER=true"
- name: Set version output
shell: bash
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/buildFrontendLighthouseImage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Build frontend docker image with okta disabled

on:
workflow_dispatch:
workflow_call:
inputs:
force_build:
description: Force build
required: false
default: false
type: boolean
outputs:
version:
description: docker image version
value: ${{ jobs.build_and_push_frontend_image.outputs.version }}

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/frontend-lighthouse

jobs:

frontend_changes:
with:
what_to_check: frontend
uses: ./.github/workflows/checkForChanges.yml

build_and_push_frontend_image:
# We want to build the image if there are changes in the frontend folder, or if we are forcing a build, or if we are on the main branch
if: needs.frontend_changes.outputs.has_changes == 'true' || inputs.force_build == true || github.ref == 'refs/heads/main'
needs: [frontend_changes]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
version: ${{ steps.set.outputs.version }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=ref,event=branch
type=ref,event=pr
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./
file: ./frontend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
"REACT_APP_BASE_URL=https://localhost.simplereport.gov"
"REACT_APP_BACKEND_URL=https://localhost.simplereport.gov/api"
"PUBLIC_URL=/app/"
"REACT_APP_OKTA_ENABLED=false"
"REACT_APP_DISABLE_MAINTENANCE_BANNER=true"
- name: Set version output
shell: bash
id: set
run: echo "version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" >> "$GITHUB_OUTPUT"
71 changes: 71 additions & 0 deletions .github/workflows/buildWiremockImage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Build wiremock docker image

on:
workflow_dispatch:
workflow_call:
inputs:
force_build:
description: Force build
required: false
default: false
type: boolean
outputs:
version:
description: docker image version
value: ${{ jobs.build_and_push_wiremock_image.outputs.version }}

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/wiremock

jobs:

wiremock_changes:
with:
what_to_check: wiremock
uses: ./.github/workflows/checkForChanges.yml

build_and_push_wiremock_image:
# We want to build the image if there are changes in the wiremock folder, or if we are forcing a build, or if we are on the main branch
if: needs.wiremock_changes.outputs.has_changes == 'true' || inputs.force_build == true || github.ref == 'refs/heads/main'
needs: [wiremock_changes]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
version: ${{ steps.set.outputs.version }}

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=ref,event=branch
type=ref,event=pr
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: wiremock
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Set version output
shell: bash
id: set
run: echo "version=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}" >> "$GITHUB_OUTPUT"
2 changes: 1 addition & 1 deletion .github/workflows/checkForChanges.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
value: ${{ jobs.check_for_changes.outputs.has_changes }}
jobs:
check_for_changes:
runs-on: 'ubuntu-20.04'
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.check_for_changes.outputs.has_changes }}
steps:
Expand Down
38 changes: 12 additions & 26 deletions .github/workflows/e2eLocal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ on:
DOCKER_NGINX_IMAGE_VERSION:
required: false
type: string
DOCKER_WIREMOCK_IMAGE_VERSION:
required: false
type: string

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-e2e-local
Expand All @@ -50,22 +53,6 @@ jobs:
with:
swap-size-gb: 10

- name: Generate certs
run: |
echo "::group::Generate ssl certs"
sudo apt update
sudo apt install libnss3-tools
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew install mkcert
mkcert -install
mkdir -p certs
cd certs
mkcert localhost.simplereport.gov
mv localhost.simplereport.gov.pem localhost.simplereport.gov.crt
mv localhost.simplereport.gov-key.pem localhost.simplereport.gov.key
cd ..
echo "::endgroup::"
- name: Update files permissions
# Even though we don't use it, we need the .env file created here due to an issue similar to this one: https://github.com/mutagen-io/mutagen/issues/265
run: |
Expand Down Expand Up @@ -94,6 +81,7 @@ jobs:
DOCKER_DATABASE_IMAGE_VERSION: ${{ inputs.DOCKER_DATABASE_IMAGE_VERSION }}
DOCKER_FRONTEND_IMAGE_VERSION: ${{ inputs.DOCKER_FRONTEND_IMAGE_VERSION }}
DOCKER_NGINX_IMAGE_VERSION: ${{ inputs.DOCKER_NGINX_IMAGE_VERSION }}
DOCKER_WIREMOCK_IMAGE_VERSION: ${{ inputs.DOCKER_WIREMOCK_IMAGE_VERSION }}
COMPOSE_HTTP_TIMEOUT: 180
# backend settings
SPRING_PROFILES_ACTIVE: e2e,db-dockerized
Expand All @@ -104,16 +92,17 @@ jobs:
SMARTY_AUTH_TOKEN: ${{ secrets.SMARTY_AUTH_TOKEN }}
SPRING_LIQUIBASE_ENABLED: "true"
GIT_DISCOVERY_ACROSS_FILESYSTEM: 1
WIREMOCK_URL: "http://wiremock:8088"
# cypress settings
CYPRESS_OKTA_REDIRECT_URI: "https%3A%2F%2Flocalhost.simplereport.gov%2Fapp"
CYPRESS_OKTA_USERNAME: ${{ secrets.CYPRESS_OKTA_USERNAME }}
CYPRESS_OKTA_PASSWORD: ${{ secrets.CYPRESS_OKTA_PASSWORD }}
CYPRESS_OKTA_SECRET: ${{ secrets.CYPRESS_OKTA_SECRET }}
CYPRESS_BACKEND_URL: "https://localhost.simplereport.gov/api"
WIREMOCK_URL: "http://cypress:8088"
SPEC_PATH: "cypress/e2e/**"
TEST_ENV: "https://localhost.simplereport.gov"
# frontend settings
REACT_APP_OKTA_URL: "http://cypress:8088"
REACT_APP_OKTA_URL: "http://wiremock:8088"
REACT_APP_OKTA_CLIENT_ID: 0oa1k0163nAwfVxNW1d7
REACT_APP_BASE_URL: https://localhost.simplereport.gov
REACT_APP_BACKEND_URL: https://localhost.simplereport.gov/api
Expand All @@ -128,19 +117,16 @@ jobs:
echo "Database branch tag (or latest): ${{ inputs.DOCKER_DATABASE_IMAGE_VERSION }}"
echo "Frontend branch tag (or latest): ${{ inputs.DOCKER_FRONTEND_IMAGE_VERSION }}"
echo "Nginx branch tag (or latest): ${{ inputs.DOCKER_NGINX_IMAGE_VERSION }}"
echo "Wiremock branch tag (or latest): ${{ inputs.DOCKER_WIREMOCK_IMAGE_VERSION }}"
docker compose -f docker-compose.yml -f docker-compose.cypress.yml up --abort-on-container-exit --attach cypress --exit-code-from cypress --quiet-pull
echo "::endgroup::"
- name: Get docker logs
if: always()
shell: bash
run: |
CONTAINERS=$(docker ps -a --format '{{.Names}}')
for container in $CONTAINERS
do
echo "Saving $container logs"
docker logs $container >& cypress/${container}.log
done
echo "Saving $container logs"
docker compose -f docker-compose.yml -f docker-compose.cypress.yml logs --timestamps >& cypress-run.log
- name: Stop containers
if: always()
Expand All @@ -151,7 +137,7 @@ jobs:
echo "::endgroup::"
- name: Archive cypress failures
if: failure()
if: always()
uses: actions/upload-artifact@v3
with:
name: cypress-results
Expand All @@ -164,4 +150,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: logs
path: cypress/*.log
path: cypress-run.log
55 changes: 32 additions & 23 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
name: "Run Lighthouse Audit"
name: Run Lighthouse Audit
on:
workflow_dispatch:
pull_request:
branches:
- "**"
workflow_call:
inputs:
DOCKER_BACKEND_IMAGE_VERSION:
required: false
type: string
DOCKER_DATABASE_IMAGE_VERSION:
required: false
type: string
DOCKER_NGINX_IMAGE_VERSION:
required: false
type: string
DOCKER_WIREMOCK_IMAGE_VERSION:
required: false
type: string
DOCKER_FRONTEND_LIGHTHOUSE_IMAGE_VERSION:
required: false
type: string

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -23,22 +36,6 @@ jobs:
with:
swap-size-gb: 10

- name: Generate certs
run: |
echo "::group::Generate ssl certs"
sudo apt update
sudo apt install libnss3-tools
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew install mkcert
mkcert -install
mkdir -p certs
cd certs
mkcert localhost.simplereport.gov
mv localhost.simplereport.gov.pem localhost.simplereport.gov.crt
mv localhost.simplereport.gov-key.pem localhost.simplereport.gov.key
cd ..
echo "::endgroup::"
- name: Add hosts to /etc/hosts
run: |
sudo echo "127.0.0.1 localhost.simplereport.gov" | sudo tee -a /etc/hosts
Expand Down Expand Up @@ -66,11 +63,23 @@ jobs:
# docker settings
DOCKER_CLIENT_TIMEOUT: 180
COMPOSE_HTTP_TIMEOUT: 180
DOCKER_BACKEND_IMAGE_VERSION: ${{ inputs.DOCKER_BACKEND_IMAGE_VERSION }}
DOCKER_DATABASE_IMAGE_VERSION: ${{ inputs.DOCKER_DATABASE_IMAGE_VERSION }}
DOCKER_NGINX_IMAGE_VERSION: ${{ inputs.DOCKER_NGINX_IMAGE_VERSION }}
DOCKER_WIREMOCK_IMAGE_VERSION: ${{ inputs.DOCKER_WIREMOCK_IMAGE_VERSION }}
DOCKER_FRONTEND_LIGHTHOUSE_IMAGE_VERSION: ${{ inputs.DOCKER_FRONTEND_LIGHTHOUSE_IMAGE_VERSION }}
shell: bash
run: |
echo "::group::Running containers"
echo "Backend branch tag (or latest): ${{ inputs.DOCKER_BACKEND_IMAGE_VERSION }}"
echo "Database branch tag (or latest): ${{ inputs.DOCKER_DATABASE_IMAGE_VERSION }}"
echo "Nginx branch tag (or latest): ${{ inputs.DOCKER_NGINX_IMAGE_VERSION }}"
echo "Wiremock branch tag (or latest): ${{ inputs.DOCKER_WIREMOCK_IMAGE_VERSION }}"
echo "Frontend branch tag (or latest): ${{ inputs.DOCKER_FRONTEND_LIGHTHOUSE_IMAGE_VERSION }}"
echo "::endgroup::"
echo "::group::Run Lighthouse locally"
npm install -g @lhci/cli@0.9.x
lhci autorun
bash lighthouse.sh
echo "::endgroup::"
- name: Archive Lighthouse results
Expand Down
Loading

0 comments on commit 8881dfc

Please sign in to comment.