Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save abdullahEmumba/07fbdb1fdab9b13c6a35147bee34b1a5 to your computer and use it in GitHub Desktop.
Save abdullahEmumba/07fbdb1fdab9b13c6a35147bee34b1a5 to your computer and use it in GitHub Desktop.
Node22 App Bitbucket Pipeline For Fargate Deployment, Includes running E2E tests , Upload Image to ECR, Register New Task Definition, Update Fargate Service
definitions:
services:
docker:
memory: 5120
pipelines:
branches:
branch-name:
- step:
name: Run Unit and E2E Tests
services:
- docker
size: 2x
image: node:22.15.1-alpine3.21
script:
- export TESTCONTAINERS_RYUK_DISABLED=true
- export TESTCONTAINERS_CHECKS_DISABLE=true
- npm install -g pnpm@latest-10
- pnpm install --frozen-lockfile
- pnpm run test
- apk update && apk upgrade
- apk add jq
- touch ./image_version.txt
- export IMAGE_VERSION=$(jq -r .version package.json)
- echo $IMAGE_VERSION >> image_version.txt
artifacts:
- image_version.txt
- step:
name: Build & Upload Image
services:
- docker
size: 2x
image: atlassian/pipelines-awscli
script:
- export IMAGE_VERSION=$(cat ./image_version.txt)
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ECR_REPO_PROD
- docker build -t upm-paper-aws-api:$IMAGE_VERSION .
- docker tag upm-paper-aws-api:$IMAGE_VERSION $AWS_ECR_REPO_PROD:$IMAGE_VERSION
- docker push $AWS_ECR_REPO_PROD:$IMAGE_VERSION
- export IMAGE_NAME=$AWS_ECR_REPO_PROD:$IMAGE_VERSION
- echo $IMAGE_NAME >> image_name.txt
artifacts:
- image_name.txt
- step:
name: Register Task definition
script:
- apt-get update >> /dev/null && apt-get install -y unzip curl gettext >> /dev/null
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- unzip awscliv2.zip >> /dev/null
- ./aws/install
- aws --version
- export IMAGE_NAME=$(cat ./image_name.txt)
- envsubst < .aws/prod.task.definition.json > updated.prod.json
- export UPDATED_TASK_DEFINITION=$(aws ecs register-task-definition --region $AWS_DEFAULT_REGION --cli-input-json file://updated.prod.json --output text --query 'taskDefinition.taskDefinitionArn')
- echo $UPDATED_TASK_DEFINITION >> task_arn.txt
artifacts:
- task_arn.txt
- step:
name: Update ECS service
image: atlassian/pipelines-awscli
trigger: manual
script:
- export UPDATED_TASK_DEFINITION=$(cat ./task_arn.txt)
- echo $UPDATED_TASK_DEFINITION
- aws ecs update-service --service $AWS_SERVICE_NAME_PROD --cluster $AWS_CLUSTER_NAME_PROD --task-definition $UPDATED_TASK_DEFINITION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment