-
Notifications
You must be signed in to change notification settings - Fork 4
/
bitbucket-pipelines.yml
76 lines (71 loc) · 3.38 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
70
71
72
73
74
75
76
image: node:14.17.6
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
services:
docker:
memory: 2048
steps:
- step: &build-app-and-deploy
name: "Build and Deploy"
image: python:3.9.7
script:
# Initial configuration
- if [ -n "$PROJECT_FOLDER" ]; then echo $PROJECT_FOLDER; fi
- export CONFIG_FILE_PATH="infra/config-files/${ENVIRONMENT}"
- source $CONFIG_FILE_PATH
- if [ -n "$PROJECT_FOLDER" ]; then mv infra ${PROJECT_FOLDER}/.; fi
- if [ -n "$PROJECT_FOLDER" ]; then cd ${PROJECT_FOLDER}; fi
# Install node
- curl -sL https://deb.nodesource.com/setup_12.x | bash -
- apt-get install -y nodejs unzip git jq
# Install AWS CLI and update AWS keys
- if [ -z "$AWS_ACCESS_KEY_ID" ]; then export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID_ECS; fi
- if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY_ECS; fi
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- unzip awscliv2.zip
- ./aws/install
# Get infra templates repo
- cp infra/cloudformation/* .
# Get certificate arn in us-east-1
- chmod +x infra/scripts/* && cp infra/scripts/* .
- export CERTIFICATE_ARN=`./getCertificate.sh us-east-1 *.${HOSTED_ZONE_NAME:0:-1}`
# CloudFront Deploy
- export PREFIX_NAME="openchannel-${ENVIRONMENT}"
- aws cloudformation deploy --region $REGION --stack-name ${CLOUDFORMATION_STACKNAME}-cloudfront --capabilities CAPABILITY_NAMED_IAM --no-fail-on-empty-changeset --template-file service-cloudfront.yml --parameter-overrides HostedZoneName=$HOSTED_ZONE_NAME CNAME=$APP_SITENAME CertificateArn=$CERTIFICATE_ARN ClusterName=$CLUSTER_NAME ProjectName=$PROJECTNAME PrefixName=$PREFIX_NAME AppName=$APP_NAME
# Build application
- npm install
- npm run build:${ENVIRONMENT}
# Application
- export DISTRIBUTION_ID=`aws ssm get-parameter --region $REGION --with-decryption --name /ECS-CLUSTER/$CLUSTER_NAME/${APP_NAME}/DISTRIBUTION_ID --output text --query Parameter.Value`
- export AWS_S3="`aws ssm get-parameter --region $REGION --with-decryption --name /ECS-CLUSTER/$CLUSTER_NAME/${APP_NAME}/AWS_S3 --output text --query Parameter.Value`"
- aws s3 sync --delete build/ s3://$AWS_S3
- aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths /index.html "/assets*"
- step: &push-to-github
name: Push to GitHub
script:
- git remote set-url origin git@github.com:openchannel/react-market-template.git
- git remote -v
- git push origin master:main
- git push origin --force --tags
- step: &sonarcloud
name: "Sonarcloud"
image: python:3.7.7-stretch
script:
- pipe: sonarsource/sonarcloud-scan:1.2.1
- pipe: sonarsource/sonarcloud-quality-gate:0.1.4
pipelines:
custom:
dev1:
- step:
<<: *build-app-and-deploy
deployment: dev1
stage1:
- step:
<<: *build-app-and-deploy
deployment: stage1
Analyze sonarcloud:
- step: *sonarcloud
branches:
master:
- step: *push-to-github