Hasan Iqbal
commited on
Added terraform skeleton code
Browse files- accounts/hasaniqbal-ds.backend.conf +6 -0
- accounts/hasaniqbal-ds.tfvars.json +6 -0
- deployments/terraform/.terraform-version +1 -0
- deployments/terraform/.terraform.lock.hcl +44 -0
- deployments/terraform/aws_dynamodb.tf +31 -0
- deployments/terraform/main.tf +93 -0
- deployments/terraform/terraform-apply.sh +66 -0
- environments/integration.json +6 -0
- environments/production.json +6 -0
- scripts/cli.sh +2 -1
- scripts/deploy.sh +236 -0
- src/openfactcheck/utils/logging.py +1 -1
accounts/hasaniqbal-ds.backend.conf
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
bucket = "hasaniqbal-ds-terraform-state"
|
2 |
+
region = "us-east-1"
|
3 |
+
encrypt = true
|
4 |
+
kms_key_id = "alias/terraform-state-bucket-key"
|
5 |
+
dynamodb_table = "hasaniqbal-ds-terraform-lock"
|
6 |
+
profile = "ds"
|
accounts/hasaniqbal-ds.tfvars.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"aws_account_name": "hasaniqbal-ds",
|
3 |
+
"aws_account": "252286678527",
|
4 |
+
"aws_region": "us-east-1",
|
5 |
+
"aws_profile": "ds"
|
6 |
+
}
|
deployments/terraform/.terraform-version
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
1.9.5
|
deployments/terraform/.terraform.lock.hcl
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This file is maintained automatically by "terraform init".
|
2 |
+
# Manual edits may be lost in future updates.
|
3 |
+
|
4 |
+
provider "registry.terraform.io/hashicorp/aws" {
|
5 |
+
version = "5.64.0"
|
6 |
+
constraints = "~> 5.64.0"
|
7 |
+
hashes = [
|
8 |
+
"h1:YH4I78rsS9t+YoGMPNzrM53aWi0Rb9Nud16iusrSXMg=",
|
9 |
+
"zh:1d361f8062c68c9d5ac14b0aa8390709542129b8a9b258e61bbbabc706078b44",
|
10 |
+
"zh:39dcbf53e3896bdd77071384c8fad4a5862c222c73f3bcf356aca488101f22fd",
|
11 |
+
"zh:3fad63505f0c5b6f01cc9a6ef02b2226983b79424126a9caf6eb724f654299f4",
|
12 |
+
"zh:53a8b90d00829cc27e3171a13a8ff1404ee0ea018e73f31d3f916d246cc39613",
|
13 |
+
"zh:5734c25ef5a04b40f3c1ac5f817f11e42ee3328f74dbc141c0e64afbb0acc834",
|
14 |
+
"zh:66ea14dbd87f291ce4a877123363933d3ca4022f209f885807a6689c22c24e80",
|
15 |
+
"zh:68e79654ad0894a3d93134c3377748ace3058d5fad5ec09d1e9a8f8f9b8a47ea",
|
16 |
+
"zh:7b74259d0ceef0c49cea6bcd171df997b6bad141085bbadded15b440faeb0eee",
|
17 |
+
"zh:988ebfb5d115dc57070b5abf2e4200ad49cde535f27fd2ba5e34cf9ab336a57f",
|
18 |
+
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
|
19 |
+
"zh:a0a2d4efe2835f0101a0a5024e044a3f28c00e10a8d87fce89c707ef6db75cea",
|
20 |
+
"zh:aecb3e4b9121771dee9cac7975bf5d0657b5f3e8b57788c455beaeb0f3c48d93",
|
21 |
+
"zh:d2d3393170b8ef761d3146f39f6788c4a3e876e6c5d4cedca4870c2680688ae6",
|
22 |
+
"zh:daba5a005c1baa4a5eefbfb86d43ccf880eb5b42e8136f0d932f55886d72bda0",
|
23 |
+
"zh:de16a6ff3baacdaf9609a0a89aa1913fc19cccaf5ee0fc1c49c5a075baa47c02",
|
24 |
+
]
|
25 |
+
}
|
26 |
+
|
27 |
+
provider "registry.terraform.io/hashicorp/local" {
|
28 |
+
version = "2.5.1"
|
29 |
+
hashes = [
|
30 |
+
"h1:/GAVA/xheGQcbOZEq0qxANOg+KVLCA7Wv8qluxhTjhU=",
|
31 |
+
"zh:0af29ce2b7b5712319bf6424cb58d13b852bf9a777011a545fac99c7fdcdf561",
|
32 |
+
"zh:126063ea0d79dad1f68fa4e4d556793c0108ce278034f101d1dbbb2463924561",
|
33 |
+
"zh:196bfb49086f22fd4db46033e01655b0e5e036a5582d250412cc690fa7995de5",
|
34 |
+
"zh:37c92ec084d059d37d6cffdb683ccf68e3a5f8d2eb69dd73c8e43ad003ef8d24",
|
35 |
+
"zh:4269f01a98513651ad66763c16b268f4c2da76cc892ccfd54b401fff6cc11667",
|
36 |
+
"zh:51904350b9c728f963eef0c28f1d43e73d010333133eb7f30999a8fb6a0cc3d8",
|
37 |
+
"zh:73a66611359b83d0c3fcba2984610273f7954002febb8a57242bbb86d967b635",
|
38 |
+
"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3",
|
39 |
+
"zh:7ae387993a92bcc379063229b3cce8af7eaf082dd9306598fcd42352994d2de0",
|
40 |
+
"zh:9e0f365f807b088646db6e4a8d4b188129d9ebdbcf2568c8ab33bddd1b82c867",
|
41 |
+
"zh:b5263acbd8ae51c9cbffa79743fbcadcb7908057c87eb22fd9048268056efbc4",
|
42 |
+
"zh:dfcd88ac5f13c0d04e24be00b686d069b4879cc4add1b7b1a8ae545783d97520",
|
43 |
+
]
|
44 |
+
}
|
deployments/terraform/aws_dynamodb.tf
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ##############################################################################
|
2 |
+
# DynamoDB Table - Default
|
3 |
+
# ##############################################################################
|
4 |
+
resource "aws_dynamodb_table" "openfactcheck_default" {
|
5 |
+
name = "openfactcheck-db-${terraform.workspace}-${var.aws_region}"
|
6 |
+
|
7 |
+
billing_mode = "PAY_PER_REQUEST"
|
8 |
+
hash_key = "PK"
|
9 |
+
|
10 |
+
global_secondary_index {
|
11 |
+
name = "gs1"
|
12 |
+
hash_key = "GS1PK"
|
13 |
+
projection_type = "ALL"
|
14 |
+
}
|
15 |
+
|
16 |
+
// ID
|
17 |
+
attribute {
|
18 |
+
name = "PK"
|
19 |
+
type = "S"
|
20 |
+
}
|
21 |
+
|
22 |
+
// Type
|
23 |
+
attribute {
|
24 |
+
name = "GS1PK"
|
25 |
+
type = "S"
|
26 |
+
}
|
27 |
+
|
28 |
+
tags = {
|
29 |
+
Name = "OpenFactCheck - DynamoDB - ${terraform.workspace} - ${var.aws_region}"
|
30 |
+
}
|
31 |
+
}
|
deployments/terraform/main.tf
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ##############################################################################
|
2 |
+
# Snippet to require usage of a 'non-default' workspace.
|
3 |
+
# ##############################################################################
|
4 |
+
data "local_file" "is_default_workspace" {
|
5 |
+
count = terraform.workspace == "default" ? 1 : 0
|
6 |
+
filename = "ERROR: Workspace does not match given environment name!"
|
7 |
+
}
|
8 |
+
|
9 |
+
# ##############################################################################
|
10 |
+
# Backend
|
11 |
+
# ##############################################################################
|
12 |
+
terraform {
|
13 |
+
backend "s3" {
|
14 |
+
key = "openfactcheck/terraform.tfstat"
|
15 |
+
workspace_key_prefix = "openfactcheck"
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
+
# ##############################################################################
|
20 |
+
# Terraform and Provider Requirements
|
21 |
+
# ##############################################################################
|
22 |
+
terraform {
|
23 |
+
required_version = "~>1.9.5"
|
24 |
+
|
25 |
+
required_providers {
|
26 |
+
aws = {
|
27 |
+
source = "hashicorp/aws"
|
28 |
+
version = "~>5.64.0"
|
29 |
+
}
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
provider "aws" {
|
34 |
+
region = var.aws_region
|
35 |
+
profile = var.aws_profile
|
36 |
+
allowed_account_ids = [var.aws_account]
|
37 |
+
|
38 |
+
default_tags {
|
39 |
+
# tags holds the default tags applied to all resources.
|
40 |
+
# Individual resources should override Name and Function,
|
41 |
+
# (as well as anything else they find appropriate).
|
42 |
+
tags = {
|
43 |
+
Name = "OpenFactCheck - ${terraform.workspace} - ${var.aws_region}"
|
44 |
+
Group = "OpenFactCheck - ${terraform.workspace}"
|
45 |
+
Owner = "OpenFactCheck Team"
|
46 |
+
Purpose = "LLM Factuality Evaluation Framework - ${terraform.workspace} - ${var.aws_region}"
|
47 |
+
Function = "App"
|
48 |
+
Environment = terraform.workspace
|
49 |
+
Criticality = "High"
|
50 |
+
TTL = "2021-06-01"
|
51 |
+
MangedBy = "terraform"
|
52 |
+
Business_Unit = "Infrastructure"
|
53 |
+
Region = var.aws_region
|
54 |
+
}
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
data "aws_caller_identity" "current" {}
|
59 |
+
|
60 |
+
# ##############################################################################
|
61 |
+
# Variables
|
62 |
+
# ##############################################################################
|
63 |
+
variable "aws_account_name" {
|
64 |
+
type = string
|
65 |
+
validation {
|
66 |
+
condition = length(var.aws_account_name) > 0
|
67 |
+
error_message = "Use the -var-file flag with the terraform command to specify the account configuration."
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
variable "aws_account" {
|
72 |
+
type = string
|
73 |
+
validation {
|
74 |
+
condition = length(var.aws_account) > 0
|
75 |
+
error_message = "Use the -var-file flag with the terraform command to specify the account configuration."
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
variable "aws_region" {
|
80 |
+
type = string
|
81 |
+
validation {
|
82 |
+
condition = length(var.aws_region) > 0
|
83 |
+
error_message = "Use the -var-file flag with the terraform command to specify the account configuration."
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
variable "aws_profile" {
|
88 |
+
type = string
|
89 |
+
validation {
|
90 |
+
condition = length(var.aws_profile) > 0
|
91 |
+
error_message = "Use the -var-file flag with the terraform command to specify the account configuration."
|
92 |
+
}
|
93 |
+
}
|
deployments/terraform/terraform-apply.sh
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
source "${BASH_SOURCE%/*}/../../scripts/common.sh"
|
4 |
+
|
5 |
+
if [ -z "$1" ] ; then
|
6 |
+
c_echo $RED "Need to provide the ENVIRONMENT as first argument. \n"
|
7 |
+
c_echo $YELLOW "Usage: $0 <environment> [auto]"
|
8 |
+
exit 1
|
9 |
+
fi
|
10 |
+
|
11 |
+
c_echo $GREEN "
|
12 |
+
--------------------------------------------------------------------------------
|
13 |
+
-- Deploying Terraform --
|
14 |
+
--------------------------------------------------------------------------------
|
15 |
+
"
|
16 |
+
|
17 |
+
INPUT_FALSE=""
|
18 |
+
AUTO_APPROVE=""
|
19 |
+
if [ "$2" = "auto" ] ; then
|
20 |
+
c_echo $YELLOW "Auto approval set..."
|
21 |
+
INPUT_FALSE="-input=false"
|
22 |
+
AUTO_APPROVE="-auto-approve"
|
23 |
+
fi
|
24 |
+
|
25 |
+
ENVIRONMENT=$1
|
26 |
+
|
27 |
+
AWS_ACCOUNT_NAME=$(cat environments/${ENVIRONMENT}.tfvars.json | jq .aws_account_name | tr -d '"')
|
28 |
+
|
29 |
+
if [ -z "$AWS_ACCOUNT_NAME" ] ; then
|
30 |
+
c_echo $RED "There was a problem loading Account Name configuration from file environments/${ENVIRONMENT}.tfvars.json"
|
31 |
+
exit 1
|
32 |
+
fi
|
33 |
+
|
34 |
+
echo "Account:"
|
35 |
+
cat environments/${ENVIRONMENT}.tfvars.json
|
36 |
+
|
37 |
+
pushd deployments/terraform > /dev/null
|
38 |
+
|
39 |
+
terraform init -reconfigure -backend-config=../../accounts/${AWS_ACCOUNT_NAME}.backend.conf $INPUT_FALSE
|
40 |
+
if [ "$?" -ne "0" ]; then
|
41 |
+
echo "Error in initing the terraform!"
|
42 |
+
exit 1
|
43 |
+
fi
|
44 |
+
|
45 |
+
echo
|
46 |
+
terraform workspace select -or-create $ENVIRONMENT
|
47 |
+
if [ "$?" -ne "0" ]; then
|
48 |
+
echo "Error in selecting workspace!"
|
49 |
+
exit 1
|
50 |
+
fi
|
51 |
+
|
52 |
+
echo
|
53 |
+
echo "Workspaces:"
|
54 |
+
terraform workspace list
|
55 |
+
if [ "$?" -ne "0" ]; then
|
56 |
+
echo "Error in listing workspaces!"
|
57 |
+
exit 1
|
58 |
+
fi
|
59 |
+
|
60 |
+
terraform apply -var-file=../../environments/${ENVIRONMENT}.tfvars.json $INPUT_FALSE $AUTO_APPROVE
|
61 |
+
if [ "$?" -ne "0" ]; then
|
62 |
+
echo "Error in terraform apply!"
|
63 |
+
exit 1
|
64 |
+
fi
|
65 |
+
|
66 |
+
popd > /dev/null
|
environments/integration.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"aws_account_name": "hasaniqbal-ds",
|
3 |
+
"aws_account": "252286678527",
|
4 |
+
"aws_region": "us-east-1",
|
5 |
+
"aws_profile": "ds"
|
6 |
+
}
|
environments/production.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"aws_account_name": "hasaniqbal-ds",
|
3 |
+
"aws_account": "252286678527",
|
4 |
+
"aws_region": "us-east-1",
|
5 |
+
"aws_profile": "ds"
|
6 |
+
}
|
scripts/cli.sh
CHANGED
@@ -11,4 +11,5 @@ source "${BASH_SOURCE%/*}/common.sh"
|
|
11 |
|
12 |
# Executing Python script
|
13 |
export PYTHONPATH="$PYTHONPATH:src/"
|
14 |
-
|
|
|
|
11 |
|
12 |
# Executing Python script
|
13 |
export PYTHONPATH="$PYTHONPATH:src/"
|
14 |
+
export OPENFACTCHECK_VERBOSITY="info"
|
15 |
+
python src/openfactcheck/cli.py "$@"
|
scripts/deploy.sh
ADDED
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
source "${BASH_SOURCE%/*}/common.sh"
|
4 |
+
|
5 |
+
# Description:
|
6 |
+
# Deploys a deployment to an environment
|
7 |
+
#
|
8 |
+
# Usage:
|
9 |
+
# ./scripts/deploy.sh --interactive
|
10 |
+
# ./scripts/deploy.sh <environment>
|
11 |
+
# ./scripts/deploy.sh --environment <environment>
|
12 |
+
# ./scripts/deploy.sh --account <account> --deployment <deployment>
|
13 |
+
# ./scripts/deploy.sh --help
|
14 |
+
|
15 |
+
# Parse arguments and set variables using getops
|
16 |
+
arg0=$(basename "$0" .sh)
|
17 |
+
blnk=$(echo "$arg0" | sed 's/./ /g')
|
18 |
+
|
19 |
+
# Print usage information
|
20 |
+
usage_info()
|
21 |
+
{
|
22 |
+
c_echo $YELLOW "Usage:"
|
23 |
+
c_echo $YELLOW " $arg0 <environment> [--auto]"
|
24 |
+
c_echo $YELLOW " $arg0 --interactive [--auto]"
|
25 |
+
c_echo $YELLOW " $arg0 --environment <environment> [--auto]"
|
26 |
+
c_echo $YELLOW " $arg0 --account <account> --deployment <deployment> [--auto]"
|
27 |
+
}
|
28 |
+
|
29 |
+
# Print usage in case of bad arguments
|
30 |
+
usage()
|
31 |
+
{
|
32 |
+
#exec 1>2 # Send standard output to standard error
|
33 |
+
usage_info
|
34 |
+
exit 1
|
35 |
+
}
|
36 |
+
|
37 |
+
# Print error message and exit
|
38 |
+
error()
|
39 |
+
{
|
40 |
+
echo "$arg0: $*" >&2
|
41 |
+
exit 1
|
42 |
+
}
|
43 |
+
|
44 |
+
# Confirmation message, take two arguments
|
45 |
+
confirmation()
|
46 |
+
{
|
47 |
+
c_echo $YELLOW "
|
48 |
+
--------------------------------------------------------------------------------
|
49 |
+
-- Confirmation --
|
50 |
+
--------------------------------------------------------------------------------
|
51 |
+
"
|
52 |
+
c_echo $YELLOW "Are you sure you want to deploy $1 to $2? (y/n) (Default: y)"
|
53 |
+
read -r CONFIRMATION
|
54 |
+
if [[ -z $CONFIRMATION ]]; then
|
55 |
+
CONFIRMATION="y"
|
56 |
+
fi
|
57 |
+
if [[ $CONFIRMATION != "y" ]]; then
|
58 |
+
c_echo $RED "Exiting..."
|
59 |
+
exit 1
|
60 |
+
fi
|
61 |
+
}
|
62 |
+
|
63 |
+
# Print help message
|
64 |
+
help()
|
65 |
+
{
|
66 |
+
usage_info
|
67 |
+
echo
|
68 |
+
c_echo $YELLOW "Options:"
|
69 |
+
echo " {-i|--interactive} -- Interactive mode"
|
70 |
+
echo " {-e|--environment} <environment> -- Environment to deploy to"
|
71 |
+
echo " {-a|--account} <account> -- Account to deploy to"
|
72 |
+
echo " {-d|--deployment} <deployment> -- Deployment to deploy"
|
73 |
+
echo " {-y|--auto} -- Auto approve"
|
74 |
+
echo " {-h|--help} -- Display this help and exit"
|
75 |
+
echo
|
76 |
+
echo
|
77 |
+
c_echo $YELLOW "Available Deployments:"
|
78 |
+
ls -d deployments/* | grep -v backend | sed 's/deployments\///g' | sort
|
79 |
+
echo
|
80 |
+
c_echo $YELLOW "Available Environments:"
|
81 |
+
ls -d environments/* | grep -v backend | sed 's/.tfvars.json//g' | sed 's/environments\///g'
|
82 |
+
echo
|
83 |
+
c_echo $YELLOW "Available Accounts:"
|
84 |
+
ls -d accounts/* | grep -v backend | sed 's/.tfvars.json//g' | sed 's/accounts\///g'
|
85 |
+
exit 0
|
86 |
+
}
|
87 |
+
|
88 |
+
# Parse command line flags using getopts
|
89 |
+
flags()
|
90 |
+
{
|
91 |
+
# No Arguments
|
92 |
+
[ $# -eq 0 ] && usage
|
93 |
+
|
94 |
+
# if argument is not a flag, then modify command with environment
|
95 |
+
if [ "${1:0:1}" != "-" ]; then
|
96 |
+
ENVIRONMENT=$1
|
97 |
+
shift
|
98 |
+
set -- "$@" "-e" "$ENVIRONMENT"
|
99 |
+
fi
|
100 |
+
|
101 |
+
# Parse Arguments
|
102 |
+
while test $# -gt 0
|
103 |
+
do
|
104 |
+
case "$1" in
|
105 |
+
(-i|--interactive)
|
106 |
+
export INTERACTIVE=true
|
107 |
+
shift;;
|
108 |
+
(-e|--environment)
|
109 |
+
shift
|
110 |
+
[ $# = 0 ] && error "No environment specified"
|
111 |
+
export ENVIRONMENT="$1"
|
112 |
+
|
113 |
+
# Ensure that environment is valid
|
114 |
+
if [ ! -f "environments/$ENVIRONMENT.tfvars.json" ]; then
|
115 |
+
error "Invalid environment $ENVIRONMENT"
|
116 |
+
fi
|
117 |
+
shift;;
|
118 |
+
(-a|--account)
|
119 |
+
shift
|
120 |
+
[ $# = 0 ] && error "No account specified"
|
121 |
+
export ACCOUNT="$1"
|
122 |
+
|
123 |
+
# Ensure that account is valid
|
124 |
+
if [ ! -f "accounts/$ACCOUNT.tfvars.json" ]; then
|
125 |
+
error "Invalid account $ACCOUNT"
|
126 |
+
fi
|
127 |
+
shift;;
|
128 |
+
(-d|--deployment)
|
129 |
+
shift
|
130 |
+
[ $# = 0 ] && error "No deployment specified"
|
131 |
+
export DEPLOYMENT="$1"
|
132 |
+
|
133 |
+
# Ensure that deployment is valid
|
134 |
+
if [ ! -d "deployments/$DEPLOYMENT" ]; then
|
135 |
+
error "Invalid deployment $DEPLOYMENT"
|
136 |
+
fi
|
137 |
+
shift;;
|
138 |
+
(-y|--auto)
|
139 |
+
export AUTO_APPROVE="auto"
|
140 |
+
shift;;
|
141 |
+
(-h|--help)
|
142 |
+
help;;
|
143 |
+
(-*)
|
144 |
+
error "Unknown option $1";;
|
145 |
+
esac
|
146 |
+
done
|
147 |
+
|
148 |
+
# Ensure that account, deployment and environment flags are not passed with interactive flag
|
149 |
+
if [ -n "$INTERACTIVE" ] && ([ -n "$ACCOUNT" ] || [ -n "$DEPLOYMENT" ] || [ -n "$ENVIRONMENT" ]); then
|
150 |
+
error "--interactive flag must be passed alone"
|
151 |
+
fi
|
152 |
+
|
153 |
+
# Ensure that environment flag is not passed with account or deployment flags
|
154 |
+
if [ -n "$ENVIRONMENT" ] && ([ -n "$ACCOUNT" ] || [ -n "$DEPLOYMENT" ]); then
|
155 |
+
error "--environment flag cannot be passed with --account or --deployment flags"
|
156 |
+
fi
|
157 |
+
|
158 |
+
# Ensure that account and deployment flags are passed together
|
159 |
+
if ([ -n "$ACCOUNT" ] && [ -z "$DEPLOYMENT" ]) || ([ -z "$ACCOUNT" ] && [ -n "$DEPLOYMENT" ]); then
|
160 |
+
error "--account and --deployment flags must be passed together"
|
161 |
+
fi
|
162 |
+
|
163 |
+
# Make environment terraform if only environment is passed
|
164 |
+
if [ -n "$ENVIRONMENT" ] && [ -z "$ACCOUNT" ] && [ -z "$DEPLOYMENT" ]; then
|
165 |
+
export DEPLOYMENT="terraform"
|
166 |
+
fi
|
167 |
+
}
|
168 |
+
|
169 |
+
flags "$@"
|
170 |
+
|
171 |
+
# Confguring interactive mode
|
172 |
+
interactive()
|
173 |
+
{
|
174 |
+
# Get all deployments except backend and list terraform at the top
|
175 |
+
DEPLOYMENTS=$(ls -d deployments/* | grep -v backend | sed 's/deployments\///g' | sort)
|
176 |
+
|
177 |
+
# Ask for deployment
|
178 |
+
c_echo $GREEN "Which deployment would you like to deploy?"
|
179 |
+
select DEPLOYMENT in $DEPLOYMENTS; do test -n "$DEPLOYMENT" && break; echo ">>> Invalid Selection"; done
|
180 |
+
|
181 |
+
# Ask for environment if deployment is terraform
|
182 |
+
if [[ $DEPLOYMENT == *"terraform"* ]]; then
|
183 |
+
ENVIRONMENTS=$(ls -d environments/* | sed 's/.tfvars.json//g' | sed 's/environments\///g')
|
184 |
+
c_echo $GREEN "On which environment would you like to deploy?"
|
185 |
+
select ENVIRONMENT in $ENVIRONMENTS; do test -n "$ENVIRONMENT" && break; echo ">>> Invalid Selection"; done
|
186 |
+
|
187 |
+
# Ask for confirmation and default to yes
|
188 |
+
confirmation $DEPLOYMENT $ENVIRONMENT
|
189 |
+
fi
|
190 |
+
|
191 |
+
# Ask for account if deployment is not terraform
|
192 |
+
if [[ $DEPLOYMENT != *"terraform"* ]]; then
|
193 |
+
ACCOUNTS=$(ls -d accounts/* | grep -v backend | sed 's/.tfvars.json//g' | sed 's/accounts\///g')
|
194 |
+
c_echo $GREEN "On which account would you like to deploy?"
|
195 |
+
select ACCOUNT in $ACCOUNTS; do test -n "$ACCOUNT" && break; echo ">>> Invalid Selection"; done
|
196 |
+
|
197 |
+
# Ask for confirmation and default to yes
|
198 |
+
confirmation $DEPLOYMENT $ACCOUNT
|
199 |
+
fi
|
200 |
+
}
|
201 |
+
|
202 |
+
# If --interactive is passed, run interactive mode
|
203 |
+
if [ -n "$INTERACTIVE" ]; then
|
204 |
+
c_echo $YELLOW "Running in interactive mode..."
|
205 |
+
interactive
|
206 |
+
fi
|
207 |
+
|
208 |
+
# Do the build and deployment only if the deployment is terraform
|
209 |
+
if [[ $DEPLOYMENT == *"terraform"* ]]; then
|
210 |
+
echo
|
211 |
+
c_echo $GREEN "Deploying to ${ENVIRONMENT}"
|
212 |
+
|
213 |
+
deployments/terraform/terraform-apply.sh $ENVIRONMENT $AUTO_APPROVE
|
214 |
+
if [ "$?" -ne "0" ]; then
|
215 |
+
c_echo $RED "Deployment failed"
|
216 |
+
exit 1
|
217 |
+
fi
|
218 |
+
echo
|
219 |
+
c_echo $GREEN "Deployment succeeded"
|
220 |
+
fi
|
221 |
+
|
222 |
+
# Do the the deployment only if the deployment is not terraform
|
223 |
+
if [[ $DEPLOYMENT != *"terraform"* ]]; then
|
224 |
+
echo
|
225 |
+
c_echo $GREEN "Deploying ${DEPLOYMENT} to ${ACCOUNT}"
|
226 |
+
|
227 |
+
deployments/${DEPLOYMENT}/${DEPLOYMENT}-apply.sh $ACCOUNT $AUTO_APPROVE
|
228 |
+
if [ "$?" -ne "0" ]; then
|
229 |
+
c_echo $RED "Deployment failed"
|
230 |
+
exit 1
|
231 |
+
fi
|
232 |
+
echo
|
233 |
+
c_echo $GREEN "Deployment succeeded"
|
234 |
+
fi
|
235 |
+
|
236 |
+
|
src/openfactcheck/utils/logging.py
CHANGED
@@ -29,7 +29,7 @@ log_levels = {
|
|
29 |
"critical": CRITICAL,
|
30 |
}
|
31 |
|
32 |
-
_default_log_level = logging.
|
33 |
|
34 |
|
35 |
class CustomStreamLoggingFormatter(logging.Formatter):
|
|
|
29 |
"critical": CRITICAL,
|
30 |
}
|
31 |
|
32 |
+
_default_log_level = logging.WARNING
|
33 |
|
34 |
|
35 |
class CustomStreamLoggingFormatter(logging.Formatter):
|