Skip to content

Commit

Permalink
chore: env file gen (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
mishraomp authored Jan 15, 2025
1 parent 21e3fb1 commit b0e97c1
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 13 deletions.
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Organics Info (ORI) - OMRR Transparency Initiative

Organics Info (ORI) shares information on authorized biosolids land application and compost facilities regulated under the Organic Matter Recycling Regulation (OMRR) in BC.
Organics Info (ORI) shares information on authorized biosolids land application and compost facilities regulated under the Organic Matter Recycling Regulation (OMRR) in BC.

This project is part of the OMRR Transparency Enhancement Initiative led by the Environmental Policy and Initiatives Branch (EPIB) in the Ministry of Environment and Climate Change Strategy.

Expand All @@ -20,7 +20,8 @@ We have [architecture diagrams](.diagrams/architecture) the document the technol

# Getting Started

Here is high-level documentation on the development of applications, use of GitHub, and Openshift in the Government of BC:
Here is high-level documentation on the development of applications, use of GitHub, and Openshift in the Government of BC:

- ["Working in github.com/bcgov" Cheatsheet](https://github.com/bcgov/BC-Policy-Framework-For-GitHub/blob/master/BC-Gov-Org-HowTo/Cheatsheet.md)
- [DevHub DC Developer guide](https://developer.gov.bc.ca/docs/default/component/bc-developer-guide/)
- [DevHub Openshift documentation](https://developer.gov.bc.ca/docs/default/component/platform-developer-docs)
Expand All @@ -31,20 +32,15 @@ Pre-requisites:

- Node.js installed on the machine
- Access to OpenShift namespace for Organics Info (ORI) project
- OC CLI installed.(https://console.apps.silver.devops.gov.bc.ca/command-line-tools)
- .env file is created in the backend folder based on the .env.sample file, the values can be retrieved from secrets in
OpenShift namespace:
- `NR_ORACLE_SERVICE_URL=http://localhost:9080`
- `NR_ORACLE_SERVICE_KEY` value is the `apiKey` value in the [nr-oracle-service dev project](https://console.apps.silver.devops.gov.bc.ca/k8s/ns/d37bb7-dev/secrets/nr-oracle-service)
- The `OS_` values can be found in the [nr-epd-organics-info-prod project](https://console.apps.silver.devops.gov.bc.ca/k8s/ns/d37bb7-prod/secrets/nr-epd-organics-info-prod)
- OC CLI installed.(https://console.apps.silver.devops.gov.bc.ca/command-line-tools) and is on path.
- Copy the .env.sample in frontend and paste it as .env and update the value of `VITE_API_URL=http://localhost:3000`
- Run the [env generator for windows](./utils/env-gen.ps1) or [env generator for linux](./utils/env-gen.sh), it will generate the backend/.env file

Steps:

1. Open a terminal, run the oc login command and switch to the namespace where the application is deployed.
- The oc login command can be found by logging into [OpenShift](https://console.apps.silver.devops.gov.bc.ca/)
- Clicking on your name in the top right corner and choose `Copy login command`
- Then choose `Developer Log In` and click `Display Token`
- Then copy the `oc login ...` command
1. Open a terminal, run the following command
- `oc login --server=https://api.silver.devops.gov.bc.ca:6443 --web`
- switch to namespace `oc project d37bb7-dev`
2. Run the following command in terminal `oc port-forward service/nr-oracle-service 9080:80`, this enables access to nr
oracle service on port 9080 of local machine.
3. Run the following command in terminal `cd backend && npm install && npm run start:debug`, this will start the backend
Expand Down
3 changes: 3 additions & 0 deletions utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Utilities

This folder contains some utilities for the project.
41 changes: 41 additions & 0 deletions utils/env-gen.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<#
.SYNOPSIS
This script is an environment generator for backend.
.DESCRIPTION
This script sets up the necessary environment variables and configurations required for the backend system to function properly.
.EXAMPLE
# To run this script, use the following command:
# .\env-gen.ps1 "
#>
$file_path = "$PSScriptRoot/../backend/.env"

# Log in to OpenShift
Start-Process "oc" -Wait -ArgumentList "login --server=https://api.silver.devops.gov.bc.ca:6443 --web"


#switch to dev,
oc project d37bb7-dev

# Get the secret data
$secretData = oc get secret nr-oracle-service -n d37bb7-dev -o json | ConvertFrom-Json

# Decode the secret data and create the .env file
$envContent = ""
foreach ($key in $secretData.data.PSObject.Properties.Name) {
if ($key -eq "apiKey") {
$decodedValue = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secretData.data.$key))
$envContent += "NR_ORACLE_SERVICE_KEY=$decodedValue`n"
}
}
$envContent += "NR_ORACLE_SERVICE_URL=http://localhost:9080`n"
$envContent += "OMRR_AUTHZ_DOCS_FLAG=true`n"
$envContent += "OMRR_APP_STATUS_FLAG=flase"
# Write the content to the output file
$envContent | Out-File -FilePath "$file_path" -Encoding utf8


Write-Host "Environment file created at $file_path"
28 changes: 28 additions & 0 deletions utils/env-gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# Set file path relative to script location
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FILE_PATH="${SCRIPT_DIR}/../backend/.env"
echo "Creating environment file at $FILE_PATH"
# Log in to OpenShift
oc login --server=https://api.silver.devops.gov.bc.ca:6443 --web

# Switch to dev project
oc project d37bb7-dev

# Get the secret data and process with jq
SECRET_DATA=$(oc get secret nr-oracle-service -n d37bb7-dev -o json)

# Initialize env content
ENV_CONTENT=""

# Extract and decode apiKey
API_KEY=$(echo "$SECRET_DATA" | jq -r '.data.apiKey' | base64 -d)
ENV_CONTENT="NR_ORACLE_SERVICE_KEY=$API_KEY
NR_ORACLE_SERVICE_URL=http://localhost:9080
OMRR_AUTHZ_DOCS_FLAG=true
OMRR_APP_STATUS_FLAG=flase"

# Write content to .env file
echo "$ENV_CONTENT" > "$FILE_PATH"

echo "Environment file created at $FILE_PATH"

0 comments on commit b0e97c1

Please sign in to comment.