Skip to content

Commit

Permalink
E2E refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed May 24, 2024
1 parent e537b3e commit 2149244
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 381 deletions.
39 changes: 0 additions & 39 deletions .github/actions/e2e-bake-compose/action.yml

This file was deleted.

47 changes: 0 additions & 47 deletions .github/actions/local-e2e-tests/action.yml

This file was deleted.

24 changes: 9 additions & 15 deletions .github/actions/run-local-api/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Run E2E tests
description: Run the E2E tests against an environment

inputs:
api-image:
description: API image to use
required: true
database_url:
description: The database URL to connect the API to
required: true
Expand All @@ -15,40 +18,31 @@ inputs:
default: 'false'

outputs:
containerId:
container-id:
description: Docker container ID for the running Flagsmith API instance
value: ${{ steps.run-api-container.outputs.containerId }}
value: ${{ steps.run-api-container.outputs.container-id }}

runs:
using: composite

steps:
- name: Set up Depot CLI
uses: depot/setup-action@v1
with:
oidc: true

- name: Build temporary Docker image for running the API
run: depot build --load -t flagsmith/flagsmith-api:e2e-${{ github.sha }} -f api/Dockerfile .
shell: bash

- name: Run the API
id: run-api-container
working-directory: api
env:
E2E_TEST_AUTH_TOKEN: ${{ inputs.e2e_test_token }}
DATABASE_URL: ${{ inputs.database_url }}
DISABLE_ANALYTICS_FEATURES: ${{ inputs.disable_analytics_features }}
E2E_TEST_AUTH_TOKEN: ${{ inputs.e2e_test_token }}
run: |
CONTAINER_ID=$( docker run \
-p 8000:8000 \
-e DATABASE_URL=$DATABASE_URL \
-e E2E_TEST_AUTH_TOKEN=$E2E_TEST_AUTH_TOKEN \
-e DISABLE_ANALYTICS_FEATURES=$DISABLE_ANALYTICS_FEATURES \
-e E2E_TEST_AUTH_TOKEN=$E2E_TEST_AUTH_TOKEN \
-e DJANGO_ALLOWED_HOSTS="*" \
-e DJANGO_SETTINGS_MODULE=app.settings.test \
-e ENABLE_FE_E2E=True \
-e ACCESS_LOG_LOCATION=- \
-d flagsmith/flagsmith-api:e2e-${{ github.sha }} )
echo "containerId=$CONTAINER_ID" >> "$GITHUB_OUTPUT"
-d ${{ inputs.api-image }} )
echo "container-id=$CONTAINER_ID" >> "$GITHUB_OUTPUT"
shell: bash
28 changes: 23 additions & 5 deletions .github/workflows/.reusable-docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Build Docker Image
on:
workflow_call:
inputs:
registry_url:
registry-url:
type: string
description: Github container registry base URL
required: false
Expand All @@ -17,11 +17,26 @@ on:
type: string
description: Image slug
required: true
build-args:
type: string
description: List of build-time variables
required: false
scan:
type: boolean
description: Whether to scan image for vulnerabilities
required: false
default: true
outputs:
image:
description: Resulting image specifier
value: ${{ inputs.registry-url }}/flagsmith/${{ inputs.slug }}:${{ jobs.build.outputs.version }}

jobs:
build:
name: Build and verify ${{ inputs.slug }} image
name: Build ${{ inputs.scan && 'and verify ' || '' }}${{ inputs.slug }} image
runs-on: ubuntu-latest
outputs:
version: ${{ steps.meta.outputs.version }}

permissions:
packages: write
Expand All @@ -38,7 +53,7 @@ jobs:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry_url }}
registry: ${{ inputs.registry-url }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -47,20 +62,23 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
${{ inputs.registry_url }}/flagsmith/${{ inputs.slug }}
${{ inputs.registry-url }}/flagsmith/${{ inputs.slug }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
- name: Build and push image
uses: depot/build-push-action@v1
with:
push: true
build-args: ${{ inputs.build-args }}
file: ${{ inputs.file }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Run Trivy vulnerability scanner
if: ${{ inputs.scan }}
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ inputs.registry_url }}/flagsmith/${{ inputs.slug }}:${{ steps.meta.outputs.version }}
image-ref: ${{ inputs.registry-url }}/flagsmith/${{ inputs.slug }}:${{ steps.meta.outputs.version }}
68 changes: 68 additions & 0 deletions .github/workflows/.reusable-local-e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# reusable workflow
name: Run E2E tests in local environment

on:
workflow_call:
inputs:
api-image:
type: string
description: API image to use
required: true
tests:
type: string
description: Space-delimited list of E2E tests to be executed
required: false
default: ''
concurrency:
type: number
description: The concurrent number of browsers to be used on testing
required: false
default: 3

jobs:
run-e2e:
runs-on: ubuntu-latest
name: "E2E Local${{ inputs.tests && format(': {0}', inputs.tests) || ''}}"

services:
postgres:
image: postgres:11.12-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: flagsmith
ports: ['5432:5432']
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Cloning repo
uses: actions/checkout@v4

- name: Run Local API
id: run-local-api
uses: ./.github/actions/run-local-api
with:
api-image: ${{ inputs.api-image }}
e2e_test_token: some-token
# As per https://stackoverflow.com/q/65497331/421808 172.17.0.1 seems like the only way to resolve host DB
database_url: postgres://postgres:postgres@172.17.0.1:5432/flagsmith
disable_analytics_features: true

- name: Run E2E tests against local
uses: ./.github/actions/e2e-tests
env:
E2E_CONCURRENCY: ${{ inputs.concurrency }}
with:
e2e_test_token: some-token
slack_token: ${{ secrets.SLACK_TOKEN }}
environment: local
tests: ${{ inputs.tests }}

- name: Output API container status and logs
if: failure()
env:
API_CONTAINER_ID: ${{ steps.run-local-api.outputs.containerId }}
run: |
docker inspect $API_CONTAINER_ID | jq '.[0].State'
docker logs $API_CONTAINER_ID
shell: bash
Loading

0 comments on commit 2149244

Please sign in to comment.