|
1 | 1 | version: 0.2 |
| 2 | + |
| 3 | +env: |
| 4 | + secrets-manager: |
| 5 | + DOCKER_HUB_USERNAME: cicd/docker-hub/username |
| 6 | + DOCKER_HUB_PAT: cicd/docker-hub/pat |
| 7 | + |
2 | 8 | phases: |
3 | 9 | install: |
4 | 10 | runtime-versions: |
5 | 11 | python: 3.11 |
6 | 12 | commands: |
7 | 13 | - pip install cfn-lint |
| 14 | + |
| 15 | + pre_build: |
| 16 | + commands: |
| 17 | + - echo Logging in to Docker Hub... |
| 18 | + - echo $DOCKER_HUB_PAT | docker login -u $DOCKER_HUB_USERNAME --password-stdin |
| 19 | + |
8 | 20 | build: |
9 | | - # This should be moved to a shell script if it gets more complicated. |
| 21 | + # This will build and push the docker image to ECR and package the |
| 22 | + # Cloudformation template to be passed as an Artifact to future pipeline |
| 23 | + # steps. It will also run unit tests and linting. |
10 | 24 | commands: |
11 | 25 | - set -e |
12 | 26 | - BRANCH_NAME=${CODEBUILD_WEBHOOK_HEAD_REF#"refs/heads/"} |
13 | 27 |
|
14 | | - - echo "This is where I would run python tests, if I had any tests" |
| 28 | + - cd $CODEBUILD_SRC_DIR |
| 29 | + |
| 30 | + - echo "Validating Cloudformation Templates..." |
| 31 | + - cfn-lint cicd/1-setup/*.template.yml |
| 32 | + - cfn-lint cicd/2-cicd/*.template.yml |
| 33 | + - cfn-lint cicd/3-app/aiproxy/template.yml |
15 | 34 |
|
| 35 | + - echo "Building Docker Image..." |
| 36 | + - IMAGE_NAME=aiproxy |
| 37 | + - IMAGE_TAG=$(git rev-parse --short HEAD) |
| 38 | + - docker build -t ${IMAGE_NAME}:${IMAGE_TAG} . |
| 39 | + |
| 40 | + - echo "Running Unit Tests..." |
| 41 | + - echo "This is where I would run my unit tests" |
| 42 | + |
| 43 | + - echo "Pushing Docker Image to ECR..." |
| 44 | + - ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) |
| 45 | + - AWS_REGION=$(aws configure get region) |
| 46 | + - ECR_REGISTRY="${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" |
| 47 | + - ECR_REPO_NAME="aiproxy-${BRANCH_NAME}" |
| 48 | + - FULL_IMAGE_NAME="${ECR_REGISTRY}/${ECR_REPO_NAME}:${IMAGE_TAG}" |
| 49 | + - aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_REGISTRY} |
| 50 | + - docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${FULL_IMAGE_NAME} |
| 51 | + - docker push ${FULL_IMAGE_NAME} |
| 52 | + |
| 53 | + - echo "Linting cloudformation..." |
16 | 54 | - cd $CODEBUILD_SRC_DIR |
17 | 55 | - cp cicd/3-app/aiproxy/template.yml ./template.yml |
18 | 56 | - cfn-lint template.yml |
19 | 57 | - cat template.yml |
20 | 58 |
|
| 59 | + - echo "Creating environment config..." |
21 | 60 | - cicd/3-app/aiproxy/config/create-environment-config.sh |
22 | 61 |
|
| 62 | + - echo "Packaging Cloudformation Template..." |
23 | 63 | - aws cloudformation package --template-file template.yml --s3-bucket $ARTIFACT_STORE --s3-prefix package --output-template-file packaged-app-template.yml |
| 64 | + |
| 65 | + - echo "Running ls command..." |
| 66 | + - ls |
24 | 67 | artifacts: |
25 | 68 | files: '**/*' |
0 commit comments