Skip to content

Commit

Permalink
Add the yaml env load (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
athiruma authored Sep 24, 2024
1 parent af789b3 commit 582f97b
Show file tree
Hide file tree
Showing 6 changed files with 348 additions and 59 deletions.
24 changes: 20 additions & 4 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,15 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }}
run: |
sudo podman run --rm --name cloud-governance -e policy=${{ matrix.policy }} -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION=${{ matrix.region }} -e dry_run=yes -e policy_output=s3://${{ secrets.BUCKET }}/test/${{ matrix.region }} -e log_level=INFO ${{ secrets.QUAY_PUBLIC_CLOUD_GOVERNANCE_REPOSITORY }}
touch env.yaml
echo "policy: ${{ matrix.policy }}" >> env.yaml
echo "AWS_DEFAULT_REGION: ${{ matrix.region }}" >> env.yaml
echo "AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}" >> env.yaml
echo "AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}" >> env.yaml
echo "dry_run: yes" >> env.yaml
echo "policy_output: "s3://${{ secrets.BUCKET }}/test/${{ matrix.region }}"" >> env.yaml
echo "log_level: INFO" >> env.yaml
sudo podman run --rm --name cloud-governance -v "${PWD}/env.yaml":"/tmp/env.yaml" ${{ secrets.QUAY_PUBLIC_CLOUD_GOVERNANCE_REPOSITORY }}
gitleaks:
name: gitleaks
needs: [ unittest, terraform_apply, integration, pypi_upload, pypi_validate, bump_version ]
Expand All @@ -397,6 +405,14 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }}
run: |
# gileaks policy
region='us-east-1'
policy='gitleaks'
sudo podman run --rm --name cloud-governance -e policy=$policy -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION=$region -e git_access_token=${{ secrets.GIT_TOKEN }} -e git_repo=https://github.com/redhat-performance/cloud-governance -e policy_output=s3://${{ secrets.BUCKET }}/test/$region -e log_level=INFO ${{ secrets.QUAY_PUBLIC_CLOUD_GOVERNANCE_REPOSITORY }} > /dev/null
region="us-east-1"
touch env.yaml
echo "AWS_DEFAULT_REGION: ${region}" >> env.yaml
echo "policy: gitleaks" >> env.yaml
echo "AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}" >> env.yaml
echo "AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}" >> env.yaml
echo "git_access_token: ${{ secrets.GIT_TOKEN }}" >> env.yaml
echo "git_repo: https://github.com/redhat-performance/cloud-governance" >> env.yaml
echo "policy_output: "s3://${{ secrets.BUCKET }}/test/${region}"" >> env.yaml
echo "log_level: INFO" >> env.yaml
sudo podman run --rm --name cloud-governance -v "${PWD}/env.yaml":"/tmp/env.yaml" ${{ secrets.QUAY_PUBLIC_CLOUD_GOVERNANCE_REPOSITORY }} > /dev/null
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,4 @@ empty_test_environment_variables.py
/cloud_governance/policy/send_mail.py
cloudsensei/.env.txt
.vscode
env.yaml
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,27 @@ podman run --rm --name cloud-governance -e policy="tag_vm" -e account="$account"

```

#### Run with yaml config

```shell
cp example.yaml env.yaml
```

Added the supported environment variables.
example:

```yaml
policy: instance_idle
AWS_ACCESS_KEY_ID: ""
AWS_SECRET_ACCESS_KEY: ""
```
```shell
podman run --rm --name cloud-governance \
-v "${PWD}/env.yaml":"/tmp/env.yaml" \
"quay.io/cloud-governance/cloud-governance:latest"
```

## Run Policy Using Pod

#### Run as a pod job via OpenShift
Expand Down
10 changes: 4 additions & 6 deletions cloud_governance/common/logger/init_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
import sys
import logging

from cloud_governance.main.environment_variables import environment_variables

logger_category_name = 'cloud_governance'
logger = logging.getLogger(logger_category_name) # instantiating a logger
handler = logging.StreamHandler(sys.stdout)
# log for output only
#log_path = os.getcwd()
#fileHandler = logging.FileHandler(filename=f'{log_path}/cloud_governance.log', mode='w+')
account_name = environment_variables.environment_variables_dict.get('account')
# log_path = os.getcwd()
# fileHandler = logging.FileHandler(filename=f'{log_path}/cloud_governance.log', mode='w+')
account_name = os.environ.get('account')
log_format = f'[%(levelname)s] %(asctime)s {account_name} - %(message)s'
formatter = logging.Formatter(log_format)
handler.setFormatter(formatter)
logger.addHandler(handler)
#logger.addHandler(fileHandler)
# logger.addHandler(fileHandler)


# def get_pyperf_log_path():
Expand Down
Loading

0 comments on commit 582f97b

Please sign in to comment.