-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitbucket-pipelines.yml
69 lines (66 loc) · 2.53 KB
/
bitbucket-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
image: node:16.15
definitions:
steps:
- step: &test-build
name: Test & Build
caches:
- node
script:
- npm ci
- npm run lint
- npm run build
artifacts:
- dist/**
- step: &build_publish_and_deploy
image: node:alpine
name: Backend build/publish docker to ECR, deploy to ECS, and lambda build/deploy.
services:
# Enable Docker for your repository
- docker
script:
# Creating environment variables
- export NAME_PREFIX="${PROJECT_NAME}--${WORKSPACE_NAME}"
- export NAME_PREFIX_SINGLE="${PROJECT_NAME}-${WORKSPACE_NAME}"
- export CLUSTER_NAME="${NAME_PREFIX}--ecs-cluster"
- export SERVICE_NAME="${NAME_PREFIX}--ecs-service"
- export TASK_FAMILY="${NAME_PREFIX}--task-definition"
- export ECR_NAME="${NAME_PREFIX_SINGLE}-ecr-repository"
- export AWS_ECR_REPO="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${ECR_NAME}"
- export EXECUTION_ROLE_ARN="arn:aws:iam::${AWS_ACCOUNT_ID}:role/${NAME_PREFIX}--ecs-task-exec-role"
# Install envsubst
- apk update && apk add gettext
# Set the name of the docker image we will be building.
- export IMAGE_NAME="${ECR_NAME}"
# Build the docker image
- docker build -t "${IMAGE_NAME}" .
# Push to ECR
- pipe: atlassian/aws-ecr-push-image:1.5.0
variables:
IMAGE_NAME: $IMAGE_NAME
TAGS: $BITBUCKET_BUILD_NUMBER
# Replace the docker image name in the task definition with the newly pushed image.
- export IMAGE_NAME="${AWS_ECR_REPO}:${BITBUCKET_BUILD_NUMBER}"
- envsubst < task-definition-template.json > task-definition.json
# Update the task definition.
- pipe: atlassian/aws-ecs-deploy:1.6.2
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
CLUSTER_NAME: $CLUSTER_NAME
SERVICE_NAME: $SERVICE_NAME
TASK_DEFINITION: 'task-definition.json'
FORCE_NEW_DEPLOYMENT: 'true'
pipelines:
pull-requests:
'**':
- step: *test-build
branches:
staging:
- step:
<<: *build_publish_and_deploy
deployment: Staging
master:
- step:
<<: *build_publish_and_deploy
deployment: Production