refactor: use lowercase names for run environment and config files (#801)

This commit is contained in:
Sanchith Hegde
2023-04-18 00:33:01 +05:30
committed by GitHub
parent b4020294cc
commit ffaa8da0d2
13 changed files with 44 additions and 43 deletions

View File

@ -34,7 +34,7 @@ jobs:
with: with:
build-args: | build-args: |
BINARY=scheduler BINARY=scheduler
SCHEDULER_FLOW=Consumer SCHEDULER_FLOW=consumer
context: . context: .
push: true push: true
tags: juspaydotin/orca-consumer:${{ github.ref_name }} tags: juspaydotin/orca-consumer:${{ github.ref_name }}
@ -44,7 +44,7 @@ jobs:
with: with:
build-args: | build-args: |
BINARY=scheduler BINARY=scheduler
SCHEDULER_FLOW=Producer SCHEDULER_FLOW=producer
context: . context: .
push: true push: true
tags: juspaydotin/orca-producer:${{ github.ref_name }} tags: juspaydotin/orca-producer:${{ github.ref_name }}

View File

@ -6,11 +6,11 @@ on:
environment: environment:
description: "Environment to create image for" description: "Environment to create image for"
required: true required: true
default: "Sandbox" default: "sandbox"
type: choice type: choice
options: options:
- Sandbox - sandbox
- Production - production
multiple_mca: multiple_mca:
description: "Whether to enable the multiple_mca feature" description: "Whether to enable the multiple_mca feature"
required: true required: true
@ -53,7 +53,7 @@ jobs:
build-args: | build-args: |
RUN_ENV=${{ inputs.environment }} RUN_ENV=${{ inputs.environment }}
BINARY=scheduler BINARY=scheduler
SCHEDULER_FLOW=Consumer SCHEDULER_FLOW=consumer
context: . context: .
push: true push: true
tags: juspaydotin/orca-consumer:${{ github.sha }} tags: juspaydotin/orca-consumer:${{ github.sha }}
@ -64,7 +64,7 @@ jobs:
build-args: | build-args: |
RUN_ENV=${{ inputs.environment }} RUN_ENV=${{ inputs.environment }}
BINARY=scheduler BINARY=scheduler
SCHEDULER_FLOW=Producer SCHEDULER_FLOW=producer
context: . context: .
push: true push: true
tags: juspaydotin/orca-producer:${{ github.sha }} tags: juspaydotin/orca-producer:${{ github.sha }}

4
.gitignore vendored
View File

@ -249,8 +249,8 @@ logs/
**/*.log **/*.log
**/*.log.* **/*.log.*
monitoring/*.tmp/ monitoring/*.tmp/
config/Sandbox.toml config/sandbox.toml
config/Production.toml config/production.toml
!loadtest/.env !loadtest/.env
loadtest/*.tmp/ loadtest/*.tmp/

View File

@ -1,6 +1,6 @@
FROM rust:slim as builder FROM rust:slim as builder
ARG RUN_ENV=Sandbox ARG RUN_ENV=sandbox
ARG EXTRA_FEATURES="" ARG EXTRA_FEATURES=""
RUN apt-get update \ RUN apt-get update \
@ -33,9 +33,7 @@ ENV RUST_BACKTRACE="short"
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL="sparse" ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL="sparse"
COPY . . COPY . .
RUN cargo build --release --features ${RUN_ENV} ${EXTRA_FEATURES}
# Use bash variable substitution to convert environment name to lowercase
RUN bash -c 'cargo build --release --features ${RUN_ENV@L} ${EXTRA_FEATURES}'
@ -46,14 +44,14 @@ ARG CONFIG_DIR=/local/config
ARG BIN_DIR=/local/bin ARG BIN_DIR=/local/bin
# RUN_ENV decides the corresponding config file to be used # RUN_ENV decides the corresponding config file to be used
ARG RUN_ENV=Sandbox ARG RUN_ENV=sandbox
# args for deciding the executable to export. three binaries: # args for deciding the executable to export. three binaries:
# 1. BINARY=router - for main application # 1. BINARY=router - for main application
# 2. BINARY=scheduler, SCHEDULER_FLOW=Consumer - part of process tracker # 2. BINARY=scheduler, SCHEDULER_FLOW=consumer - part of process tracker
# 3. BINARY=scheduler, SCHEDULER_FLOW=Producer - part of process tracker # 3. BINARY=scheduler, SCHEDULER_FLOW=producer - part of process tracker
ARG BINARY=router ARG BINARY=router
ARG SCHEDULER_FLOW=Consumer ARG SCHEDULER_FLOW=consumer
RUN apt-get update \ RUN apt-get update \
&& apt-get install -y ca-certificates tzdata libpq-dev curl procps && apt-get install -y ca-certificates tzdata libpq-dev curl procps

View File

@ -148,8 +148,8 @@ impl Settings {
// 1. Defaults from the implementation of the `Default` trait. // 1. Defaults from the implementation of the `Default` trait.
// 2. Values from config file. The config file accessed depends on the environment // 2. Values from config file. The config file accessed depends on the environment
// specified by the `RUN_ENV` environment variable. `RUN_ENV` can be one of // specified by the `RUN_ENV` environment variable. `RUN_ENV` can be one of
// `Development`, `Sandbox` or `Production`. If nothing is specified for `RUN_ENV`, // `development`, `sandbox` or `production`. If nothing is specified for `RUN_ENV`,
// `/config/Development.toml` file is read. // `/config/development.toml` file is read.
// 3. Environment variables prefixed with `DRAINER` and each level separated by double // 3. Environment variables prefixed with `DRAINER` and each level separated by double
// underscores. // underscores.
// //

View File

@ -397,8 +397,8 @@ impl Settings {
// 1. Defaults from the implementation of the `Default` trait. // 1. Defaults from the implementation of the `Default` trait.
// 2. Values from config file. The config file accessed depends on the environment // 2. Values from config file. The config file accessed depends on the environment
// specified by the `RUN_ENV` environment variable. `RUN_ENV` can be one of // specified by the `RUN_ENV` environment variable. `RUN_ENV` can be one of
// `Development`, `Sandbox` or `Production`. If nothing is specified for `RUN_ENV`, // `development`, `sandbox` or `production`. If nothing is specified for `RUN_ENV`,
// `/config/Development.toml` file is read. // `/config/development.toml` file is read.
// 3. Environment variables prefixed with `ROUTER` and each level separated by double // 3. Environment variables prefixed with `ROUTER` and each level separated by double
// underscores. // underscores.
// //

View File

@ -3,7 +3,6 @@
use std::path::PathBuf; use std::path::PathBuf;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use strum::{Display, EnumString};
/// Environment variables accessed by the application. This module aims to be the source of truth /// Environment variables accessed by the application. This module aims to be the source of truth
/// containing all environment variable that the application accesses. /// containing all environment variable that the application accesses.
@ -11,7 +10,7 @@ pub mod vars {
/// Parent directory where `Cargo.toml` is stored. /// Parent directory where `Cargo.toml` is stored.
pub const CARGO_MANIFEST_DIR: &str = "CARGO_MANIFEST_DIR"; pub const CARGO_MANIFEST_DIR: &str = "CARGO_MANIFEST_DIR";
/// Environment variable that sets Development/Sandbox/Production environment. /// Environment variable that sets development/sandbox/production environment.
pub const RUN_ENV: &str = "RUN_ENV"; pub const RUN_ENV: &str = "RUN_ENV";
/// Directory of config TOML files. Default is `config`. /// Directory of config TOML files. Default is `config`.
@ -19,7 +18,11 @@ pub mod vars {
} }
/// Current environment. /// Current environment.
#[derive(Debug, Default, Deserialize, Serialize, Clone, Copy, Display, EnumString)] #[derive(
Debug, Default, Deserialize, Serialize, Clone, Copy, strum::Display, strum::EnumString,
)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum Env { pub enum Env {
/// Development environment. /// Development environment.
#[default] #[default]
@ -30,7 +33,7 @@ pub enum Env {
Production, Production,
} }
/// Name of current environment. Either "Development", "Sandbox" or "Production". /// Name of current environment. Either "development", "sandbox" or "production".
pub fn which() -> Env { pub fn which() -> Env {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
let default_env = Env::Development; let default_env = Env::Development;

View File

@ -123,8 +123,8 @@ impl Config {
// 1. Defaults from the implementation of the `Default` trait. // 1. Defaults from the implementation of the `Default` trait.
// 2. Values from config file. The config file accessed depends on the environment // 2. Values from config file. The config file accessed depends on the environment
// specified by the `RUN_ENV` environment variable. `RUN_ENV` can be one of // specified by the `RUN_ENV` environment variable. `RUN_ENV` can be one of
// `Development`, `Sandbox` or `Production`. If nothing is specified for `RUN_ENV`, // `development`, `sandbox` or `production`. If nothing is specified for `RUN_ENV`,
// `/config/Development.toml` file is read. // `/config/development.toml` file is read.
// 3. Environment variables prefixed with `ROUTER` and each level separated by double // 3. Environment variables prefixed with `ROUTER` and each level separated by double
// underscores. // underscores.
// //
@ -166,9 +166,9 @@ impl Config {
let config_directory = let config_directory =
std::env::var(crate::env::vars::CONFIG_DIR).unwrap_or_else(|_| "config".into()); std::env::var(crate::env::vars::CONFIG_DIR).unwrap_or_else(|_| "config".into());
let config_file_name = match environment { let config_file_name = match environment {
"Production" => "Production.toml", "production" => "production.toml",
"Sandbox" => "Sandbox.toml", "sandbox" => "sandbox.toml",
_ => "Development.toml", _ => "development.toml",
}; };
config_path.push(crate::env::workspace_path()); config_path.push(crate::env::workspace_path());

View File

@ -400,16 +400,16 @@ The application configuration files are present under the
The configuration file read varies with the environment: The configuration file read varies with the environment:
- Development: [`config/Development.toml`][config-development] - Development: [`config/development.toml`][config-development]
- Sandbox: `config/Sandbox.toml` - Sandbox: `config/sandbox.toml`
- Production: `config/Production.toml` - Production: `config/production.toml`
Refer to [`config.example.toml`][config-example] for all the available Refer to [`config.example.toml`][config-example] for all the available
configuration options. configuration options.
Refer to [`Development.toml`][config-development] for the recommended defaults for Refer to [`development.toml`][config-development] for the recommended defaults for
local development. local development.
Ensure to update the [`Development.toml`][config-development] file if you opted Ensure to update the [`development.toml`][config-development] file if you opted
to use different database credentials as compared to the sample ones included in to use different database credentials as compared to the sample ones included in
this guide. this guide.
@ -417,7 +417,7 @@ Once you're done with configuring the application, proceed with
[running the application](#run-the-application). [running the application](#run-the-application).
[config-directory]: /config [config-directory]: /config
[config-development]: /config/Development.toml [config-development]: /config/development.toml
[config-example]: /config/config.example.toml [config-example]: /config/config.example.toml
[config-docker-compose]: /config/docker_compose.toml [config-docker-compose]: /config/docker_compose.toml
@ -463,7 +463,7 @@ Once you're done with configuring the application, proceed with
[`config/docker_compose.toml`][config-docker-compose], search for [`config/docker_compose.toml`][config-docker-compose], search for
`admin_api_key` to find the admin API key. `admin_api_key` to find the admin API key.
2. If you set up the dependencies locally, you can find the configuration 2. If you set up the dependencies locally, you can find the configuration
file at [`config/Development.toml`][config-development], search for file at [`config/development.toml`][config-development], search for
`admin_api_key` to find the admin API key `admin_api_key` to find the admin API key
4. Open the ["Quick Start" folder][quick-start] in the collection. 4. Open the ["Quick Start" folder][quick-start] in the collection.

View File

@ -42,13 +42,13 @@ services:
- -c - -c
- | - |
./diesel migration run ./diesel migration run
./router -f /config/Development.toml ./router -f /config/development.toml
ports: ports:
- "8080" - "8080"
environment: environment:
DATABASE_URL: postgres://postgres:postgres@db/loadtest_router DATABASE_URL: postgres://postgres:postgres@db/loadtest_router
RUST_LOG: INFO RUST_LOG: INFO
RUN_ENV: Development RUN_ENV: development
OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4317 OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4317
networks: networks:
- loadtest_net - loadtest_net

View File

@ -41,7 +41,7 @@ cd $SCRIPT/..
# remove template files if already created for this connector # remove template files if already created for this connector
rm -rf $conn/$pg $conn/$pg.rs rm -rf $conn/$pg $conn/$pg.rs
git checkout $conn.rs $src/types/api.rs $src/configs/settings.rs config/Development.toml config/docker_compose.toml config/config.example.toml loadtest/config/Development.toml crates/api_models/src/enums.rs $src/core/payments/flows.rs git checkout $conn.rs $src/types/api.rs $src/configs/settings.rs config/development.toml config/docker_compose.toml config/config.example.toml loadtest/config/development.toml crates/api_models/src/enums.rs $src/core/payments/flows.rs
# add enum for this connector in required places # add enum for this connector in required places
prvc='' prvc=''
@ -51,14 +51,14 @@ sed -i'' -e "s|pub mod $prvc;|pub mod $prvc;\npub mod ${pg};|" $conn.rs
sed -i'' -e "s/};/${pg}::${pgc},\n};/" $conn.rs sed -i'' -e "s/};/${pg}::${pgc},\n};/" $conn.rs
sed -i'' -e "s|\"$prvc\" \(.*\)|\"$prvc\" \1\n\t\t\t\"${pg}\" => Ok(Box::new(\&connector::${pgc})),|" $src/types/api.rs sed -i'' -e "s|\"$prvc\" \(.*\)|\"$prvc\" \1\n\t\t\t\"${pg}\" => Ok(Box::new(\&connector::${pgc})),|" $src/types/api.rs
sed -i'' -e "s/pub $prvc: \(.*\)/pub $prvc: \1\n\tpub ${pg}: ConnectorParams,/" $src/configs/settings.rs sed -i'' -e "s/pub $prvc: \(.*\)/pub $prvc: \1\n\tpub ${pg}: ConnectorParams,/" $src/configs/settings.rs
sed -i'' -e "s|$prvc.base_url \(.*\)|$prvc.base_url \1\n${pg}.base_url = \"$base_url\"|" config/Development.toml config/docker_compose.toml config/config.example.toml loadtest/config/Development.toml sed -i'' -e "s|$prvc.base_url \(.*\)|$prvc.base_url \1\n${pg}.base_url = \"$base_url\"|" config/development.toml config/docker_compose.toml config/config.example.toml loadtest/config/development.toml
sed -r -i'' -e "s/\"$prvc\",/\"$prvc\",\n \"${pg}\",/" config/Development.toml config/docker_compose.toml config/config.example.toml loadtest/config/Development.toml sed -r -i'' -e "s/\"$prvc\",/\"$prvc\",\n \"${pg}\",/" config/development.toml config/docker_compose.toml config/config.example.toml loadtest/config/development.toml
sed -i'' -e "s/Dummy,/Dummy,\n\t${pgc},/" crates/api_models/src/enums.rs sed -i'' -e "s/Dummy,/Dummy,\n\t${pgc},/" crates/api_models/src/enums.rs
sed -i'' -e "s/pub enum RoutableConnectors {/pub enum RoutableConnectors {\n\t${pgc},/" crates/api_models/src/enums.rs sed -i'' -e "s/pub enum RoutableConnectors {/pub enum RoutableConnectors {\n\t${pgc},/" crates/api_models/src/enums.rs
sed -i'' -e "s/^default_imp_for_\(.*\)/default_imp_for_\1\n\tconnector::${pgc},/" $src/core/payments/flows.rs sed -i'' -e "s/^default_imp_for_\(.*\)/default_imp_for_\1\n\tconnector::${pgc},/" $src/core/payments/flows.rs
# remove temporary files created in above step # remove temporary files created in above step
rm $conn.rs-e $src/types/api.rs-e $src/configs/settings.rs-e config/Development.toml-e config/docker_compose.toml-e config/config.example.toml-e loadtest/config/Development.toml-e crates/api_models/src/enums.rs-e $src/core/payments/flows.rs-e rm $conn.rs-e $src/types/api.rs-e $src/configs/settings.rs-e config/development.toml-e config/docker_compose.toml-e config/config.example.toml-e loadtest/config/development.toml-e crates/api_models/src/enums.rs-e $src/core/payments/flows.rs-e
cd $conn/ cd $conn/
# generate template files for the connector # generate template files for the connector