0

I have setup a cicd pipeline using AWS Codepipeline and AWS CodeBuild. Right now my application's frontend and backend are present in different repositories. I have two source stages in my Codepipeline. Now I want to build both frontend image and backend image in the CodeBuild using buildspec.yml file.

Problem

I am very confused how to setup buildspec.yml files for both frontend and backend repos. Do I have to specify buildspec.yml file in both repos separate or I have to specify buildspec.yml file only in PrimarySource repository.

This is my buildspec.yml file:

version: 0.2

phases:
  install:
    runtime-versions:
      docker: 18
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws --version
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_TAG=${COMMIT_HASH:=latest}
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...
      - docker build -t $ECR_REPOSITORY_URI:latest .
      - docker tag $ECR_REPOSITORY_URI:latest $ECR_REPOSITORY_URI:$IMAGE_TAG
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker images...
      - docker push $ECR_REPOSITORY_URI:latest
      - docker push $ECR_REPOSITORY_URI:$IMAGE_TAG
      - printf '{"ImageURI":"%s:%s"}' $ECR_REPOSITORY_URI $IMAGE_TAG > imageDetail.json
artifacts:
  files:
    - imageDetail.json

I want to know how I can setup similar for backend too. So, my Codebuild should first build for frontend and then for backend.

  • How about using the buildSpec commands inline while creating the codebuild project instead of using the buildSpec.yml file in each repository? – Levi Dec 06 '22 at 15:42

0 Answers0