Skip to content

Commit b5c40bc

Browse files
scriptify pr buildspec
1 parent 9b0367f commit b5c40bc

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

ci-build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [ -n "$CODEBUILD_BUILD_ID" ]; then
6+
# CodeBuild environment
7+
IMAGE_TAG=${CODEBUILD_RESOLVED_SOURCE_VERSION:0:7}
8+
else
9+
# Local Git repository
10+
IMAGE_TAG=$(git rev-parse --short HEAD)
11+
fi
12+
13+
IMAGE_NAME=aiproxy
14+
15+
echo "Building Docker Image ${IMAGE_NAME}:${IMAGE_TAG}..."
16+
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .

ci-lint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo "Validating Cloudformation Templates via cfn-lint docker..."
6+
docker run --rm -i
7+
cfn-lint cicd/1-setup/*.template.yml
8+
cfn-lint cicd/2-cicd/*.template.yml
9+
cfn-lint cicd/3-app/aiproxy/template.yml
10+
11+
echo "Validating Dockerfile..."
12+
docker run --rm -i hadolint/hadolint < Dockerfile

cicd/3-app/aiproxy/pr-buildspec.yml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,15 @@ phases:
1717
- echo Logging in to Docker Hub...
1818
- echo $DOCKER_HUB_PAT | docker login -u $DOCKER_HUB_USERNAME --password-stdin
1919

20-
2120
build:
22-
# This should be moved to a shell script if it gets more complicated.
2321
commands:
2422
- set -e
2523

2624
- BRANCH_NAME=${CODEBUILD_WEBHOOK_HEAD_REF#"refs/heads/"}
2725
- ARTIFACT_PATH=branch/$BRANCH_NAME/$CODEBUILD_BUILD_NUMBER
26+
- COMMIT_HASH=${CODEBUILD_RESOLVED_SOURCE_VERSION:0:7}
2827

2928
- cd $CODEBUILD_SRC_DIR
3029

31-
- echo "Validating Cloudformation Templates..."
32-
- cfn-lint cicd/1-setup/*.template.yml
33-
- cfn-lint cicd/2-cicd/*.template.yml
34-
- cfn-lint cicd/3-app/aiproxy/template.yml
35-
36-
- echo "Building Docker Image..."
37-
- IMAGE_NAME=aiproxy
38-
- IMAGE_TAG=${CODEBUILD_RESOLVED_SOURCE_VERSION:0:7}
39-
- docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
40-
41-
- echo "Running Unit Tests..."
42-
- docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} python -m unittest test_app.py
43-
44-
- echo "Pushing Docker Image to ECR..."
45-
- echo "This is where I would push the docker image to ECR, when I get around to it"
30+
- ./ci-lint.sh
31+
- ./ci-build.sh

0 commit comments

Comments
 (0)