Skip to content

Commit 7f7bb16

Browse files
add build steps to buildspec
1 parent 808006b commit 7f7bb16

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

cicd/1-setup/deploy-cicd-dependencies.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ read -r -p "Would you like to deploy this template to AWS account $ACCOUNT? [y/N
1919
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
2020
then
2121
echo Updating cloudformation stack...
22+
echo "Follow along at https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks?filteringText=aiproxy-cicd-deps&filteringStatus=active&viewNested=true&hideStacks=false"
2223
aws cloudformation deploy \
2324
--stack-name aiproxy-cicd-deps \
2425
--template-file ${TEMPLATE_FILE} \

cicd/3-app/aiproxy/buildspec.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,51 @@ phases:
66
commands:
77
- pip install cfn-lint
88
build:
9-
# This should be moved to a shell script if it gets more complicated.
9+
# This will build and push the docker image to ECR and package the
10+
# Cloudformation template to be passed as an Artifact to future pipeline
11+
# steps. It will also run unit tests and linting.
1012
commands:
1113
- set -e
1214
- BRANCH_NAME=${CODEBUILD_WEBHOOK_HEAD_REF#"refs/heads/"}
1315

14-
- echo "This is where I would run python tests, if I had any tests"
16+
- cd $CODEBUILD_SRC_DIR
17+
18+
- echo "Validating Cloudformation Templates..."
19+
- cfn-lint cicd/1-setup/*.template.yml
20+
- cfn-lint cicd/2-cicd/*.template.yml
21+
- cfn-lint cicd/3-app/aiproxy/template.yml
22+
23+
- echo "Building Docker Image..."
24+
- IMAGE_NAME=aiproxy
25+
- IMAGE_TAG=$(git rev-parse --short HEAD)
26+
- docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
1527

28+
- echo "Running Unit Tests..."
29+
- echo "This is where I would run my unit tests"
30+
31+
- echo "Pushing Docker Image to ECR..."
32+
- ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
33+
- AWS_REGION=$(aws configure get region)
34+
- ECR_REGISTRY="${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
35+
- ECR_REPO_NAME="aiproxy-${BRANCH_NAME}"
36+
- FULL_IMAGE_NAME="${ECR_REGISTRY}/${ECR_REPO_NAME}:${IMAGE_TAG}"
37+
- aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_REGISTRY}
38+
- docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${FULL_IMAGE_NAME}
39+
- docker push ${FULL_IMAGE_NAME}
40+
41+
- echo "Linting cloudformation..."
1642
- cd $CODEBUILD_SRC_DIR
1743
- cp cicd/3-app/aiproxy/template.yml ./template.yml
1844
- cfn-lint template.yml
1945
- cat template.yml
2046

47+
- echo "Creating environment config..."
2148
- cicd/3-app/aiproxy/config/create-environment-config.sh
2249

50+
- echo "Packaging Cloudformation Template..."
2351
- aws cloudformation package --template-file template.yml --s3-bucket $ARTIFACT_STORE --s3-prefix package --output-template-file packaged-app-template.yml
52+
53+
- echo "Running ls command..."
54+
- ls
2455
artifacts:
2556
files: '**/*'

cicd/3-app/aiproxy/integration-test-buildspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ phases:
1010
commands:
1111
- set -e
1212

13-
- echo "This is where I would run my integration tests, if I had any tests"
13+
- echo "This is where I would run my tests against the Test environment, if I had any tests"

0 commit comments

Comments
 (0)