Skip to content

Commit 4c2f404

Browse files
authored
Feature/updated gh action (#42)
* update pr diff * tag * use latest image * this better * use latewt * fix * limit runs * more perm issions * Adds IaC dependency files * check this * more privs * add all ew file * ignore cpg * use scan folder * change port * upload logs * more verbose logs * perm * Safe * skip docker login * which dir * new files track
1 parent 18361c4 commit 4c2f404

File tree

9 files changed

+332
-25
lines changed

9 files changed

+332
-25
lines changed

.github/workflows/appcd-iac-pr-diff.yml

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,74 @@ on:
55
- main
66
jobs:
77
compare-artifacts:
8+
permissions:
9+
contents: write
10+
pull-requests: write
811
runs-on: ubuntu-latest
912
steps:
1013
- name: Checkout Main Branch
11-
uses: actions/checkout@v2
14+
uses: actions/checkout@v4
1215
with:
1316
ref: main
1417
path: main_branch
15-
- name: Login to docker
16-
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
17-
18+
fetch-depth: 1
1819
- name: Generate IaC from Main Branch
20+
env:
21+
APPCD_TOKEN: ${{ secrets.APPCD_TOKEN }}
22+
APPCD_URL: ${{ secrets.APPCD_URL }}
1923
run: |
20-
mkdir -p artifact/main/
24+
mkdir -p artifact/main/ ./artifact/tmp
2125
docker run --rm \
22-
--workdir=/code \
23-
-v ./main_branch:/code -v ./artifact/main:/artifact/main ghcr.io/appcd-dev/appcd-dist/appcd@sha256:a38ade31e60f3f7f76b1135a388db158eed3c90816d5b5c09e33dd806efb67d5 \
24-
generate --mode ci --output=/artifact/main/.appcd/charts
26+
--workdir=/app/scan \
27+
-e APPCD_TOKEN=$APPCD_TOKEN \
28+
-e APPCD_URL=$APPCD_URL \
29+
-v ./main_branch:/app/scan \
30+
-v ./artifact/tmp:/tmp \
31+
-v ./artifact/main:/artifact/main \
32+
--entrypoint=appcd \
33+
ghcr.io/appcd-dev/appcd-dist/appcd-cli:v0.9.1 \
34+
generate --mode ci --lang Python --log 2 --output=/artifact/main/.appcd/charts --iac-type Helm
35+
cd artifact/main/.appcd/charts
36+
unzip scan.zip && rm scan.zip && ls -latr && pwd
37+
- name: Upload logs
38+
uses: actions/upload-artifact@v2
39+
with:
40+
name: analyzer_logs_1
41+
path: artifact
2542
- name: Checkout PR Branch
26-
uses: actions/checkout@v2
43+
uses: actions/checkout@v4
2744
with:
2845
ref: ${{ github.head_ref }}
2946
path: pr_branch
47+
fetch-depth: 1
3048
- name: Extract branch name
3149
id: extract_branch
3250
run: echo "branch=$(basename ${{ github.head_ref}})" >> $GITHUB_OUTPUT
3351
- name: echo branch name
3452
run: echo ${{ steps.extract_branch.outputs.branch }}
3553
- name: Generate IaC from PR branch
54+
env:
55+
APPCD_TOKEN: ${{ secrets.APPCD_TOKEN }}
56+
APPCD_URL: ${{ secrets.APPCD_URL }}
3657
run: |
37-
mkdir -p artifact/${{ steps.extract_branch.outputs.branch }}/
58+
mkdir -p artifact/${{ steps.extract_branch.outputs.branch }}/ ./artifact/tmp
3859
docker run --rm \
39-
--workdir=/code \
40-
-v ./pr_branch/:/code -v ./artifact/${{ steps.extract_branch.outputs.branch }}:/artifact/${{ steps.extract_branch.outputs.branch }} ghcr.io/appcd-dev/appcd-dist/appcd@sha256:a38ade31e60f3f7f76b1135a388db158eed3c90816d5b5c09e33dd806efb67d5 \
41-
generate --mode ci --output=/artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts
60+
--workdir=/app/scan \
61+
-v ./pr_branch/:/app/scan \
62+
-v ./artifact/${{ steps.extract_branch.outputs.branch }}:/artifact/${{ steps.extract_branch.outputs.branch }} \
63+
-v ./artifact/tmp:/tmp \
64+
-e APPCD_TOKEN=$APPCD_TOKEN \
65+
-e APPCD_URL=$APPCD_URL \
66+
--entrypoint=appcd \
67+
ghcr.io/appcd-dev/appcd-dist/appcd-cli:v0.9.1 \
68+
generate --mode ci --lang Python --log 2 --iac-type Helm --output=/artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts
69+
cd artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts
70+
unzip scan.zip && rm scan.zip && ls -latr
71+
- name: Upload logs
72+
uses: actions/upload-artifact@v2
73+
with:
74+
name: analyzer_logs_2
75+
path: artifact
4276
- name: Copy infrastructure files if empty
4377
run: |
4478
cd pr_branch
@@ -51,22 +85,22 @@ jobs:
5185
git commit -m "Adds IaC dependency files"
5286
git push
5387
fi
54-
cd ../
5588
- name: Generate diff between Main and PR branch
5689
run: |
5790
mkdir -p pr_branch/deployment_files
58-
mv ./artifact/main/.appcd pr_branch/deployment_files/
91+
mv ./artifact/main/.appcd/charts/helm/scan_*/* pr_branch/deployment_files/
5992
cd pr_branch
6093
git config --local user.email "action@github.com"
6194
git config --local user.name "GitHub Action"
6295
git add deployment_files
6396
git commit -m "staging deployment files from main to compare them"
64-
rm -rf deploment_files/*
65-
rm -rf deployment_files/.appcd
97+
rm -rf deploment_files
6698
cd ..
67-
mv artifact/${{ steps.extract_branch.outputs.branch }}/.appcd pr_branch/deployment_files/
99+
mkdir -p pr_branch/deployment_files/
100+
cp -R artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts/helm/scan_*/* pr_branch/deployment_files/
68101
cd pr_branch
69-
git diff --output=../diff.txt deployment_files/ | cat
102+
git add .
103+
git diff --staged --output=../diff.txt deployment_files/ | cat
70104
cat ../diff.txt
71105
- name: Comment PR with IaC Changes
72106
uses: actions/github-script@v6

.github/workflows/docker-publish.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ jobs:
2424
runs-on: ubuntu-latest
2525

2626
steps:
27-
- uses: actions/checkout@v2
27+
- uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 1
2830

2931
- name: Run tests
3032
run: |
@@ -50,6 +52,8 @@ jobs:
5052

5153
steps:
5254
- uses: actions/checkout@v4
55+
with:
56+
fetch-depth: 1
5357

5458
- name: Build image
5559
run: docker build . --file Dockerfile --tag $IMAGE_NAME
@@ -91,9 +95,11 @@ jobs:
9195
- name: run appCD
9296
run: |
9397
docker run --rm \
94-
--workdir=/code \
95-
-v $PWD:/code ghcr.io/appcd-dev/appcd-dist/appcd@sha256:a38ade31e60f3f7f76b1135a388db158eed3c90816d5b5c09e33dd806efb67d5 \
96-
generate --mode ci --output=/code/.appcd/charts
98+
--workdir=/code \
99+
-v $PWD:/code ghcr.io/appcd-dev/appcd-dist/appcd-cli:v0.9.0 \
100+
generate --mode ci --lang Python --iac-type Helm --output=/code/.appcd/charts
101+
cd .appcd/charts && ls
102+
unzip DogeAPI.zip && rm DogeAPI.zip
97103
98104
- name: Inflate helm chart in gitops/
99105
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,4 @@ dev.pem
174174
.appcd/charts/
175175
cpg.bin
176176
analyzer.log
177+
*.cpg.bin

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ USER 1000
2626
ENV ACCESS_LOG=${ACCESS_LOG:-/proc/1/fd/1}
2727
ENV ERROR_LOG=${ERROR_LOG:-/proc/1/fd/2}
2828

29-
EXPOSE 8000
29+
EXPOSE 8080
3030

3131
# Define the Uvicorn command to run our application
32-
CMD ["uvicorn", "main:app", "--reload", "--workers", "1", "--host", "0.0.0.0", "--port", "8000"]
32+
CMD ["uvicorn", "main:app", "--reload", "--workers", "1", "--host", "0.0.0.0", "--port", "8080"]

infrastructure/rds/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# RDS
2+
3+
Infrastructure templates used to manage the Postgres RDS DB cluster
4+
5+
## Requirements
6+
7+
| Name | Version |
8+
|------|---------|
9+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
10+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.9 |
11+
12+
## Providers
13+
14+
| Name | Version |
15+
|------|---------|
16+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.65.0 |
17+
| <a name="provider_terraform"></a> [terraform](#provider\_terraform) | n/a |
18+
19+
## Modules
20+
21+
| Name | Source | Version |
22+
|------|--------|---------|
23+
| <a name="module_aurora_postgresql_v2"></a> [aurora\_postgresql\_v2](#module\_aurora\_postgresql\_v2) | terraform-aws-modules/rds-aurora/aws | n/a |
24+
25+
## Resources
26+
27+
| Name | Type |
28+
|------|------|
29+
| [aws_rds_engine_version.postgresql](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/rds_engine_version) | data source |
30+
| [terraform_remote_state.vpc](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/data-sources/remote_state) | data source |
31+
32+
## Inputs
33+
34+
| Name | Description | Type | Default | Required |
35+
|------|-------------|------|---------|:--------:|
36+
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS region | `any` | n/a | yes |
37+
| <a name="input_database_name"></a> [database\_name](#input\_database\_name) | Database name | `any` | n/a | yes |
38+
| <a name="input_environment"></a> [environment](#input\_environment) | Environment name | `any` | n/a | yes |
39+
| <a name="input_postgresql_engine_version"></a> [postgresql\_engine\_version](#input\_postgresql\_engine\_version) | PostgreSQL engine version | `string` | `"15.2"` | no |
40+
| <a name="input_state_bucket_name"></a> [state\_bucket\_name](#input\_state\_bucket\_name) | State bucket name | `string` | `"cafi-dev-state-bucket"` | no |
41+
| <a name="input_state_bucket_region"></a> [state\_bucket\_region](#input\_state\_bucket\_region) | State bucket region | `string` | `"us-east-1"` | no |
42+
| <a name="input_state_bucket_vpc_key"></a> [state\_bucket\_vpc\_key](#input\_state\_bucket\_vpc\_key) | State bucket VPC key | `string` | `"cafi-dev/cafi/infrastructure/vpc/terraform.tfstate"` | no |
43+
44+
## Outputs
45+
46+
| Name | Description |
47+
|------|-------------|
48+
| <a name="output_aurora_postgresql_v2_additional_cluster_endpoints"></a> [aurora\_postgresql\_v2\_additional\_cluster\_endpoints](#output\_aurora\_postgresql\_v2\_additional\_cluster\_endpoints) | A map of additional cluster endpoints and their attributes |
49+
| <a name="output_aurora_postgresql_v2_cluster_arn"></a> [aurora\_postgresql\_v2\_cluster\_arn](#output\_aurora\_postgresql\_v2\_cluster\_arn) | Amazon Resource Name (ARN) of cluster |
50+
| <a name="output_aurora_postgresql_v2_cluster_database_name"></a> [aurora\_postgresql\_v2\_cluster\_database\_name](#output\_aurora\_postgresql\_v2\_cluster\_database\_name) | Name for an automatically created database on cluster creation |
51+
| <a name="output_aurora_postgresql_v2_cluster_endpoint"></a> [aurora\_postgresql\_v2\_cluster\_endpoint](#output\_aurora\_postgresql\_v2\_cluster\_endpoint) | Writer endpoint for the cluster |
52+
| <a name="output_aurora_postgresql_v2_cluster_engine_version_actual"></a> [aurora\_postgresql\_v2\_cluster\_engine\_version\_actual](#output\_aurora\_postgresql\_v2\_cluster\_engine\_version\_actual) | The running version of the cluster database |
53+
| <a name="output_aurora_postgresql_v2_cluster_hosted_zone_id"></a> [aurora\_postgresql\_v2\_cluster\_hosted\_zone\_id](#output\_aurora\_postgresql\_v2\_cluster\_hosted\_zone\_id) | The Route53 Hosted Zone ID of the endpoint |
54+
| <a name="output_aurora_postgresql_v2_cluster_id"></a> [aurora\_postgresql\_v2\_cluster\_id](#output\_aurora\_postgresql\_v2\_cluster\_id) | The RDS Cluster Identifier |
55+
| <a name="output_aurora_postgresql_v2_cluster_instances"></a> [aurora\_postgresql\_v2\_cluster\_instances](#output\_aurora\_postgresql\_v2\_cluster\_instances) | A map of cluster instances and their attributes |
56+
| <a name="output_aurora_postgresql_v2_cluster_master_password"></a> [aurora\_postgresql\_v2\_cluster\_master\_password](#output\_aurora\_postgresql\_v2\_cluster\_master\_password) | The database master password |
57+
| <a name="output_aurora_postgresql_v2_cluster_master_username"></a> [aurora\_postgresql\_v2\_cluster\_master\_username](#output\_aurora\_postgresql\_v2\_cluster\_master\_username) | The database master username |
58+
| <a name="output_aurora_postgresql_v2_cluster_members"></a> [aurora\_postgresql\_v2\_cluster\_members](#output\_aurora\_postgresql\_v2\_cluster\_members) | List of RDS Instances that are a part of this cluster |
59+
| <a name="output_aurora_postgresql_v2_cluster_port"></a> [aurora\_postgresql\_v2\_cluster\_port](#output\_aurora\_postgresql\_v2\_cluster\_port) | The database port |
60+
| <a name="output_aurora_postgresql_v2_cluster_reader_endpoint"></a> [aurora\_postgresql\_v2\_cluster\_reader\_endpoint](#output\_aurora\_postgresql\_v2\_cluster\_reader\_endpoint) | A read-only endpoint for the cluster, automatically load-balanced across replicas |
61+
| <a name="output_aurora_postgresql_v2_cluster_resource_id"></a> [aurora\_postgresql\_v2\_cluster\_resource\_id](#output\_aurora\_postgresql\_v2\_cluster\_resource\_id) | The RDS Cluster Resource ID |
62+
| <a name="output_aurora_postgresql_v2_cluster_role_associations"></a> [aurora\_postgresql\_v2\_cluster\_role\_associations](#output\_aurora\_postgresql\_v2\_cluster\_role\_associations) | A map of IAM roles associated with the cluster and their attributes |
63+
| <a name="output_aurora_postgresql_v2_db_subnet_group_name"></a> [aurora\_postgresql\_v2\_db\_subnet\_group\_name](#output\_aurora\_postgresql\_v2\_db\_subnet\_group\_name) | The db subnet group name |

infrastructure/rds/main.tf

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
terraform {
2+
required_version = "~> 1.5.6"
3+
4+
backend "s3" {
5+
bucket = "cafi-demo1"
6+
key = "demos/dogeapi/rds/terraform.tfstate"
7+
region = "us-east-1"
8+
role_arn = "arn:aws:iam::180217099948:role/atlantis-access"
9+
}
10+
11+
required_providers {
12+
aws = {
13+
source = "hashicorp/aws"
14+
version = "~> 5.0"
15+
}
16+
}
17+
}
18+
19+
provider "aws" {
20+
region = var.aws_region
21+
assume_role {
22+
role_arn = "arn:aws:iam::180217099948:role/atlantis-access"
23+
}
24+
}
25+
26+
locals {
27+
tags = {
28+
Terraform = "True"
29+
Environment = var.environment
30+
}
31+
}
32+
33+
# PostgreSQL Serverless v2
34+
data "aws_rds_engine_version" "postgresql" {
35+
engine = "aurora-postgresql"
36+
version = var.postgresql_engine_version
37+
}
38+
39+
module "aurora_postgresql_v2" {
40+
source = "terraform-aws-modules/rds-aurora/aws"
41+
42+
name = "${var.database_name}-${var.environment}"
43+
engine = data.aws_rds_engine_version.postgresql.engine
44+
engine_mode = "provisioned"
45+
engine_version = data.aws_rds_engine_version.postgresql.version
46+
storage_encrypted = true
47+
manage_master_user_password = true
48+
master_username = "root"
49+
50+
vpc_id = var.vpc_id
51+
db_subnet_group_name = var.db_subnet_group_name
52+
security_group_rules = {
53+
vpc_ingress = {
54+
cidr_blocks = var.private_subnets_cidr_blocks
55+
}
56+
}
57+
58+
# Enhanced monitoring disabled for now
59+
monitoring_interval = 0
60+
61+
apply_immediately = true
62+
skip_final_snapshot = true
63+
64+
serverlessv2_scaling_configuration = {
65+
min_capacity = 0.5
66+
max_capacity = 1
67+
}
68+
69+
instance_class = "db.serverless"
70+
instances = {
71+
one = {}
72+
two = {}
73+
}
74+
75+
tags = local.tags
76+
}

infrastructure/rds/output.tf

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# aws_db_subnet_group
2+
output "aurora_postgresql_v2_db_subnet_group_name" {
3+
description = "The db subnet group name"
4+
value = module.aurora_postgresql_v2.db_subnet_group_name
5+
}
6+
7+
# aws_rds_cluster
8+
output "aurora_postgresql_v2_cluster_arn" {
9+
description = "Amazon Resource Name (ARN) of cluster"
10+
value = module.aurora_postgresql_v2.cluster_arn
11+
}
12+
13+
output "aurora_postgresql_v2_cluster_id" {
14+
description = "The RDS Cluster Identifier"
15+
value = module.aurora_postgresql_v2.cluster_id
16+
}
17+
18+
output "aurora_postgresql_v2_cluster_resource_id" {
19+
description = "The RDS Cluster Resource ID"
20+
value = module.aurora_postgresql_v2.cluster_resource_id
21+
}
22+
23+
output "aurora_postgresql_v2_cluster_members" {
24+
description = "List of RDS Instances that are a part of this cluster"
25+
value = module.aurora_postgresql_v2.cluster_members
26+
}
27+
28+
output "aurora_postgresql_v2_cluster_endpoint" {
29+
description = "Writer endpoint for the cluster"
30+
value = module.aurora_postgresql_v2.cluster_endpoint
31+
}
32+
33+
output "aurora_postgresql_v2_cluster_reader_endpoint" {
34+
description = "A read-only endpoint for the cluster, automatically load-balanced across replicas"
35+
value = module.aurora_postgresql_v2.cluster_reader_endpoint
36+
}
37+
38+
output "aurora_postgresql_v2_cluster_engine_version_actual" {
39+
description = "The running version of the cluster database"
40+
value = module.aurora_postgresql_v2.cluster_engine_version_actual
41+
}
42+
43+
# database_name is not set on `aws_rds_cluster` resource if it was not specified, so can't be used in output
44+
output "aurora_postgresql_v2_cluster_database_name" {
45+
description = "Name for an automatically created database on cluster creation"
46+
value = module.aurora_postgresql_v2.cluster_database_name
47+
}
48+
49+
output "aurora_postgresql_v2_cluster_port" {
50+
description = "The database port"
51+
value = module.aurora_postgresql_v2.cluster_port
52+
}
53+
54+
output "aurora_postgresql_v2_cluster_master_password" {
55+
description = "The database master password"
56+
value = module.aurora_postgresql_v2.cluster_master_password
57+
sensitive = true
58+
}
59+
60+
output "aurora_postgresql_v2_cluster_master_username" {
61+
description = "The database master username"
62+
value = module.aurora_postgresql_v2.cluster_master_username
63+
sensitive = true
64+
}
65+
66+
output "aurora_postgresql_v2_cluster_hosted_zone_id" {
67+
description = "The Route53 Hosted Zone ID of the endpoint"
68+
value = module.aurora_postgresql_v2.cluster_hosted_zone_id
69+
}
70+
71+
# aws_rds_cluster_instances
72+
output "aurora_postgresql_v2_cluster_instances" {
73+
description = "A map of cluster instances and their attributes"
74+
value = module.aurora_postgresql_v2.cluster_instances
75+
}
76+
77+
# aws_rds_cluster_endpoint
78+
output "aurora_postgresql_v2_additional_cluster_endpoints" {
79+
description = "A map of additional cluster endpoints and their attributes"
80+
value = module.aurora_postgresql_v2.additional_cluster_endpoints
81+
}
82+
83+
# aws_rds_cluster_role_association
84+
output "aurora_postgresql_v2_cluster_role_associations" {
85+
description = "A map of IAM roles associated with the cluster and their attributes"
86+
value = module.aurora_postgresql_v2.cluster_role_associations
87+
}

0 commit comments

Comments
 (0)