Skip to content

Commit fcae196

Browse files
committed
creating fully featured codepipeline
1 parent 3516eb5 commit fcae196

File tree

6 files changed

+210
-3
lines changed

6 files changed

+210
-3
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: 0.2
2+
3+
phases:
4+
install:
5+
runtime-versions:
6+
python: 3.12 # Specify the desired Python version
7+
commands:
8+
- echo "Installing required dependencies..."
9+
- pip install --upgrade pip
10+
- pip install -r requirements.txt
11+
- pip install black # Install black
12+
pre_build:
13+
commands:
14+
- echo "Starting format check with black..."
15+
build:
16+
commands:
17+
- echo "Running black format check..."
18+
- black --check src/ # Check formatting without modifying files
19+
post_build:
20+
commands:
21+
- echo "Format check completed."
22+
23+
artifacts:
24+
files:
25+
- "**/*" # Include all files
26+
discard-paths: yes
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: 0.2
2+
3+
phases:
4+
install:
5+
runtime-versions:
6+
python: 3.12 # Specify the desired Python version
7+
commands:
8+
- echo "Installing required dependencies..."
9+
- pip install --upgrade pip
10+
- pip install -r requirements.txt
11+
- pip install pylint # Install pylint
12+
pre_build:
13+
commands:
14+
- echo "Starting pylint checks..."
15+
build:
16+
commands:
17+
- echo "Running pylint documentation check..."
18+
- pylint src/ # Check for missing docstrings
19+
- echo "Documentation check completed."
20+
post_build:
21+
commands:
22+
- echo "Pylint documentation check completed successfully."
23+
24+
artifacts:
25+
files:
26+
- "**/*" # Include all files
27+
discard-paths: yes

terraform/pipelines/modules/codepipeline/buildspecs/ossdepscan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 0.2
33
phases:
44
install:
55
runtime-versions:
6-
python: 3.9
6+
python: 3.12
77
commands:
88
- echo "Installing container scanning tools..."
99
- pip install --upgrade pip

terraform/pipelines/modules/codepipeline/buildspecs/sastscanning.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ phases:
1212
pre_build:
1313
commands:
1414
- echo "Installing dependencies..."
15+
- pip install --upgrade pip
1516
- pip install -r requirements.txt
1617
build:
1718
commands:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: 0.2
2+
3+
phases:
4+
install:
5+
runtime-versions:
6+
python: 3.12 # Specify the desired Python version
7+
commands:
8+
- echo "Installing required dependencies..."
9+
- pip install --upgrade pip
10+
- pip install -r requirements.txt
11+
- pip install pytest pytest-cov # Install pytest and pytest-cov for coverage reporting
12+
pre_build:
13+
commands:
14+
- echo "Starting unit test process..."
15+
build:
16+
commands:
17+
- echo "Running pytest with coverage reporting..."
18+
# Run tests and generate coverage report
19+
- pytest --cov=src --cov-report=xml --cov-report=term-missing --cov-fail-under=80
20+
post_build:
21+
commands:
22+
- echo "Unit testing and coverage reporting completed."
23+
24+
artifacts:
25+
files:
26+
- "coverage.xml" # Include the coverage report as an artifact
27+
discard-paths: yes

terraform/pipelines/modules/codepipeline/main.tf

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,25 +240,69 @@ resource "aws_codepipeline" "pipeline" {
240240
name = "Test"
241241

242242
action {
243-
name = "StaticCodeAnalysis"
243+
name = "FormatCheck"
244244
category = "Test"
245245
owner = "AWS"
246246
provider = "CodeBuild"
247247
version = "1"
248248
input_artifacts = ["BuildArtifact"]
249+
run_order = 1
250+
251+
configuration = {
252+
ProjectName = aws_codebuild_project.format_check_project.name
253+
}
254+
}
255+
256+
action {
257+
name = "LintCheck"
258+
category = "Test"
259+
owner = "AWS"
260+
provider = "CodeBuild"
261+
version = "1"
262+
input_artifacts = ["BuildArtifact"]
263+
run_order = 1
264+
265+
configuration = {
266+
ProjectName = aws_codebuild_project.lint_check_project.name
267+
}
268+
}
269+
270+
action {
271+
name = "RunUnitTests"
272+
category = "Test"
273+
owner = "AWS"
274+
provider = "CodeBuild"
275+
version = "1"
276+
input_artifacts = ["BuildArtifact"]
277+
run_order = 2
278+
279+
configuration = {
280+
ProjectName = aws_codebuild_project.unittest_project.name
281+
}
282+
}
283+
284+
action {
285+
name = "SnykSecurityScan"
286+
category = "Test"
287+
owner = "AWS"
288+
provider = "CodeBuild"
289+
version = "1"
290+
input_artifacts = ["BuildArtifact"]
291+
run_order = 3
249292

250293
configuration = {
251294
ProjectName = aws_codebuild_project.static_analysis_project.name
252295
}
253296
}
254297

255298
action {
256-
name = "OSSDependencyScan"
299+
name = "ContainerSecurityScan"
257300
category = "Test"
258301
owner = "AWS"
259302
provider = "CodeBuild"
260303
version = "1"
261304
input_artifacts = ["BuildArtifact"]
305+
run_order = 3
262306

263307
configuration = {
264308
ProjectName = aws_codebuild_project.oss_scanning_project.name
@@ -313,6 +357,88 @@ resource "aws_codebuild_project" "build_project" {
313357
}
314358
}
315359

360+
resource "aws_codebuild_project" "format_check_project" {
361+
name = "${var.repo_name}-formatcheck-project"
362+
service_role = aws_iam_role.codebuild_role.arn
363+
364+
environment {
365+
compute_type = var.compute_type
366+
image = var.build_image
367+
type = var.environment_type
368+
privileged_mode = var.privileged_mode
369+
370+
environment_variable {
371+
name = "IMAGE_REPO_NAME"
372+
value = aws_ecr_repository.this.name
373+
}
374+
}
375+
376+
source {
377+
type = "NO_SOURCE"
378+
buildspec = file("${path.module}/buildspecs/formatcheck.yml")
379+
}
380+
381+
artifacts {
382+
type = "S3"
383+
location = var.s3_bucket_name
384+
}
385+
}
386+
387+
resource "aws_codebuild_project" "unittest_project" {
388+
name = "${var.repo_name}-unittest-project"
389+
service_role = aws_iam_role.codebuild_role.arn
390+
391+
environment {
392+
compute_type = var.compute_type
393+
image = var.build_image
394+
type = var.environment_type
395+
privileged_mode = var.privileged_mode
396+
397+
environment_variable {
398+
name = "IMAGE_REPO_NAME"
399+
value = aws_ecr_repository.this.name
400+
}
401+
}
402+
403+
source {
404+
type = "NO_SOURCE"
405+
buildspec = file("${path.module}/buildspecs/unittests.yml")
406+
}
407+
408+
artifacts {
409+
type = "S3"
410+
location = var.s3_bucket_name
411+
}
412+
}
413+
414+
415+
resource "aws_codebuild_project" "lint_check_project" {
416+
name = "${var.repo_name}-lintcheck-project"
417+
service_role = aws_iam_role.codebuild_role.arn
418+
419+
environment {
420+
compute_type = var.compute_type
421+
image = var.build_image
422+
type = var.environment_type
423+
privileged_mode = var.privileged_mode
424+
425+
environment_variable {
426+
name = "IMAGE_REPO_NAME"
427+
value = aws_ecr_repository.this.name
428+
}
429+
}
430+
431+
source {
432+
type = "NO_SOURCE"
433+
buildspec = file("${path.module}/buildspecs/lintcheck.yml")
434+
}
435+
436+
artifacts {
437+
type = "S3"
438+
location = var.s3_bucket_name
439+
}
440+
}
441+
316442
resource "aws_codebuild_project" "deploy_project" {
317443
name = "${var.repo_name}-deploy-prj"
318444
service_role = aws_iam_role.codebuild_role.arn

0 commit comments

Comments
 (0)