From 04d7488d7703e4149513185a199098114c6eb6c2 Mon Sep 17 00:00:00 2001 From: Ivar Abrahamsen Date: Thu, 28 Nov 2024 19:04:17 +0000 Subject: [PATCH] Compose stack --- README.md | 29 ++++- compose.yml | 143 ++++++++++++++++----- docker/config/cdp-portal-backend.env | 15 +++ docker/config/cdp-portal-frontend.env | 3 + docker/config/cdp-portal-stubs.env | 7 + docker/config/cdp-self-service-ops.env | 1 + docker/config/cdp-user-service-backend.env | 1 + docker/config/defaults.env | 17 ++- docker/config/example-backend.env | 1 - docker/config/example-frontend.env | 1 - 10 files changed, 171 insertions(+), 47 deletions(-) create mode 100644 docker/config/cdp-portal-backend.env create mode 100644 docker/config/cdp-portal-frontend.env create mode 100644 docker/config/cdp-portal-stubs.env create mode 100644 docker/config/cdp-self-service-ops.env create mode 100644 docker/config/cdp-user-service-backend.env delete mode 100644 docker/config/example-backend.env delete mode 100644 docker/config/example-frontend.env diff --git a/README.md b/README.md index 5a6bf1e..2179824 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,13 @@ -cdp-portal-journey-tests +# cdp-portal-journey-tests -The template to create a service that runs WDIO tests against an environment. +Testing CDP Portal. -- [Requirements](#requirements) - - [Node.js](#nodejs) +WDIO tests against an environment, github workflow or locally. + +- [Related Tests](#related-tests) - [Local](#local) + - [Requirements](#requirements) + - [Node.js](#nodejs) - [Setup](#setup) - [Running local tests](#running-local-tests) - [Debugging local tests](#debugging-local-tests) @@ -15,6 +18,19 @@ The template to create a service that runs WDIO tests against an environment. ## Local Development +### Requirements + +#### Node.js + +Please install [Node.js](http://nodejs.org/) `>= v20` and [npm](https://nodejs.org/) `>= v9`. You will find it +easier to use the Node Version Manager [nvm](https://github.com/creationix/nvm) + +To use the correct version of Node.js for this application, via nvm: + +```bash +nvm use +``` + ### Setup Install application dependencies: @@ -25,7 +41,10 @@ npm install ### Running local tests -Start application you are testing on the url specified in `baseUrl` [wdio.local.conf.js](wdio.local.conf.js) +1. Edit [wdio.local.conf.js](wdio.local.conf.js) and set `baseUrl` to your service under test. + +1. Start application you are testing on the url specified in `baseUrl` + ```bash npm run test:local diff --git a/compose.yml b/compose.yml index 3900c36..c4dda3c 100644 --- a/compose.yml +++ b/compose.yml @@ -37,6 +37,7 @@ services: interval: 5s start_period: 5s retries: 3 + ################################################################################ localstack: image: localstack/localstack:3.2.0 @@ -70,39 +71,113 @@ services: # Add the services you want to test below. # ################################################################################ -# cdp-example-node-frontend: -# image: defradigital/cdp-example-node-frontend:latest -# env_file: -# - ./docker/config/defaults.env -# - ./docker/config/example-frontend.env -# environment: -# - PORT=3000 -# depends_on: -# cdp-example-node-backend: -# condition: service_started -# redis: -# condition: service_healthy -# ports: -# - 3000:3000 -# healthcheck: -# test: ["CMD", "curl", "http://localhost:3000/health"] -# interval: 3s -# start_period: 2s -# retries: 3 + cdp-portal-frontend: + image: defradigital/cdp-portal-frontend:latest + env_file: + - ./docker/config/defaults.env + - ./docker/config/portal-frontend.env + environment: + - PORT=3000 + depends_on: + cdp-portal-backend: + condition: service_started + cdp-self-service-ops: + condition: service_started + cdp-user-service-backend: + condition: service_started + redis: + condition: service_healthy + ports: + - 3000:3000 + healthcheck: + test: ["CMD", "curl", "http://localhost:3000/health"] + interval: 3s + start_period: 2s + retries: 3 + +################################################################################ + cdp-portal-backend: + image: defradigital/cdp-portal-backend:latest + ports: + - 5094:5094 + env_file: + - ./docker/config/defaults.env + - ./docker/config/portal-backend.env + environment: + - PORT=5094 + depends_on: + localstack: + condition: service_healthy + mongodb: + condition: service_healthy + cdp-self-service-ops: + condition: service_started + cdp-user-service-backend: + condition: service_started ################################################################################ -# cdp-example-node-backend: -# image: defradigital/cdp-example-node-backend:latest -# env_file: -# - ./docker/config/defaults.env -# - ./docker/config/example-backend.env -# environment: -# - PORT=3001 -# depends_on: -# mongodb: -# condition: service_healthy -# healthcheck: -# test: ["CMD", "curl", "http://localhost:3001/health"] -# interval: 3s -# start_period: 2s -# retries: 3 + cdp-user-service-backend: + image: defradigital/cdp-user-service-backend:latest + ports: + - 3001:3001 + env_file: + - ./config/defaults.env + - ./config/cdp-user-service-backend.env + environment: + - PORT=3001 + depends_on: + localstack: + condition: service_healthy + mongodb: + condition: service_started + healthcheck: + test: ["CMD", "curl", "http://localhost:3001/health"] + interval: 3s + start_period: 2s + retries: 3 + +################################################################################ + cdp-self-service-ops: + image: defradigital/cdp-self-service-ops:latest + ports: + - 3009:3009 + env_file: + - ./config/defaults.env + - ./config/cdp-self-service-ops.env + environment: + - PORT=3009 + depends_on: + localstack: + condition: service_healthy + mongodb: + condition: service_started + healthcheck: + test: ["CMD", "curl", "http://localhost:3009/health"] + interval: 3s + start_period: 2s + retries: 3 + +################################################################################ + cdp-portal-stubs: + image: defradigital/cdp-portal-stubs:latest + env_file: + - ./config/defaults.env + - ./config/cdp-portal-stubs.env + ports: + - 3939:3939 + environment: + - PORT=3939 + - OIDC_SHOW_LOGIN=true + depends_on: + localstack: + condition: service_healthy + mongodb: + condition: service_started + redis: + condition: service_started + healthcheck: + test: ["CMD", "echo", "Y29uc3QgZT1yZXF1aXJlKCJodHRwIiksdD17aG9zdG5hbWU6ImxvY2FsaG9zdCIscG9ydDpwcm9jZXNzLmVudi5QT1JULHBhdGg6Ii9oZWFsdGgiLG1ldGhvZDoiR0VUIn0sbz1lLnJlcXVlc3QodCwoZT0+e2xldCB0PSIiO2Uub24oImRhdGEiLChlPT57dCs9ZX0pKSxlLm9uKCJlbmQiLCgoKT0+e3Byb2Nlc3MuZXhpdCgwKX0pKX0pKTtvLm9uKCJlcnJvciIsKGU9Pntwcm9jZXNzLmV4aXQoMSl9KSksby5lbmQoKTsK", "|", "base64", "-d", "|", "node", "-"] + interval: 3s + start_period: 2s + profiles: + - portal diff --git a/docker/config/cdp-portal-backend.env b/docker/config/cdp-portal-backend.env new file mode 100644 index 0000000..04109f7 --- /dev/null +++ b/docker/config/cdp-portal-backend.env @@ -0,0 +1,15 @@ +Github__ApiUrl=http://localhost:3939 +# This is a mock app key +# $ ssh-keygen -t rsa -b 4096 -m PEM -f /tmp/mock.key -q -P "" && cat /tmp/mock.key | base64 -w0 +Github__AppKey=... + +ASPNETCORE_ENVIRONMENT=Development +Docker__RegistryUrl=http://localhost:3939 +Github__PollIntervalSecs=10 + +UserServiceBackendUrl=http://localhost:3001 + +LocalStack__Config__LocalStackHost=localhost +SqsLocalServiceUrl=http://localhost:4566 +EcsEvents__QueueUrl=http://localhost:4566/000000000000/ecs-deployments +EcrEvents__QueueUrl=http://localhost:4566/000000000000/ecr-push-events diff --git a/docker/config/cdp-portal-frontend.env b/docker/config/cdp-portal-frontend.env new file mode 100644 index 0000000..b2d578b --- /dev/null +++ b/docker/config/cdp-portal-frontend.env @@ -0,0 +1,3 @@ +APP_BASE_URL=http://localhost:3000 +USE_SINGLE_INSTANCE_CACHE=true +TERMINAL_PROXY_URL=http://localhost:8085 diff --git a/docker/config/cdp-portal-stubs.env b/docker/config/cdp-portal-stubs.env new file mode 100644 index 0000000..1e02d39 --- /dev/null +++ b/docker/config/cdp-portal-stubs.env @@ -0,0 +1,7 @@ +# +OIDC_BASE_PATH=/63983fc2-cfff-45bb-8ec2-959e21062b9a/v2.0 +OIDC_SHOW_LOGIN=false +# OIDC_PUBLIC_KEY_B64=... + +# random key for local testing +# OIDC_PRIVATE_KEY_B64=... diff --git a/docker/config/cdp-self-service-ops.env b/docker/config/cdp-self-service-ops.env new file mode 100644 index 0000000..d7965f5 --- /dev/null +++ b/docker/config/cdp-self-service-ops.env @@ -0,0 +1 @@ +SQS_GITHUB_QUEUE=http://localstack:4566/000000000000/github-events diff --git a/docker/config/cdp-user-service-backend.env b/docker/config/cdp-user-service-backend.env new file mode 100644 index 0000000..01adc72 --- /dev/null +++ b/docker/config/cdp-user-service-backend.env @@ -0,0 +1 @@ +AZURE_CLIENT_BASE_URL=http://localhost:3939/msgraph/ diff --git a/docker/config/defaults.env b/docker/config/defaults.env index 5c81751..791b876 100644 --- a/docker/config/defaults.env +++ b/docker/config/defaults.env @@ -1,16 +1,16 @@ # MongoDB -MONGO_URI=mongodb://mongodb:27017/?tls=false -Mongo__DatabaseUri=mongodb://mongodb:27017/?tls=false +MONGO_URI=mongodb://localhost:27017/?tls=false +Mongo__DatabaseUri=mongodb://localhost:27017/?tls=false # Redis REDIS_HOST=redis USE_SINGLE_INSTANCE_CACHE=true # Localstack/AWS -LOCALSTACK_URL=http://localstack:4566 -SNS_ENDPOINT=http://localstack:4566 -SQS_ENDPOINT=http://localstack:4566 -S3_ENDPOINT=http://localstack:4566 +LOCALSTACK_URL=http://localhost:4566 +SNS_ENDPOINT=http://localhost:4566 +SQS_ENDPOINT=http://localhost:4566 +S3_ENDPOINT=http://localhost:4566 AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test @@ -19,3 +19,8 @@ AWS_REGION=eu-west-2 # Placeholder trust store cert TRUSTSTORE_CDP_ROOT_CA=LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUI5akNDQVYrZ0F3SUJBZ0lVS1I4MkxndGtOQmNjZHlwWUQyNks4N3paK3ZZd0RRWUpLb1pJaHZjTkFRRUUKQlFBd0RURUxNQWtHQTFVRUN3d0NSVkF3SGhjTk1Ua3dPVEkyTURJd05EVXlXaGNOTVRreE1ESTJNREl3TkRVeQpXakFOTVFzd0NRWURWUVFMREFKRlVEQ0JuekFOQmdrcWhraUc5dzBCQVFFRkFBT0JqUUF3Z1lrQ2dZRUF3S3ZhCk5aQ09HY3VZOTAvQnVkUytxUWljK0EzMXVNOG1MdG1JNjBSMWlFamdFV0dCQ3hTaURiMmg4bVFKaVh3a3VsOVcKZWJhYXpQN2hrcWtkTm9KZ1YvNk5FNysrR0t5eVM4ZkloSmdlV1NiNkVlbE1GaGpRMG5aS3piWlg1bXMzSTkxbgp0d3prY0h0S0NRaS9naS9Sb3VobGsvUC9RVmNyelNnSFVIcUpOeTBDQXdFQUFhTlRNRkV3SFFZRFZSME9CQllFCkZISGJncW5uaG0zR0FKNGd5Mkl1RUR4cEx5ZTdNQjhHQTFVZEl3UVlNQmFBRkhIYmdxbm5obTNHQUo0Z3kySXUKRUR4cEx5ZTdNQThHQTFVZEV3RUIvd1FGTUFNQkFmOHdEUVlKS29aSWh2Y05BUUVFQlFBRGdZRUFHNUNvcWNFeQoxNXZVcGo1VmZKZVIvRFM3MHRQSWlucC9UQ0M5a1JPLysrVFNuUGJxVmNmUHI4dkl5YzRMM01QS2pYRkJzZWZFCnZ0ZkhHR3VjVnR2NU4xKzRVL2I5TnhORmJ1SDJNUDdXM3N3WjRXTTcyTmErVzZpT2h3ZXNPcjBwM0ljT2Z4YzMKUk5DbmFnRm10YkRGeEFsUFhRMGQrbStONWd4TFJvQ1gxaEU9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K + +GITHUB_BASE_URL=http://localhost:3939 +PORTAL_BACKEND_URL=http://localhost:5094 +SELF_SERVICE_OPS_URL=http://localhost:3009 +USER_SERVICE_BACKEND_URL=http://localhost:3001 diff --git a/docker/config/example-backend.env b/docker/config/example-backend.env deleted file mode 100644 index 3df8d83..0000000 --- a/docker/config/example-backend.env +++ /dev/null @@ -1 +0,0 @@ -S3_BUCKET=test-bucket diff --git a/docker/config/example-frontend.env b/docker/config/example-frontend.env deleted file mode 100644 index 4443215..0000000 --- a/docker/config/example-frontend.env +++ /dev/null @@ -1 +0,0 @@ -EXAMPLE_BACKEND_URL=http://example-node-backend:3001