From 5f238d6b6d322560d98a811774ede2bf744e55bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Wed, 12 Mar 2025 13:47:36 +0100 Subject: [PATCH] chore: use a local image of unleash enterprise for testing FE (#9509) This removes the need of running a heroku instance with enterprise to run frontend tests. We can also get rid of vercel deployments of the frontend for PRs (ofc we'd be loosing the preview if we do this) It relies on the free enterprise docker image to spin up a clean Unleash instance on each frontend spec test. It also seems to speed up tests, I guess because we don't have to wait for vercel deployment queue: ![image](https://github.com/user-attachments/assets/60a2aef1-9a5a-442d-b241-8c5c145c679e) Compared with other recent PRs: ![image](https://github.com/user-attachments/assets/9a7498aa-26e6-48a4-aba0-c67e5380ced4) Unrelated to this PR but something is making the features spec tests very slow since Cypress upgrade: https://github.com/Unleash/unleash/actions/runs/13784760762/job/38550079932#step:4:138 --- .github/docker-compose.test.yml | 55 +++++++++++++++++++++++++++++ .github/workflows/e2e.frontend.yaml | 14 ++++++-- 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 .github/docker-compose.test.yml diff --git a/.github/docker-compose.test.yml b/.github/docker-compose.test.yml new file mode 100644 index 0000000000..27f99eb9f0 --- /dev/null +++ b/.github/docker-compose.test.yml @@ -0,0 +1,55 @@ +# This docker compose setup configures: +# - the Unleash enterprise server instance + the necessary backing Postgres database +# +# To learn more about all the parts of Unleash, visit +# https://docs.getunleash.io +# +# NOTE: please do not use this configuration for production setups. +# Unleash does not take responsibility for any data leaks or other +# problems that may arise as a result. +# +# This is intended to be used for demo, development, and learning +# purposes only. + +services: + # The Unleash server contains the Unleash configuration and + # communicates with server-side SDKs and the Unleash Proxy + unleash: + image: 726824350591.dkr.ecr.eu-central-1.amazonaws.com/unleash-enterprise:latest + pull_policy: "always" + ports: + - "4242:4242" + environment: + DATABASE_URL: "postgres://postgres:unleash@db/unleash" + DATABASE_SSL: "false" + UNLEASH_LICENSE: "${FRONTEND_TEST_LICENSE}" + depends_on: + db: + condition: service_healthy + healthcheck: + test: wget --no-verbose --tries=1 --spider http://localhost:4242/health || exit 1 + interval: 1s + timeout: 1m + retries: 5 + start_period: 15s + db: + expose: + - "5432" + image: postgres:16 + environment: + POSTGRES_DB: "unleash" + # trust incoming connections blindly (DON'T DO THIS IN PRODUCTION!) + POSTGRES_HOST_AUTH_METHOD: "trust" + healthcheck: + test: + [ + "CMD", + "pg_isready", + "--username=postgres", + "--host=127.0.0.1", + "--port=5432", + ] + interval: 2s + timeout: 1m + retries: 5 + start_period: 10s diff --git a/.github/workflows/e2e.frontend.yaml b/.github/workflows/e2e.frontend.yaml index 4a25887039..9137e3ea6c 100644 --- a/.github/workflows/e2e.frontend.yaml +++ b/.github/workflows/e2e.frontend.yaml @@ -1,8 +1,10 @@ name: e2e:frontend -on: [deployment_status] +on: + pull_request: + # paths: + # - 'frontend/**' jobs: e2e: - if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' && contains(github.event.deployment_status.target_url, 'unleash-monorepo-frontend') runs-on: ubuntu-latest strategy: matrix: @@ -19,11 +21,17 @@ jobs: echo "$GITHUB_CONTEXT" - name: Checkout uses: actions/checkout@v4 + - name: Start Unleash test instance + run: | + curl https://app.unleash-hosted.com/docker-login/token/${{ secrets.ECR_ENTERPRISE_TOKEN }} | docker login --username AWS --password-stdin 726824350591.dkr.ecr.eu-central-1.amazonaws.com + docker compose -f .github/docker-compose.test.yml up -d --wait -t 90 + env: + FRONTEND_TEST_LICENSE: ${{ secrets.FRONTEND_TEST_LICENSE }} - name: Run Cypress uses: cypress-io/github-action@v6 with: working-directory: frontend env: AUTH_USER=admin,AUTH_PASSWORD=unleash4all - config: baseUrl=${{ github.event.deployment_status.target_url }} + config: baseUrl=http://localhost:4242 spec: cypress/integration/${{ matrix.test }} install-command: yarn --immutable