diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..29e8410a25 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +#Ignore the following directories +backend/build/ +backend/.gradle/ +frontend/build/ +frontend/node_modules/ +nginx/ +ops/**/.terraform/ +ops/services/app_functions/report_stream_batched_publisher/functions/node_modules/ +docs/ +.github/ +.run/ +node_modules/ +cypress/node_modules/ +cypress/screenshots/ +cypress/videos/ \ No newline at end of file diff --git a/.env.cypress.sample b/.env.cypress.sample index 96491aa828..395a1aad04 100644 --- a/.env.cypress.sample +++ b/.env.cypress.sample @@ -4,7 +4,7 @@ COMPOSE_HTTP_TIMEOUT=180 # Backend settings SPRING_PROFILES_ACTIVE=e2e,db-dockerized -WIREMOCK_URL=http://cypress:8088 +WIREMOCK_URL=http://wiremock:8088 SPRING_LIQUIBASE_ENABLED="true" OKTA_TESTING_DISABLEHTTPSCHECK="true" @@ -28,7 +28,7 @@ REACT_APP_BACKEND_URL=https://localhost.simplereport.gov/api PUBLIC_URL=/app/ REACT_APP_OKTA_ENABLED=true REACT_APP_DISABLE_MAINTENANCE_BANNER=true -REACT_APP_OKTA_URL=http://cypress:8088 +REACT_APP_OKTA_URL=http://wiremock:8088 REACT_APP_BASE_URL=https://localhost.simplereport.gov REACT_APP_OKTA_CLIENT_ID= diff --git a/.github/workflows/buildBackendImage.yml b/.github/workflows/buildBackendImage.yml index 02ebf4489b..39e1bc4176 100644 --- a/.github/workflows/buildBackendImage.yml +++ b/.github/workflows/buildBackendImage.yml @@ -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 }} diff --git a/.github/workflows/buildFrontendImage.yml b/.github/workflows/buildFrontendImage.yml index 4742706d63..e73751162d 100644 --- a/.github/workflows/buildFrontendImage.yml +++ b/.github/workflows/buildFrontendImage.yml @@ -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 diff --git a/.github/workflows/buildFrontendLighthouseImage.yml b/.github/workflows/buildFrontendLighthouseImage.yml new file mode 100644 index 0000000000..c111b60b1f --- /dev/null +++ b/.github/workflows/buildFrontendLighthouseImage.yml @@ -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" diff --git a/.github/workflows/checkForChanges.yml b/.github/workflows/checkForChanges.yml index 54a493a202..f56cdff91d 100644 --- a/.github/workflows/checkForChanges.yml +++ b/.github/workflows/checkForChanges.yml @@ -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: diff --git a/.github/workflows/e2eLocal.yml b/.github/workflows/e2eLocal.yml index 53da666f9d..a2521ae1d7 100644 --- a/.github/workflows/e2eLocal.yml +++ b/.github/workflows/e2eLocal.yml @@ -50,22 +50,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: | @@ -104,16 +88,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 @@ -135,12 +120,8 @@ jobs: 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() @@ -151,7 +132,7 @@ jobs: echo "::endgroup::" - name: Archive cypress failures - if: failure() + if: always() uses: actions/upload-artifact@v3 with: name: cypress-results @@ -164,4 +145,4 @@ jobs: uses: actions/upload-artifact@v3 with: name: logs - path: cypress/*.log + path: cypress-run.log diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 11d6c8ce94..5c8bd23db8 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -1,9 +1,19 @@ -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_FRONTEND_LIGHTHOUSE_IMAGE_VERSION: + required: false + type: string concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -23,22 +33,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 @@ -66,11 +60,21 @@ 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_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 "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 diff --git a/.github/workflows/testingWorkflow.yml b/.github/workflows/testingWorkflow.yml index 4c757f079d..8f376da504 100644 --- a/.github/workflows/testingWorkflow.yml +++ b/.github/workflows/testingWorkflow.yml @@ -23,6 +23,9 @@ jobs: build_frontend_image: uses: ./.github/workflows/buildFrontendImage.yml + build_frontend_lighthouse_image: + uses: ./.github/workflows/buildFrontendLighthouseImage.yml + build_nginx_image: uses: ./.github/workflows/buildNginxImage.yml @@ -47,7 +50,18 @@ jobs: DOCKER_DATABASE_IMAGE_VERSION: ${{ needs.build_database_image.outputs.version }} DOCKER_FRONTEND_IMAGE_VERSION: ${{ needs.build_frontend_image.outputs.version }} DOCKER_NGINX_IMAGE_VERSION: ${{ needs.build_nginx_image.outputs.version }} - + lighthouse: + needs: + - build_backend_image + - build_database_image + - build_nginx_image + - build_frontend_lighthouse_image + uses: ./.github/workflows/lighthouse.yml + with: + DOCKER_BACKEND_IMAGE_VERSION: ${{ needs.build_backend_image.outputs.version }} + DOCKER_FRONTEND_LIGHTHOUSE_IMAGE_VERSION: ${{ needs.build_frontend_lighthouse_image.outputs.version }} + DOCKER_DATABASE_IMAGE_VERSION: ${{ needs.build_database_image.outputs.version }} + DOCKER_NGINX_IMAGE_VERSION: ${{ needs.build_nginx_image.outputs.version }} tests: needs: - build_database_image diff --git a/.gitignore b/.gitignore index 84ae3f2a94..79df860475 100644 --- a/.gitignore +++ b/.gitignore @@ -9,10 +9,10 @@ node_modules *.orig *.rej /.env +/.env.local certs/ yarn-error.log backend/locust/__pycache__/ -wiremock*.jar cypress/cypress.env.json frontend/src/.env.local .run/Backend.run.xml diff --git a/.run/e2e local headless.run.xml b/.run/e2e local headless.run.xml new file mode 100644 index 0000000000..400a476e45 --- /dev/null +++ b/.run/e2e local headless.run.xml @@ -0,0 +1,12 @@ + + + + + +