version: 0.2 env: parameter-store: container_registry: "/ingenspark/aws/docker_registry" ecr_repo: "/mr-mvp/backend-api/ecr-repo" aws_region: "/ingenspark/aws/region" access_key: "/ingenspark/aws/access_key" secret_key: "/ingenspark/aws/secret_key" gitlab_username: "/ingenspark/gitlab_username" gitlab_credentials: "/ingenspark/gitlab_credentials" phases: install: run-as: root on-failure: ABORT commands: - echo Updating latest updates in linux... - yum update -y finally: - docker --version - aws configure set aws_access_key_id $access_key - aws configure set aws_secret_access_key $secret_key - aws configure set region $aws_region - aws configure get region - echo AWS Access Key,Secret Key and Region is configured pre_build: run-as: root on-failure: ABORT commands: - echo Entered the pre_build phase... - aws ecr get-login-password --region $aws_region | docker login --username AWS --password-stdin $container_registry - echo ECR Docker Login has successful... build: run-as: root on-failure: ABORT commands: - echo Entered the build phase... - echo Build started on `date` - echo $CODEBUILD_BUILD_NUMBER - echo $buildnumber - echo $CODEBUILD_BUILD_SUCCEEDING - pwd - ls -la - docker build -t $container_registry/$ecr_repo:$env_image_tag$CODEBUILD_BUILD_NUMBER --build-arg build_env=$build_env . - docker images - docker push $container_registry/$ecr_repo:$env_image_tag$CODEBUILD_BUILD_NUMBER - echo $container_registry/$ecr_repo:$env_image_tag$CODEBUILD_BUILD_NUMBER finally: - echo Build successfully completed post_build: run-as: root on-failure: ABORT commands: - echo "Updating GIT Repository" - touch ~/.git-credentials - echo $gitlab_credentials - echo $gitlab_credentials > ~/.git-credentials - git config --global user.email "nsainath0289@gmail.com" - echo "$gitlab_username" - git config --global user.name "$gitlab_username" - git config --global credential.helper 'store --file ~/.git-credentials' - echo git crendentials saved successfully... - echo $(($CODEBUILD_BUILD_NUMBER-1)) - pwd - git clone -b main $git_repo /root/igw-gitops - cd - pwd - cd $git_path - sed -i "s|$container_registry/$ecr_repo:$env_image_tag$(($CODEBUILD_BUILD_NUMBER-1))|$container_registry/$ecr_repo:$env_image_tag$CODEBUILD_BUILD_NUMBER|g" $deployment_file finally: - echo Pushing code to Code Commit Repository - git add . - git commit -am "updating backend api deployment yaml file" - git push origin main - echo Finished pushing to GIT Repository