-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor build scripts and gh-action
- Loading branch information
Showing
20 changed files
with
305 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
KUBER_API_URL=https://sanchonet.kuber.cardanoapi.io | ||
KUBER_API_KEY=xxxxxxxxxxxxx | ||
|
||
## Not required anymore | ||
BLOCKFROST_API_URL= | ||
BLOCKFROST_PROJECT_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
from pydantic_settings import BaseSettings | ||
from pydantic import BaseModel | ||
|
||
|
||
class Settings(BaseSettings): | ||
class Settings(BaseModel): | ||
kuber_api_url: str | ||
kuber_api_key: str | ||
kuber_api_key: str = "" # Default value is an empty string | ||
|
||
blockfrost_api_url: str | ||
blockfrost_project_id: str | ||
|
||
|
||
settings = Settings() | ||
settings = Settings(kuber_api_url="your_api_url_here") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
STACK_NAME=govtool | ||
PROJECT_NAME=govtool | ||
CARDANO_NETWORK=sanchonet | ||
BASE_DOMAIN=govtool.cardanoapi.io | ||
BLOCKFROST_API_URL="" | ||
BLOCKFROST_PROJECT_ID="" | ||
GOVTOOL_TAG=test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,41 @@ | ||
GovTool Test Infrastructure | ||
==================== | ||
|
||
Services required for testing GovTool | ||
Compose files and scripts to deploy and test environment of govtool. | ||
Additionally, it deploys services required to perform integration test on the environment | ||
|
||
## 1. Setting up the services | ||
## Compose files and services | ||
1. [basic-services](./docker-compose-basic-services.yml) : postgres and gateway | ||
2. [cardano](./docker-compose-cardano.yml) : node, dbsync and kuber | ||
3. [govtool](./docker-compose-govtool.yml) : govtool-frontend and govtool-backend | ||
4. [govaction-loader](./docker-compose-govaction-loader.yml) : govaction-loader frontend and badkcne | ||
5. [test](./docker-compose-test.yml) : lighthouse-server and metadata-api | ||
|
||
## Setting up the services | ||
|
||
#### a. Deploy with docker on swarm mode. | ||
|
||
#### a. Update .env file and DNS records | ||
|
||
- Create `.env` file by copying `.env.example` and update it. | ||
- Make sure that DNS is pointed to the right server. Following are the domains used. | ||
- lighthouse.BASE_DOMAIN | ||
- metabase.BASE_DOMAIN | ||
- sonarqube.BASE_DOMAIN | ||
- metrics.BASE_DOMAIN | ||
- kuber.BASE_DOMAIN | ||
|
||
|
||
`docker stack deploy` command doesn't support `.env` file secret/config files. | ||
There's a helper script `deploy-swarm.sh` to load the environment variables from `.env` file and generate rendered docker compose file. | ||
```bash | ||
cd ./test/test-infrastructure # cd into the test-infrastructure folder | ||
docker swarm init # if swarm mode is not enabled yet. | ||
docker compose build # build the images | ||
docker node update xxxx --label-add govtool-test-stack=true ## set the node to be used for deploying the services | ||
./gen-configs.sh # generate configs and secrets. | ||
./deploy-swarm.sh prepare # start postgres and nginx | ||
sleep 30 # wait for 30 secs for postgres to be healthy | ||
./deploy-swarm.sh finalize # deploy all the required services. | ||
``` | ||
|
||
#### b. Setup | ||
When the stack is ready, further configuration is required it the services and github repo secrets and workflow files. | ||
|
||
# 2. Services List | ||
|
||
## SonarQube Server | ||
#### Requires | ||
- postgres database | ||
|
||
#### Used by | ||
- Github Action to submit sonar-sacanner result | ||
|
||
`sonar-scanner` is used for static analysis of code. | ||
The analysis generated by sonar-scanner is saved to SonarQube server for better visibility and to see progress over time. | ||
|
||
|
||
**Docker Image:** [mc1arke/sonarqube-with-community-branch-plugin:9.9-community](https://hub.docker.com/layers/mc1arke/sonarqube-with-community-branch-plugin/9.9-community/images/sha256-b91ac551bea0fc3b394eaf7f82ea79115e03db9ab47d26610b9e1566723a07a5?context=explore) | ||
|
||
**See :** [sonar-scanner](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner/), [actions/sonar-scanner](https://github.com/marketplace/actions/sonar-scanner) | ||
|
||
### Initial configuration. | ||
|
||
- Login and change the initial password. | ||
``` | ||
username: admin | ||
password: admin | ||
``` | ||
- Create new project and set the projectKey in file [govtool/frontend/sonar-project.properties](../../govtool/frontend/sonar-project.properties) | ||
- Update the github action secrets | ||
- SONAR_HOST_URL | ||
- SONAR_TOKEN | ||
|
||
|
||
## Metabase Server | ||
#### Requires | ||
- postgres database | ||
|
||
Metabase provides UI to show graphs and visualization from different datasource. | ||
It is used for visualizing the test metrics and the api response times over time. | ||
|
||
**Docker Image:** [metabase/metabase:v0.46.6.4](https://hub.docker.com/layers/metabase/metabase/v0.46.6.4/images/sha256-95c60db0c87c5da9cb81f6aefd0cd548fe2c14ff8c8dcba2ea58a338865cdbd9?context=explore) | ||
|
||
### Initial Configuration | ||
- Setup initial account for login via the webapp. | ||
- Under database section in admin settings, add the `govtool_lithghouse` and `govtool_metrics` databases | ||
- Select the database and add visualizations, queries for the data. | ||
|
||
## LightHouse Report Server | ||
#### Requires | ||
- postgres database | ||
|
||
#### Used by | ||
- GitHub Action to submit lighthouse report. | ||
|
||
Lighthouse has audits for performance, accessibility, progressive web apps, SEO, and more. | ||
Lighthouse-Server is used to host and display the audits generated by lighthouse. | ||
|
||
**Docker Image:** [patrickhulce/lhci-server:0.12.0](https://hub.docker.com/r/patrickhulce/lhci-server) | ||
|
||
### Initial Configuration | ||
- install lhci locally and run `lhci wizard` to setup project | ||
- update `--serverBaseUrl={{...}}` parameter in [.github/workflows/lighthouse.yml](../../.github/workflows/lighthouse.yml) | ||
- update `LHCI_SERVER_TOKEN` in github secrets. | ||
- install lighthouse github app on the repo | ||
- obtain app token from lighthouse app and update `LHCI_GITHUB_APP_TOKEN` secret | ||
|
||
See: **[lighthouse-server-docs](https://googlechrome.github.io/lighthouse-ci/docs/server.html)** | ||
|
||
|
||
## Metrics API Server | ||
#### Requires | ||
- postgres database | ||
- metabase *(for result visualization) | ||
|
||
|
||
#### Used by | ||
- Github Action - backend test to submit test metrics. | ||
|
||
Metrics API Server receives metrics collected during backend test and saves them to database. | ||
The results are visualized in metabase. | ||
|
||
### Initial Configuration | ||
- update `RECORD_METRICS_API` variable in file [.github/workflows/test_backend.yml](../../.github/workflows/test_backend.yml) | ||
|
||
|
||
**Source Code:** [tests/test-metrics-api](../test-metrics-api) | ||
|
||
## Kuber Server | ||
#### Requires | ||
- cardano-node's socket connection | ||
|
||
#### Used by | ||
- Cypress integration test | ||
- Governance Data Loader | ||
|
||
Opensource API server for transaction building and querying the ledger . | ||
Kuber makes it easy to construct and submit transaction from the frontend. | ||
|
||
**Docker Image:** [dquadrant/kuber:70be9b0166177eab5cf33e603fd3dc579e14cf31](https://hub.docker.com/layers/dquadrant/kuber/70be9b0166177eab5cf33e603fd3dc579e14cf31/images/sha256-d3b3f7c2304da8c4777155b26220238b682c81a3ff2b14753a5dc41c4f151364?context=explore) | ||
- lighthouse-{BASE_DOMAIN} | ||
- kuber-{BASE_DOMAIN} | ||
- metadata-{BASE_DOMAIN} | ||
- governance-{BASE_DOMAIN} | ||
|
||
### b. Prepare the machine. | ||
- Buy a virtual server | ||
- Install `docker` and enable `docker compose` plugin. | ||
- execute `docker swarm init` command. | ||
|
||
### c. One time setup on the machine. | ||
- Generate secrets and configurations required by the services | ||
`./gen-configs.sh` | ||
- Mark the nodes with labels to specify where the services should be run. In case of single node | ||
docker swarm, all labels can be set to single node. | ||
`./deploy.sh prepare` | ||
|
||
### d. Build images and deploy the stacks. | ||
- `./build-images.sh` | ||
- `./deploy.sh stack all` | ||
|
||
### Initial Configuration | ||
- update `CYPRESS_kuberApiUrl` variable in [.github/workflows/test_integration_cypress.yml](../../.github/workflows/test_integration_cypress.yml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
BASE_IMAGE_NAME=govtool | ||
export GOVTOOL_TAG="$(git rev-parse HEAD)" | ||
export PROJECT_NAME=govtool | ||
export CARDANO_NETWORK=sanchonet | ||
export BASE_DOMAIN=govtool.cardanoapi.io | ||
|
||
. ./scripts/deploy-stack.sh | ||
|
||
check_env | ||
|
||
# Build images | ||
./build-images.sh | ||
function update-service(){ | ||
docker service update --image "$2" "$1" | ||
} | ||
|
||
if [[ "$1" == "update-images" ]] | ||
|
||
update-service govtool_backend "$BASE_IMAGE_NAME"/backend:${GOVTOOL_TAG} | ||
update-service govtool_frontend "$BASE_IMAGE_NAME"/frontend:${GOVTOOL_TAG} | ||
update-service govtool_metadata-validation "$BASE_IMAGE_NAME"/metadata-validation:${GOVTOOL_TAG} | ||
|
||
update-service govaction-loader_backend "$BASE_IMAGE_NAME"/gov-action-loader-frontend:${GOVTOOL_TAG} | ||
update-service govaction-loader_frontend "$BASE_IMAGE_NAME"/gov-action-loader-backend:${GOVTOOL_TAG} | ||
|
||
elif [[ $1 == "full" ]] | ||
./deploy stack all | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
export BASE_IMAGE_NAME="govtool" | ||
# build the base image | ||
docker build -t "$BASE_IMAGE_NAME"/backend-base -f ../../govtool/backend/Dockerfile.base ../../govtool/backend | ||
BASE_IMAGE_EXISTS=$(docker images -q "$BASE_IMAGE_NAME"/backend-base 2> /dev/null) | ||
|
||
if [ -z "$BASE_IMAGE_EXISTS" ]; then | ||
echo "Building the base image..." | ||
docker build -t "$BASE_IMAGE_NAME"/backend-base -f ../../govtool/backend/Dockerfile.base ../../govtool/backend | ||
else | ||
echo "Base image already exists. Skipping build." | ||
fi | ||
|
||
docker compose -f ./docker-compose-govtool.yml build | ||
docker compose -f ./docker-compose.yml build | ||
docker compose -f ./docker-compose-govaction-loader.yml build |
8 changes: 4 additions & 4 deletions
8
tests/test-infrastructure/configs_template/postgres_db_setup.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CREATE database ${STACK_NAME}_lighthouse; | ||
CREATE database ${STACK_NAME}_metrics; | ||
CREATE database ${STACK_NAME}_sonarqube; | ||
CREATE database ${STACK_NAME}_dbsync; | ||
CREATE database ${PROJECT_NAME}_lighthouse; | ||
CREATE database ${PROJECT_NAME}_metrics; | ||
CREATE database ${PROJECT_NAME}_sonarqube; | ||
CREATE database ${PROJECßT_NAME}_dbsync; |
Oops, something went wrong.