Skip to content

Commit

Permalink
Merge pull request #244 from xeptagondev/develop
Browse files Browse the repository at this point in the history
Sprint changes 47
  • Loading branch information
mbelinsky authored Dec 19, 2023
2 parents 16e6e19 + 6cd3668 commit 3ee5433
Show file tree
Hide file tree
Showing 71 changed files with 483 additions and 1,741 deletions.
35 changes: 17 additions & 18 deletions .github/workflows/frontend-deployment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,27 @@ jobs:
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# - name: Build, tag, and push the image to Amazon ECR
# id: build-image
# env:
# ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
# ECR_REPOSITORY: carbon-web
# IMAGE_TAG: v1
# run: |
# # Build a docker container and push it to ECR
# docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f web/Dockerfile . --build-arg PORT=3030 --build-arg REACT_APP_BACKEND=https://test.carbreg.org:3000 --build-arg REACT_APP_STAT_URL=https://test.carbreg.org:3100 --build-arg COUNTRY_NAME="CountryX" --build-arg COUNTRY_FLAG_URL="https://carbon-common-dev.s3.amazonaws.com/flag.png" --build-arg COUNTRY_CODE="NG" --build-arg REACT_APP_MAP_TYPE="Mapbox" --build-arg REACT_APP_MAPBOXGL_ACCESS_TOKEN=${{ secrets.MAPBOXGL_ACCESS_TOKEN }} --build-arg NGINX_CONFIG="nginx_prod.conf"
# echo "Pushing image to ECR..."
# docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
# echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Build, tag, and push the image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: carbon-web
IMAGE_TAG: v1
IMAGE_TAG: develop
run: |
# Build a docker container and push it to ECR
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f web/Dockerfile . --build-arg PORT=3030 --build-arg REACT_APP_BACKEND=https://test.carbreg.org:3000 --build-arg REACT_APP_STAT_URL=https://test.carbreg.org:3100 --build-arg COUNTRY_NAME="CountryX" --build-arg COUNTRY_FLAG_URL="https://carbon-common-dev.s3.amazonaws.com/flag.png" --build-arg COUNTRY_CODE="NG" --build-arg REACT_APP_MAP_TYPE="Mapbox" --build-arg REACT_APP_MAPBOXGL_ACCESS_TOKEN=${{ secrets.MAPBOXGL_ACCESS_TOKEN }} --build-arg NGINX_CONFIG="nginx_prod.conf"
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f web/Dockerfile . --build-arg PORT=3030 --build-arg REACT_APP_BACKEND=http://localhost:3000 --build-arg REACT_APP_STAT_URL=http://localhost:3100 --build-arg COUNTRY_NAME="CountryX" --build-arg COUNTRY_FLAG_URL="https://carbon-common-dev.s3.amazonaws.com/flag.png" --build-arg COUNTRY_CODE="NG" --build-arg REACT_APP_MAP_TYPE="Mapbox" --build-arg REACT_APP_MAPBOXGL_ACCESS_TOKEN=${{ secrets.MAPBOXGL_ACCESS_TOKEN }}
echo "Pushing image to ECR..."
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
Expand All @@ -77,7 +89,7 @@ jobs:
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: carbon-web
IMAGE_TAG: v1
IMAGE_TAG: develop
PRIVATE_KEY: ${{ secrets.AWS_SSH_KEY_PRIVATE }}
HOSTNAME: ${{secrets.HOST_IP}}
USER_NAME: ec2-user
Expand All @@ -86,19 +98,6 @@ jobs:
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} '
cd repos/carbon-registry &&
sudo $(aws ecr get-login --no-include-email --region us-east-1) &&
sudo docker stop carbon-registry-web-1 || true &&
sudo docker rm carbon-registry-web-1 &&
sudo docker pull 302213478610.dkr.ecr.us-east-1.amazonaws.com/carbon-web:v1 &&
(docker stop carbon-registry-web-1 > /dev/null && docker rm carbon-registry-web-1 ) 2>/dev/null || true &&
sudo docker pull 302213478610.dkr.ecr.us-east-1.amazonaws.com/carbon-web:develop &&
docker compose -f docker-compose-image.yml up -d web '
- name: Build, tag, and push the QA-develop image to Amazon ECR
id: build-image-develop
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: carbon-web
IMAGE_TAG: develop
run: |
# Build a docker container and push it to ECR
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f web/Dockerfile . --build-arg PORT=3030 --build-arg REACT_APP_BACKEND=http://localhost:3000 --build-arg REACT_APP_STAT_URL=http://localhost:3100 --build-arg COUNTRY_NAME="CountryX" --build-arg COUNTRY_FLAG_URL="https://carbon-common-dev.s3.amazonaws.com/flag.png" --build-arg COUNTRY_CODE="NG" --build-arg REACT_APP_MAP_TYPE="Mapbox" --build-arg REACT_APP_MAPBOXGL_ACCESS_TOKEN=${{ secrets.MAPBOXGL_ACCESS_TOKEN }}
echo "Pushing image to ECR..."
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
12 changes: 6 additions & 6 deletions .github/workflows/server-deployments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ jobs:
run: |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} '
cd repos/carbon-registry &&
sudo $(aws ecr get-login --no-include-email --region us-east-1) &&
sudo docker stop carbon-registry-national-1 carbon-registry-replicator-1 carbon-registry-stats-1 || true &&
sudo docker rm carbon-registry-national-1 carbon-registry-replicator-1 carbon-registry-stats-1 &&
sudo docker pull 302213478610.dkr.ecr.us-east-1.amazonaws.com/carbon-services:develop &&
docker compose -f docker-compose-image.yml up -d national stats replicator '
repos/carbon-registry/backend_deploy.sh '
# cd repos/carbon-registry &&
# sudo $(aws ecr get-login --no-include-email --region us-east-1) &&
# (docker stop carbon-registry-national-1 carbon-registry-replicator-1 carbon-registry-stats-1 > /dev/null && docker rm carbon-registry-national-1 carbon-registry-replicator-1 carbon-registry-stats-1 ) 2>/dev/null || true &&
# sudo docker pull 302213478610.dkr.ecr.us-east-1.amazonaws.com/carbon-services:develop &&
# docker compose -f docker-compose-image.yml up -d national stats replicator '
# automated-api-tests:
# runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ backend/services/.env.local
./data/*
!./data/README.md
.yalc
yalc.lock
yalc.lock
web/public/locales/*
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

The National Carbon Registry enables carbon credit trading in order to reduce greenhouse gas emissions.

As an online database, the National Carbon Registry uses national and international standards for quantifying and verifying greenhouse gas emissions reductions by programmes, tracking issued carbon credits and enabling credit transfers in an efficient and transparent manner. The Registry functions by receiving, processing, recording and storing data on mitigations projects, the issuance, holding, transfer, acquisition, cancellation, and retirement of emission reduction credits. This information is publicly accessible to increase public confidence in the emissions reduction agenda.
As an online database, the National Carbon Registry uses national and international standards for quantifying and verifying greenhouse gas emissions reductions by projects, tracking issued carbon credits and enabling credit transfers in an efficient and transparent manner. The Registry functions by receiving, processing, recording and storing data on mitigations projects, the issuance, holding, transfer, acquisition, cancellation, and retirement of emission reduction credits. This information is publicly accessible to increase public confidence in the emissions reduction agenda.

The National Carbon Registry enables carbon credit tracking transactions from mitigation activities, as the digital implementation of the Paris Agreement. Any country can customize and deploy a local version of the registry then connect it to other national & international registries, MRV systems, and more.

Expand Down Expand Up @@ -60,11 +60,11 @@ UNDP Carbon Registry is based on service oriented architecture (SOA). Following

### National Service

Authenticate, Validate and Accept user (Government, Programme Developer/Certifier) API requests related to the following functionalities,
Authenticate, Validate and Accept user (Government, Project Developer/Certifier) API requests related to the following functionalities,

* User and company CRUD operations.
* User authentication.
* Programme life cycle management.
* Project life cycle management.
* Credit life cycle management.

Service is horizontally scalable and state maintained in the following locations,
Expand All @@ -73,8 +73,8 @@ Service is horizontally scalable and state maintained in the following locations
* Operational Database.
* Ledger Database.

Uses the Carbon Credit Calculator and Serial Number Generator node modules to estimate the programme carbon credit amount and issue a serial number.
Uses Ledger interface to persist programme and credit life cycles.
Uses the Carbon Credit Calculator and Serial Number Generator node modules to estimate the project carbon credit amount and issue a serial number.
Uses Ledger interface to persist project and credit life cycles.

### Analytics Service

Expand Down Expand Up @@ -122,8 +122,8 @@ Change by environment variable `FILE_SERVICE`. Supported types are `LOCAL` (defa

### **Database Architecture**

Primary/secondary database architecture used to store carbon programme and account balances.
Ledger database is the primary database. Add/update programmes and update account balances in a single transaction. Currently implemented only for AWS QLDB
Primary/secondary database architecture used to store carbon project and account balances.
Ledger database is the primary database. Add/update projects and update account balances in a single transaction. Currently implemented only for AWS QLDB

Operational Database is the secondary database. Eventually replicated to this from primary database via data stream. Implemented based on PostgreSQL

Expand All @@ -135,7 +135,7 @@ Operational Database is the secondary database. Eventually replicated to this fr

#### Why Ledger Database?

1. Immutable and Transparent - Track and maintain a sequenced history of every carbon programme and credit change.
1. Immutable and Transparent - Track and maintain a sequenced history of every carbon project and credit change.
2. Data Integrity (Cryptographic verification by third party).
3. Reconcile carbon credits and company account balance.

Expand All @@ -145,19 +145,19 @@ This enables the capability to add any blockchain or ledger database support to

#### PostgreSQL Ledger Implementation

This ledger implementation stores all the carbon programme and credit events in a separate event database with the sequence number. Support all the ledger functionalities except immutability.
This ledger implementation stores all the carbon project and credit events in a separate event database with the sequence number. Support all the ledger functionalities except immutability.

Single database approach used for user and company management.

### **Ledger Layout**

Carbon Registry contains 3 ledger tables.

1. Programme ledger - Contains all the programme and credit transactions.
1. Project ledger - Contains all the project and credit transactions.
2. Company Account Ledger (Credit) - Contains company accounts credit transactions.
3. Country Account Ledger (Credit) - Contains country credit transactions.

The below diagram demonstrates the ledger behavior of programme create, authorise, issue and transfer processes. Blue color document icon denotes a single data block in a ledger.
The below diagram demonstrates the ledger behavior of project create, authorise, issue and transfer processes. Blue color document icon denotes a single data block in a ledger.

![Ledger Layout](./documention/imgs/Ledger.svg)

Expand All @@ -184,7 +184,7 @@ The below diagram demonstrates the ledger behavior of programme create, authoris
├── serverless.yml # Service deployment scripts [Serverless + AWS Lambda]
├── libs
├── carbon-credit-calculator # Implementation for the Carbon credit calculation library [Node module + Typescript]
├── serial-number-gen # Implementation for the carbon programme serial number calculation [Node module + Typescript]
├── serial-number-gen # Implementation for the carbon project serial number calculation [Node module + Typescript]
├── web # System web frontend implementation [ReactJS]
├── .gitignore
├── docker-compose.yml # Docker container definitions
Expand All @@ -205,7 +205,7 @@ The below diagram demonstrates the ledger behavior of programme create, authoris
* `SMTP_PASSWORD`
* Use `DB_PASSWORD` env variable to change PostgreSQL database password
* Configure system root account email by updating environment variable `ROOT EMAIL`. If the email service is enabled, on the first docker start, this email address will receive a new email with the root user password.
* By default frontend does not show map images on dashboard and programme view. To enable them please update `REACT_APP_MAP_TYPE` env variable to `Mapbox` and add new env variable `REACT_APP_MAPBOXGL_ACCESS_TOKEN` with [MapBox public access token](https://docs.mapbox.com/help/tutorials/get-started-tokens-api/) in web container.
* By default frontend does not show map images on dashboard and project view. To enable them please update `REACT_APP_MAP_TYPE` env variable to `Mapbox` and add new env variable `REACT_APP_MAPBOXGL_ACCESS_TOKEN` with [MapBox public access token](https://docs.mapbox.com/help/tutorials/get-started-tokens-api/) in web container.
* Add user data
* Update [organisations.csv](./organisations.csv) file to add organisations.
* Update [users.csv](./users.csv) file to add users.
Expand Down Expand Up @@ -304,7 +304,7 @@ Web frontend implemented using ReactJS framework. Please refer [getting started
* Languages (Current): English
* Languages (In progress): French, Spanish

For updating translations or adding new ones, reference <https://github.com/undp/carbon-registry/tree/main/web/public/Assets/i18n>
Please refer [here](./web/public/locales/i18n/README.md) for adding a new language translation file.

<a name="api"></a>

Expand Down
2 changes: 1 addition & 1 deletion backend/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@nestjs/swagger": "^6.1.3",
"@nestjs/typeorm": "^9.0.1",
"@undp/carbon-credit-calculator": "^1.1.1",
"@undp/carbon-services-lib": "0.0.250",
"@undp/carbon-services-lib": "0.0.293",
"@undp/serial-number-gen": "^1.0.0",
"amazon-qldb-driver-nodejs": "^3.0.1",
"aws-kinesis-agg": "^4.2.6",
Expand Down
4 changes: 2 additions & 2 deletions backend/services/src/i18n/en/creditCertification.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"certifyPendingProgramme": "The programme has been certified successfully",
"certifyPendingProgramme": "The project has been certified successfully",
"certifyRejectedProgramme": "This action is unauthorised",
"certifyProgrammeAlreadyCertifiedBySameCertifier": "This programme has already been certified",
"certifyProgrammeAlreadyCertifiedBySameCertifier": "This project has already been certified",
"unAuthorizedCertification": "This action is unauthorised",
"certificationRevocation": "The certificate has been revoked successfully"
}
Loading

0 comments on commit 3ee5433

Please sign in to comment.