-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbitbucket-pipelines.yml
140 lines (139 loc) · 6.31 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
image: node:14.17.6
definitions:
services:
docker:
memory: 2048
caches:
sonar: ~/.sonar/cache
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
- if [ -n "$NG_BUILD" ]; then export BUILD_ENVIRONMENT="${NG_BUILD}"; else export BUILD_ENVIRONMENT="${ENVIRONMENT}"; 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
- rm -rf package-lock.json || true
- npm install
- npm install -g @angular/cli
- echo "${BUILD_ENVIRONMENT}"
- echo $BUILD_ENVIRONMENT
- ng build --configuration=${BUILD_ENVIRONMENT} --output-path dist/
# 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 dist/ s3://$AWS_S3
- aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths /index.html "/assets*"
- step: &build-test
name: Build and test
caches:
- sonar
script:
- npm install
- npm run build --configuration=dev1
- npm run test
artifacts:
- coverage/lcov.info
- step: &analyze-sonarcloud
name: Analyze on SonarCloud
max-time: 15
caches:
- sonar
script:
- pipe: sonarsource/sonarcloud-scan:1.2.1
variables:
SONAR_SCANNER_OPTS: -Xmx2048m
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '
-Dsonar.sources=src/app
-Dsonar.tests=src
-Dsonar.test.inclusions=**/*.spec.ts
-Dsonar.coverage.exclusions=**/mock/**
-Dsonar.typescript.lcov.reportPaths=coverage/lcov.info
'
- step: &push-to-github
name: Push to GitHub
script:
- git remote set-url origin git@github.com:openchannel/angular-portal-template.git
- git remote -v
- git push origin master:main
- git push origin --tags
- step: &create-git-tag
name: Create Git Tag
script:
- /bin/bash ./scripts/create-and-push-github-tag/create-and-push-github-tag.sh "${CUSTOM_TAG_NAME}" "./package.json" "${PUSH_TAG_FORCE}"
- step: &up-version
name: "Up version"
script:
- /bin/bash ./scripts/package-json-version/up-package-json-version.sh "$PROJECT_VERSION" "$SERVICES_AND_COMPONENTS_VERSION"
- step: &create-changelog-with-git-tag
name: "Create changelog and add git tag"
script:
# Get current package.json version
- projectVerion=$(node -e "console.log(require('./package.json').version)")
# Validate package.json version
- if [[ ! $projectVerion == +([0-9]).+([0-9]).+([0-9]) ]]; then echo "Error. package.json file includes prerelease version $projectVerion. Must be like '1.1.1'. Please change version."; exit 1; fi
# Install required libs for changelog script
- npm i --prefix ./scripts/changelog-builder
# Generate new changelog file or skip
- EMAIL=${JIRA_EMAIL} API_KEY=${JIRA_API_KEY} RELEASE_VERSION=${JIRA_RELEASE_VERSION} PROJECT_VERSION=$projectVerion node ./scripts/changelog-builder/script.js
# Commit and push
- if [[ ! -z $(git status --porcelain) ]]; then git add . ; git commit -m "Created changelog.md for $JIRA_RELEASE_VERSION release." ; git push ; else echo 'Changelog not changed.'; fi
# Create git tag and push
- /bin/bash ./scripts/create-and-push-github-tag/script.sh "${PUSH_TAG_FORCE}"
pipelines:
pull-requests:
'**':
- step: *build-test
- step: *analyze-sonarcloud
custom:
dev1:
- step:
<<: *build-app-and-deploy
deployment: dev1
stage1:
- step:
<<: *build-app-and-deploy
deployment: stage1
Up version:
- variables:
- name: SERVICES_AND_COMPONENTS_VERSION
- name: PROJECT_VERSION
- step: *up-version
Create changelog and Git Tag:
- variables:
- name: JIRA_RELEASE_VERSION
- name: PUSH_TAG_FORCE
- step: *build-test
- step: *analyze-sonarcloud
- step: *create-changelog-with-git-tag
branches:
develop:
- step: *build-test
- step: *analyze-sonarcloud
master:
- step: *build-test
- step: *analyze-sonarcloud
- step: *push-to-github