# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 version: 0.2 phases: pre_build: commands: - echo Logging in to Amazon ECR... - aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com - echo Checking for build type - | if expr "${FOLDER_PATH}" : ".*client*" ; then echo "Client build, embedding frontend layer file with ALB backend DNS" sed -i "s||$SERVER_ALB_URL|g" ./Code/client/src/services/RestServices.js else echo "Server build, adding ECS Task Role to the task definition file" sed -i "3i\"taskRoleArn\": \"arn:aws:iam:::role/\"," ./Infrastructure/Templates/taskdef.json echo "Replacing table name in the server function" sed -i "s|DYNAMODB_TABLE|$DYNAMODB_TABLE|g" ./Code/server/src/app.js echo "Adding Swagger host" sed -i "s||$SERVER_ALB_URL|g" ./Code/server/src/swagger/swagger.js fi build: commands: - echo Build started on `date` - echo Building the Docker image... - docker build -t $REPO_URL $FOLDER_PATH post_build: commands: - echo Build completed on `date` - echo Pushing the Docker image... - docker push $REPO_URL:$IMAGE_TAG - echo Changing directory to Templates directory - cd ./Infrastructure/Templates - echo Preparing spec files in new folder - mkdir Artifacts - cp appspec.yaml Artifacts/appspec.yaml && cp taskdef.json Artifacts/taskdef.json - echo Changing directory to the Artifacts directory - cd Artifacts - echo Preparating artifacts - sed -i "s||$TASK_DEFINITION_FAMILY|g" taskdef.json - sed -i "s||$CONTAINER_NAME|g" appspec.yaml taskdef.json - sed -i "s||$SERVICE_PORT|g" appspec.yaml taskdef.json - sed -i "s||$ECS_ROLE|g" taskdef.json - sed -i "s||$ECS_TASK_ROLE|g" taskdef.json - sed -i "s||$REPO_URL|g" taskdef.json - sed -i "s||$AWS_ACCOUNT_ID|g" taskdef.json - sed -i "s||$AWS_REGION|g" taskdef.json artifacts: files: - '**/*' base-directory: 'Infrastructure/Templates/Artifacts' discard-paths: yes