Skip to content

Commit

Permalink
Clean up makefile, pipenv and workflows.
Browse files Browse the repository at this point in the history
  • Loading branch information
William Chrisp authored and JoshArmi committed Apr 14, 2023
1 parent 5b38e39 commit 260fdcf
Show file tree
Hide file tree
Showing 34 changed files with 1,388 additions and 485 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/aws_cicd.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: cicd
name: aws-cicd
on:
push:
branches:
Expand All @@ -15,8 +15,6 @@ jobs:
permissions:
id-token: write
contents: read
env:
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -34,7 +32,7 @@ jobs:

- uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.9"

- name: Install pipenv
run: pip install pipenv
Expand All @@ -53,10 +51,10 @@ jobs:
run: make unittest

- name: Synthesize terraform configuration template
run: make build
run: make aws-synth

- name: Dev deployment
run: make deploy
run: make aws-deploy-all INFRA_ARGS=--auto-approve

- name: Perform full test and check coverage
run: make test
Expand All @@ -74,11 +72,8 @@ jobs:
- name: Prepare for production deployment
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: make clean
env:
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY_PROD }}

- name: Production deployment
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: make deploy
env:
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY_PROD }}
run: make aws-deploy-all INFRA_ARGS=--auto-approve

15 changes: 6 additions & 9 deletions .github/workflows/gcp_cicd.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: cicd
name: gcp-cicd
on:
push:
branches:
Expand Down Expand Up @@ -33,7 +33,7 @@ jobs:

- uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.9"

- name: Install pipenv
run: pip install pipenv
Expand All @@ -49,19 +49,16 @@ jobs:
run: make install-dependencies

- name: Synthesize terraform configuration template
run: make synth-gcp

- name: Terraform plan
run: make plan-gcp
run: make gcp-synth

- name: Deploy base infrastructure
run: make deploy-base-gcp
run: make gcp-deploy-base INFRA_ARGS=--auto-approve

- name: Build & push docker image
run: make build-image
run: make gcp-build-image

- name: Deploy main infrastructure
run: make deploy-main-gcp
run: make gcp-deploy-core INFRA_ARGS=--auto-approve

# - name: Perform full test and check coverage
# run: make test
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Thumbs.db

# CDKTF Specifics
requirements.txt
all_files/
controller_core/
api_key_rotation/
!api_key_rotation/main.py
imports/
Expand Down
2 changes: 1 addition & 1 deletion 10_oidc/role.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ resource "aws_iam_role" "github_oidc" {
Condition = {
StringLike = {
"token.actions.githubusercontent.com:aud" = "sts.amazonaws.com"
"token.actions.githubusercontent.com:sub" = "repo:contino/apac-flight-controller-aws:*"
"token.actions.githubusercontent.com:sub" = "repo:contino/flight-controller:*"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion 11_oidc_prod/role.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ resource "aws_iam_role" "github_oidc" {
Condition = {
StringEquals = {
"token.actions.githubusercontent.com:aud" = "sts.amazonaws.com"
"token.actions.githubusercontent.com:sub" = "repo:contino/apac-flight-controller-aws:ref:refs/heads/main"
"token.actions.githubusercontent.com:sub" = "repo:contino/flight-controller:ref:refs/heads/main"
}
}
},
Expand Down
142 changes: 100 additions & 42 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
INFRA_ARGS =

# Local Commands
local: install-dependencies
pipenv shell

install-dependencies:
pipenv clean
pipenv install --dev

docs-install:
Expand Down Expand Up @@ -34,67 +37,122 @@ e2e:
cd tests/; pipenv run behave

# Infrastructure Commands
build-python:
pipenv requirements | tee requirements.txt
rsync -avu $(shell pwd)/src $(shell pwd)/infrastructure/aws/all_files
pip install -r requirements.txt --target=$(shell pwd)/infrastructure/aws/all_files
pip install boto3 --target=$(shell pwd)/infrastructure/aws/api_key_rotation
cd infrastructure/aws; cdktf provider add grafana/grafana
cd infrastructure/gcp; cdktf provider add grafana/grafana

# General
clean:
cd infrastructure/aws; rm -rf cdktf.out
cd infrastructure/gcp; rm -rf cdktf.out

synth-aws:
cd infrastructure/aws;cdktf synth aws_infra_cdktf

synth-grafana:
cd infrastructure/aws;cdktf synth grafana
synth: aws-synth gcp-synth

synth-gcp:
cd infrastructure/gcp; cdktf provider add grafana/grafana
cd infrastructure/gcp; cdktf synth base_gcp_infra
cd infrastructure/gcp; cdktf synth main_gcp_infra

synth: synth-aws synth-grafana synth-gcp
plan: aws-plan-all gcp-plan-all

build: build-python synth
deploy: aws-deploy-all gcp-deploy-all

plan-aws:
cd infrastructure/aws;cdktf plan aws_infra_cdktf
destroy: aws-destroy-all gcp-destroy-all

plan-grafana:
cd infrastructure/aws;cdktf plan grafana
# AWS
aws-build-dependencies:
@echo "\n\n---AWS-BUILD-DEPENDENCIES---\n"
rsync -avu $(shell pwd)/src $(shell pwd)/infrastructure/aws/controller_core
pipenv requirements | tee requirements.txt
pip install -r requirements.txt --target=$(shell pwd)/infrastructure/aws/controller_core
pip install boto3 --target=$(shell pwd)/infrastructure/aws/api_key_rotation
cd infrastructure/aws; cdktf provider add grafana/grafana

aws-synth: aws-build-dependencies
@echo "\n\n---AWS-SYNTH---\n"
cd infrastructure/aws;cdktf synth

plan-gcp:
cd infrastructure/gcp;cdktf plan base_gcp_infra main_gcp_infra
aws-plan-core:
@echo "\n\n---AWS-PLAN-CORE---\n"
cd infrastructure/aws;cdktf plan aws_core

plan-gcp-grafana:
cd infrastructure/gcp;cdktf plan grafana
aws-plan-grafana:
@echo "\n\n---AWS-PLAN-GRAFANA---\n"
cd infrastructure/aws;cdktf plan aws_grafana_dashboard

plan: build-python plan-aws plan-grafana plan-gcp
aws-plan-all: aws-plan-core aws-plan-grafana

plan-gcpstack: plan-gcp plan-grafana
aws-deploy-core:
@echo "\n\n---AWS-DEPLOY-CORE---\n"
cd infrastructure/aws;cdktf deploy aws_core ${INFRA_ARGS}

deploy:
cd infrastructure/aws;cdktf deploy aws_infra_cdktf grafana --auto-approve
aws-deploy-grafana:
@echo "\n\n---AWS-DEPLOY-GRAFANA---\n"
cd infrastructure/aws;cdktf deploy aws_grafana_dashboard ${INFRA_ARGS}

destroy-aws:
cd infrastructure/aws;cdktf destroy aws_infra_cdktf
aws-deploy-all:
@echo "\n\n---AWS-DEPLOY-ALL---\n"
cd infrastructure/aws;cdktf deploy aws_core aws_grafana_dashboard ${INFRA_ARGS}

destroy-grafana:
cd infrastructure/aws;cdktf destroy grafana
aws-destroy-core:
@echo "\n\n---AWS-DESTROY-CORE---\n"
cd infrastructure/aws;cdktf destroy aws_core

destroy: destroy-core destroy-grafana
aws-destroy-grafana:
@echo "\n\n---AWS-DESTROY-GRAFANA---\n"
cd infrastructure/aws;cdktf destroy aws_grafana_dashboard

deploy-base-gcp:
cd infrastructure/gcp; cdktf deploy base_gcp_infra --auto-approve
aws-destroy-all:
@echo "\n\n---AWS-DESTROY-ALL---\n"
cd infrastructure/aws;cdktf destroy aws_core aws_grafana_dashboard

deploy-main-gcp:
cd infrastructure/gcp; cdktf deploy base_gcp_infra main_gcp_infra --auto-approve
# GCP
gcp-build-dependencies:
@echo "\n\n---GCP-BUILD-DEPENDENCIES---\n"
cd infrastructure/gcp; cdktf provider add grafana/grafana

build-image:
gcp-build-image:
@echo "\n\n---GCP-BUILD-IMAGE---\n"
gcloud auth configure-docker australia-southeast1-docker.pkg.dev
pipenv requirements | tee requirements.txt
docker buildx build --platform=linux/amd64 --push . -t australia-southeast1-docker.pkg.dev/contino-squad0-fc/flight-contoller-event-receiver/event_receiver:latest
docker buildx build --platform=linux/amd64 --push . -t australia-southeast1-docker.pkg.dev/contino-squad0-fc/flight-contoller-event-receiver/event_receiver:latest

gcp-synth: gcp-build-dependencies
@echo "\n\n---GCP-SYNTH---\n"
cd infrastructure/gcp; cdktf synth

gcp-plan-base:
@echo "\n\n---GCP-PLAN-BASE---\n"
cd infrastructure/gcp;cdktf plan gcp_base

gcp-plan-core:
@echo "\n\n---GCP-PLAN-CORE---\n"
cd infrastructure/gcp;cdktf plan gcp_core

gcp-plan-grafana:
@echo "\n\n---GCP-PLAN-GRAFANA---\n"
cd infrastructure/gcp;cdktf plan gcp_grafana

gcp-plan-all: gcp-plan-base gcp-plan-core #gcp-plan-grafana

gcp-deploy-base:
@echo "\n\n---GCP-DEPLOY-BASE---\n"
cd infrastructure/gcp;cdktf deploy gcp_base ${INFRA_ARGS}

gcp-deploy-core:
@echo "\n\n---GCP-DEPLOY-CORE---\n"
cd infrastructure/gcp;cdktf deploy gcp_base gcp_core ${INFRA_ARGS}

gcp-deploy-grafana:
@echo "\n\n---GCP-DEPLOY-GRAFANA---\n"
cd infrastructure/gcp;cdktf deploy gcp_grafana ${INFRA_ARGS}

gcp-deploy-all: gcp-deploy-base gcp-build-image gcp-deploy-core #gcp-deploy-grafana

gcp-destroy-base:
@echo "\n\n---GCP-DESTROY-BASE---\n"
cd infrastructure/gcp;cdktf destroy gcp_base

gcp-destroy-core:
@echo "\n\n---GCP-DESTROY-CORE---\n"
cd infrastructure/gcp;cdktf destroy gcp_core

gcp-destroy-grafana:
@echo "\n\n---GCP-DESTROY-GRAFANA---\n"
cd infrastructure/gcp;cdktf destroy gcp_grafana

gcp-destroy-all:
@echo "\n\n---GCP-DESTROY-ALL---\n"
cd infrastructure/gcp;cdktf destroy gcp_base gcp_core gcp_grafana
5 changes: 3 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ structlog = "*"
boto3= "*"
flask = "*"
pydantic = "*"
pydantic-core = "*"

[dev-packages]
pytest = "*"
Expand All @@ -30,7 +31,7 @@ pytest-watch = "*"
dirhash = "*"

[requires]
python_version = "3.10"
python_version = "3.9"

[pipenv]
allow_prereleases = true
allow_prereleases = true
Loading

0 comments on commit 260fdcf

Please sign in to comment.