Skip to content

Commit

Permalink
infracost triggers fixes when there is no token
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzag committed Aug 14, 2023
1 parent 1c13908 commit a898b3f
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 46 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/aws_caching_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,20 @@ jobs:
with:
python-version: 3.9


- name: Checkout infracost pricing repo
uses: actions/checkout@v3
with:
repository: infracost/cloud-pricing-api
path: cloud-pricing-api

- name: Echo the values
run: |
echo "project_name is: ${{ github.event.client_payload.project_name }}"
echo "infracost_token is: ${{ github.event.client_payload.infracost_token }}"
- name: Caching Tasks
if: always()
run: |
cd cloud-pricing-api
export SELF_HOSTED_INFRACOST_API_KEY="${{ github.event.client_payload.infracost_token }}"
export INFRACOST_API_KEY="${{ github.event.client_payload.infracost_token }}"
docker-compose run init_job
docker-compose ps
docker-compose up -d api
docker-compose ps
export PGPASSWORD=postgres
export POSTGRES_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' cloud-pricing-api_postgres_1)
curl --retry 20 --retry-all-errors http://localhost:4000/health
export MONGO_URL=${{ github.event.client_payload.mongo_url }}
export MONGO_USER=${{ github.event.client_payload.mongo_user }}
export MONGO_PASSWORD=${{ github.event.client_payload.mongo_password }}
export PROJECT_NAME=${{ github.event.client_payload.project_name }}
export INFRACOST_TOKEN=${{ github.event.client_payload.infracost_token }}
export INFRACOST_URL=http://localhost:4000
export POSTGRES_PORT=5432
export SECRET_KEY=${{ secrets.SECRET_KEY }}
export GITHUB_ACTIONS_ENV=Yes
export PYTHONPATH=$PYTHONPATH:.
cd ..
pip3 install -r web/requirements.txt
python3 web/scripts/aws_caching_script.py --aws-access-key-id ${{ github.event.client_payload.aws_access_key_id }} --aws-secret-access-key ${{ github.event.client_payload.aws_secret_access_key }}
64 changes: 64 additions & 0 deletions .github/workflows/aws_caching_action_with_infracost.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: AWS Caching with Infracost
on:
repository_dispatch:
types: aws-caching-action-infracost-trigger

jobs:
aws-caching-trigger:
runs-on: ubuntu-22.04
steps:
- uses: 'actions/checkout@v3'

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ github.event.client_payload.aws_access_key_id }}
aws-secret-access-key: ${{ github.event.client_payload.aws_secret_access_key }}
aws-region: us-east-1

- name: Checkout Code
uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9


- name: Checkout infracost pricing repo
uses: actions/checkout@v3
with:
repository: infracost/cloud-pricing-api
path: cloud-pricing-api

- name: Echo the values
run: |
echo "project_name is: ${{ github.event.client_payload.project_name }}"
echo "infracost_token is: ${{ github.event.client_payload.infracost_token }}"
- name: Caching Tasks
if: always()
run: |
cd cloud-pricing-api
export SELF_HOSTED_INFRACOST_API_KEY="${{ github.event.client_payload.infracost_token }}"
export INFRACOST_API_KEY="${{ github.event.client_payload.infracost_token }}"
docker-compose run init_job
docker-compose ps
docker-compose up -d api
docker-compose ps
export PGPASSWORD=postgres
export POSTGRES_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' cloud-pricing-api_postgres_1)
curl --retry 20 --retry-all-errors http://localhost:4000/health
export MONGO_URL=${{ github.event.client_payload.mongo_url }}
export MONGO_USER=${{ github.event.client_payload.mongo_user }}
export MONGO_PASSWORD=${{ github.event.client_payload.mongo_password }}
export PROJECT_NAME=${{ github.event.client_payload.project_name }}
export INFRACOST_TOKEN=${{ github.event.client_payload.infracost_token }}
export INFRACOST_URL=http://localhost:4000
export POSTGRES_PORT=5432
export SECRET_KEY=${{ secrets.SECRET_KEY }}
export GITHUB_ACTIONS_ENV=Yes
export PYTHONPATH=$PYTHONPATH:.
cd ..
pip3 install -r web/requirements.txt
python3 web/scripts/aws_caching_script.py --aws-access-key-id ${{ github.event.client_payload.aws_access_key_id }} --aws-secret-access-key ${{ github.event.client_payload.aws_secret_access_key }}
22 changes: 0 additions & 22 deletions .github/workflows/az_caching_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
echo "client_id is: ${{ github.event.client_payload.client_id }}"
echo "client_secret is: ${{ github.event.client_payload.client_secret }}"
echo "tenant_id is: ${{ github.event.client_payload.tenant_id }}"
echo "infracost_token is: ${{ github.event.client_payload.infracost_token }}"
- name: Az CLI login
uses: Azure/login@v1
Expand All @@ -38,36 +37,15 @@ jobs:
creds: ${{ env.CREDENTIALS }}


- name: Checkout infracost pricing repo
uses: actions/checkout@v3
with:
repository: infracost/cloud-pricing-api
path: cloud-pricing-api


- name: Caching Tasks
if: always()
run: |
cd cloud-pricing-api
export SELF_HOSTED_INFRACOST_API_KEY="${{ github.event.client_payload.infracost_token }}"
export INFRACOST_API_KEY="${{ github.event.client_payload.infracost_token }}"
docker-compose run init_job
docker-compose ps
docker-compose up -d api
docker-compose ps
export PGPASSWORD=postgres
export POSTGRES_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' cloud-pricing-api_postgres_1)
curl --retry 20 --retry-all-errors http://localhost:4000/health
export MONGO_URL=${{ github.event.client_payload.mongo_url }}
export MONGO_USER=${{ github.event.client_payload.mongo_user }}
export MONGO_PASSWORD=${{ github.event.client_payload.mongo_password }}
export PROJECT_NAME=${{ github.event.client_payload.project_name }}
export INFRACOST_TOKEN=${{ github.event.client_payload.infracost_token }}
export INFRACOST_URL=http://localhost:4000
export POSTGRES_PORT=5432
export SECRET_KEY=${{ secrets.SECRET_KEY }}
export GITHUB_ACTIONS_ENV=Yes
export PYTHONPATH=$PYTHONPATH:.
cd ..
pip3 install -r web/requirements.txt
python3 web/scripts/az_caching_script.py
73 changes: 73 additions & 0 deletions .github/workflows/az_caching_action_with_infracost.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: AZ Caching with Infracost
on:
repository_dispatch:
types: az-caching-action-infracost-trigger

jobs:
az_caching:
runs-on: ubuntu-22.04
permissions:
contents: read
pages: write
id-token: write
steps:
- uses: 'actions/checkout@v3'

- name: Checkout Code
uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Echo the values
run: |
echo "client_payload is: ${{ github.event.client_payload.client_payload }}"
echo "azure_credentials is: ${{ github.event.client_payload.azure_credentials }}"
echo "project_name is: ${{ github.event.client_payload.project_name }}"
echo "client_id is: ${{ github.event.client_payload.client_id }}"
echo "client_secret is: ${{ github.event.client_payload.client_secret }}"
echo "tenant_id is: ${{ github.event.client_payload.tenant_id }}"
echo "infracost_token is: ${{ github.event.client_payload.infracost_token }}"
- name: Az CLI login
uses: Azure/login@v1
env:
CREDENTIALS: ${{ github.event.client_payload.azure_credentials }}
with:
creds: ${{ env.CREDENTIALS }}


- name: Checkout infracost pricing repo
uses: actions/checkout@v3
with:
repository: infracost/cloud-pricing-api
path: cloud-pricing-api


- name: Caching Tasks
if: always()
run: |
cd cloud-pricing-api
export SELF_HOSTED_INFRACOST_API_KEY="${{ github.event.client_payload.infracost_token }}"
export INFRACOST_API_KEY="${{ github.event.client_payload.infracost_token }}"
docker-compose run init_job
docker-compose ps
docker-compose up -d api
docker-compose ps
export PGPASSWORD=postgres
export POSTGRES_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' cloud-pricing-api_postgres_1)
curl --retry 20 --retry-all-errors http://localhost:4000/health
export MONGO_URL=${{ github.event.client_payload.mongo_url }}
export MONGO_USER=${{ github.event.client_payload.mongo_user }}
export MONGO_PASSWORD=${{ github.event.client_payload.mongo_password }}
export PROJECT_NAME=${{ github.event.client_payload.project_name }}
export INFRACOST_TOKEN=${{ github.event.client_payload.infracost_token }}
export INFRACOST_URL=http://localhost:4000
export POSTGRES_PORT=5432
export SECRET_KEY=${{ secrets.SECRET_KEY }}
export GITHUB_ACTIONS_ENV=Yes
export PYTHONPATH=$PYTHONPATH:.
cd ..
pip3 install -r web/requirements.txt
python3 web/scripts/az_caching_script.py
12 changes: 10 additions & 2 deletions web/cluster_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,12 @@ def trigger_gcp_caching(self):
return False

def trigger_aws_caching(self):
if self.infracost_token:
event_type = "aws-caching-action-infracost-trigger"
else:
event_type = "aws-caching-action-trigger"
json_data = {
"event_type": "aws-caching-action-trigger",
"event_type": event_type,
"client_payload": {"project_name": self.project_name,
"aws_access_key_id": self.aws_access_key_id,
"aws_secret_access_key": self.aws_secret_access_key,
Expand All @@ -336,8 +340,12 @@ def trigger_az_caching(self):
client_id = json.loads(self.azure_credentials)['clientId']
client_secret = json.loads(self.azure_credentials)['clientSecret']
tenant_id = json.loads(self.azure_credentials)['tenantId']
if self.infracost_token:
event_type = "az-caching-action-infracost-trigger"
else:
event_type = "az-caching-action-trigger"
json_data = {
"event_type": "az-caching-action-trigger",
"event_type": event_type,
"client_payload": {"azure_credentials": self.azure_credentials,
"infracost_token": self.infracost_token,
"client_id": client_id,
Expand Down

0 comments on commit a898b3f

Please sign in to comment.