deploy spring boot application on ECS fargate using buildPacks

1

Hi team,

I have a spring boot application I want to deploy it to my fargate cluster using codePipeline,

in my build buildspec.yml is it best practice to use tye Cloud Native Build packs to generate the image or to use dockerfile with docker commands :

docker build -t, docker tag ...

if it's best practice to use build packs

I found 2 ways to do it :

1 - buildpack-builder build my-app -p my-app/ --builder cloudfoundry/cnb:bionic

2 - by installing the build packs in the installation phase : echo "$(curl -Ls https://github.com/buildpacks/pack/releases/download/v0.13.0/pack-v0.13.0-linux.tgz | gunzip | tar -xf - -C /usr/local/bin)"

not sure what is the difference between them and which one is best to use.

is there a complete example of a buildspec.yml using buildPacks

Thank you for your help,

Regards,

1 Answer
0

Hello there,

Thank you for contacting AWS support!

I understand that you want an example of a CodeBuild buildspec.yml file which uses buildPacks as you want to know the best practise for the same.

I would like to inform you that latest iteration of buildpacks can be thought of as decoupling the build mechanism of these platforms so that it can be consumed by the broader container community. As this project has matured, it has been adopted by a number of vendors and tools.

Additionally, I would like to mention that writing custom buildspec falls out of our support scope, however, I would be providing you a sample Buidlspec.yml file for your use-case:

version: 0.2
env:
  variables:
    builder: "paketobuildpacks/builder:base"
    pack_version: "0.18.1"
    application_name: "default_application"
  exported-variables:
  # Exported the image tag to be used later in the CodePipeline
  - IMAGE_TAG

phases:
  install:
    commands:
    # Download the pack linux binary
    - wget -q https://github.com/buildpacks/pack/releases/download/v$pack_version/pack-v$pack_version-linux.tgz -O - | tar -xz
    - chmod +x ./pack
  pre_build:
    commands:
    # Log in to ECR
    - ECR_DOMAIN="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com"
    - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $ECR_DOMAIN
    # Set up some derived values for subsequent phases
    - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
    - ECR_REPOSITORY="$ECR_DOMAIN/$application_name"
    - IMAGE_TAG="$ECR_REPOSITORY:$COMMIT_HASH"
  build:
    commands:
    - |
      ./pack build --no-color --builder $builder \
      --tag $IMAGE_TAG $ECR_REPOSITORY:latest \
      --cache-image $ECR_REPOSITORY:cache \
      --publish

Please use the above .yml file for example and configure your buildspec files as per your use-case.

I hope the information provided above is useful.

Thanks!

AWS
SUPPORT ENGINEER
answered a year ago
  • thank you for your answer, I understand from your answer this is not the recommended way to do it from AWS. So what would be the AWS recommended way to build a spring boot application?

    Thank you

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions