Skip to content

Commit

Permalink
test: add pgpool test environment (#4747)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell authored Nov 27, 2024
1 parent 7ffa794 commit 15cf98f
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 36 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/manual-e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'Manual E2E tests'

on:
workflow_dispatch:
inputs:
e2e-token:
description: 'The authentication token used by the E2E process'
required: true
e2e-concurrency:
description: 'The concurrency value to use when running the E2E process'
default: 3
type: number
api-url:
description: 'Which database service to use to run the API against'
default: 'https://api.flagsmith.com/api/v1/'

jobs:
run-e2e-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
cache: npm
node-version-file: frontend/.nvmrc
cache-dependency-path: frontend/package-lock.json

- name: Run tests
working-directory: frontend
env:
E2E_TEST_AUTH_TOKEN: ${{ inputs.e2e-token }}
FLAGSMITH_API_URL: ${{ inputs.api-url }}
E2E_CONCURRENCY: ${{ inputs.e2e-concurrency }}
run: |
npm ci
npm run env
npm run test
62 changes: 62 additions & 0 deletions docker-compose.pgpool.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
services:
pg-0:
extends:
file: ./docker/common/db/.pgpool.yml
service: pg-0
volumes:
- pg_0_data:/bitnami/postgresql

pg-1:
extends:
file: ./docker/common/db/.pgpool.yml
service: pg-1
volumes:
- pg_1_data:/bitnami/postgresql

pgpool:
extends:
file: ./docker/common/db/.pgpool.yml
service: pgpool

flagsmith:
image: flagsmith/flagsmith:latest
platform: linux/arm64
environment:
DATABASE_URL: postgresql://flagsmith:password@pgpool:5432/flagsmith
USE_POSTGRES_FOR_ANALYTICS: 'true' # Store API and Flag Analytics data in Postgres

ENVIRONMENT: production # set to 'production' in production.
DJANGO_ALLOWED_HOSTS: '*' # Change this in production
ALLOW_ADMIN_INITIATION_VIA_CLI: 'true' # Change this in production
FLAGSMITH_DOMAIN: localhost:8000 # Change this in production
DJANGO_SECRET_KEY: secret # Change this in production
ENABLE_ADMIN_ACCESS_USER_PASS: 'true'
TASK_RUN_METHOD: TASK_PROCESSOR # other options are: SYNCHRONOUSLY, SEPARATE_THREAD (default)
ports:
- 8000:8000
healthcheck:
test: ['CMD-SHELL', 'python /app/scripts/healthcheck.py']
interval: 2s
timeout: 2s
retries: 20
start_period: 20s
depends_on:
pgpool:
condition: service_healthy

flagsmith_processor:
image: flagsmith/flagsmith:latest
platform: linux/arm64
environment:
DATABASE_URL: postgresql://flagsmith:password@pgpool:5432/flagsmith
USE_POSTGRES_FOR_ANALYTICS: 'true'
depends_on:
flagsmith:
condition: service_healthy
command: run-task-processor

volumes:
pg_0_data:
driver: local
pg_1_data:
driver: local
62 changes: 62 additions & 0 deletions docker/common/db/.pgpool.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright Broadcom, Inc. All Rights Reserved.
# SPDX-License-Identifier: APACHE-2.0

services:
pg-0:
image: docker.io/bitnami/postgresql-repmgr:15
ports:
- 5432
environment:
- POSTGRESQL_POSTGRES_PASSWORD=password
- POSTGRESQL_USERNAME=flagsmith
- POSTGRESQL_PASSWORD=password
- POSTGRESQL_DATABASE=flagsmith
- POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS=1
- REPMGR_PRIMARY_HOST=pg-0
- REPMGR_PARTNER_NODES=pg-1,pg-0
- REPMGR_NODE_NAME=pg-0
- REPMGR_NODE_NETWORK_NAME=pg-0
- REPMGR_USERNAME=repmgr
- REPMGR_PASSWORD=repmgrpassword

pg-1:
image: docker.io/bitnami/postgresql-repmgr:15
ports:
- 5432
environment:
- POSTGRESQL_POSTGRES_PASSWORD=password
- POSTGRESQL_USERNAME=flagsmith
- POSTGRESQL_PASSWORD=password
- POSTGRESQL_DATABASE=flagsmith
- POSTGRESQL_NUM_SYNCHRONOUS_REPLICAS=1
- REPMGR_PRIMARY_HOST=pg-0
- REPMGR_PARTNER_NODES=pg-0,pg-1
- REPMGR_NODE_NAME=pg-1
- REPMGR_NODE_NETWORK_NAME=pg-1
- REPMGR_USERNAME=repmgr
- REPMGR_PASSWORD=repmgrpassword

pgpool:
image: docker.io/bitnami/pgpool:4
ports:
- 5432:5432
environment:
- PGPOOL_BACKEND_NODES=0:pg-0:5432,1:pg-1:5432
- PGPOOL_SR_CHECK_USER=repmgr
- PGPOOL_SR_CHECK_PASSWORD=repmgrpassword
- PGPOOL_ENABLE_LDAP=no
- PGPOOL_POSTGRES_USERNAME=postgres
- PGPOOL_POSTGRES_PASSWORD=password
- PGPOOL_ADMIN_USERNAME=admin
- PGPOOL_ADMIN_PASSWORD=adminpassword
- PGPOOL_ENABLE_LOAD_BALANCING=yes
- PGPOOL_POSTGRES_CUSTOM_USERS=flagsmith
- PGPOOL_POSTGRES_CUSTOM_PASSWORDS=password
healthcheck:
test: ['CMD', '/opt/bitnami/scripts/pgpool/healthcheck.sh']
interval: 10s
timeout: 5s
retries: 5
depends_on:
- pg-0
- pg-1
42 changes: 42 additions & 0 deletions docker/common/e2e/.e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
services:
flagsmith-api:
image: ${API_IMAGE:-ghcr.io/flagsmith/flagsmith-api:dev}
build:
context: ../../../
target: oss-api
environment:
E2E_TEST_AUTH_TOKEN: some-token
ENABLE_FE_E2E: 'True'
DJANGO_ALLOWED_HOSTS: '*'
DISABLE_ANALYTICS_FEATURES: 'true'
EMAIL_BACKEND: django.core.mail.backends.smtp.EmailBackend
ACCESS_LOG_LOCATION: /dev/shm/log.txt
ports:
- 8000:8000
healthcheck:
test: '[ -e /dev/shm/log.txt ] && exit 0 || exit 1'
start_period: 60s
interval: 10s
timeout: 3s
retries: 30

frontend:
image: ${E2E_IMAGE:-ghcr.io/flagsmith/flagsmith-e2e:dev}
build:
context: ../../../
dockerfile: frontend/Dockerfile.e2e
environment:
E2E_TEST_TOKEN_DEV: some-token
DISABLE_ANALYTICS_FEATURES: 'true'
FLAGSMITH_API: flagsmith-api:8000/api/v1/
SLACK_TOKEN: ${SLACK_TOKEN}
GITHUB_ACTION_URL: ${GITHUB_ACTION_URL}
ports:
- 8080:8080
depends_on:
flagsmith-api:
condition: service_healthy

links:
- flagsmith-api:flagsmith-api
command: [npm, run, test]
17 changes: 0 additions & 17 deletions docker/db.yml

This file was deleted.

19 changes: 0 additions & 19 deletions frontend/docker-compose.yml

This file was deleted.

0 comments on commit 15cf98f

Please sign in to comment.