-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure_pipelines.yml
170 lines (163 loc) · 7.44 KB
/
azure_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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
trigger:
- dev
- uat
- sta
pr:
autoCancel: true
branches:
include:
- "*"
# Services object is now defined per environment.
# Check the variables file for the desired environment!
parameters:
- name: buildBranches
type: object
default: ["dev", "sta", "uat"]
- name: validEnvironments
type: object
displayName: List of valid environments to deploy (do not change)
default: ['dev','sta', 'uat', 'prd']
- name: vmImage
type: string
default: "ubuntu-22.04"
variables:
- name: pushArtefacts
value: ${{ containsValue(parameters.buildBranches, variables['Build.SourceBranchName']) }}
- ${{ if containsValue(parameters.validEnvironments ,variables['Build.SourceBranchName']) }}:
- template: pipeline-variables/${{ coalesce(variables['Build.SourceBranchName'], 'fallback') }}.yml
- ${{ else }}:
- template: pipeline-variables/dev.yml
- name: runSmokeTest
value: ${{ eq('dev', variables['Build.SourceBranchName']) }}
resources:
repositories:
- repository: pipeline-templates
type: github
name: ogcio/building-blocks-pipelines
ref: refs/tags/v0.5.1
endpoint: ogcio
- repository: journey-k8s-apps
type: github
name: ogcio/journey-k8s-apps
ref: main
endpoint: ogcio
- repository: journey-api-k8s-apps
type: github
name: ogcio/journey-api-k8s-apps
ref: main
endpoint: ogcio
stages:
- stage: securityScan
displayName: Security Scans
pool:
vmImage: ${{ parameters.vmImage }}
jobs:
- template: security/gitleaks.yml@pipeline-templates
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- job: bearerScan
displayName: Bearer
steps:
- task: DockerInstaller@0
displayName: Docker Installer
inputs:
dockerVersion: 17.09.0-ce
releaseType: stable
- script: |
docker run --rm -v $(pwd):/tmp/scan bearer/bearer:latest-amd64 scan --no-color --hide-progress-bar --fail-on-severity critical,high /tmp/scan
displayName: Code Scan
- stage: BuildDeps
displayName: Build service dependencies
pool:
vmImage: ${{ parameters.vmImage }}
jobs:
- template: pipeline-templates/build_dependencies.yml
- ${{ each serviceName in split(replace(variables.services, ' ', ''), ',') }}:
- stage: Unit_Tests_${{ replace(serviceName, '-', '_') }}
displayName: Run unit tests - ${{ serviceName }}
pool:
vmImage: ${{ parameters.vmImage }}
dependsOn:
- securityScan
- BuildDeps
jobs:
- template: test/unit_test.yml@pipeline-templates
parameters:
serviceName: ${{ serviceName }}
testPath: './apps/'
dependenciesBuild: 'node scripts/init-env.mjs'
- stage: Build_${{ replace(serviceName, '-', '_') }}
displayName: Build ${{ serviceName }}
pool:
vmImage: ${{ parameters.vmImage }}
dependsOn: Unit_Tests_${{ replace(serviceName, '-', '_') }}
jobs:
- template: build/build_service.yml@pipeline-templates
parameters:
serviceName: ${{ serviceName }}
pushArtefacts: ${{ variables.pushArtefacts }}
dockerfile: apps/${{ serviceName }}/Dockerfile
dependencies: "base-deps"
# TODO: Use arguments per service
buildArguments: '--build-arg "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=$(nextPublicStripePublishableKey)" --build-arg "NEXT_PUBLIC_HOST_URL=$(nextPublicHostUrl)" --build-arg "NEXT_PUBLIC_API_ENDPOINT=$(nextPublicApiEndpoint)" --build-arg "NEXT_PUBLIC_MESSAGING_SERVICE_ENTRY_POINT=$(nextPublicMessagingServiceEntryPoint)" --build-arg "NEXT_PUBLIC_PAYMENTS_SERVICE_ENTRY_POINT=$(nextPublicPaymentsServiceEntryPoint)" --build-arg "NEXT_PUBLIC_LIFE_EVENTS_SERVICE_ENTRY_POINT=$(nextPublicLifeEventsServiceEntryPoint)" --build-arg "NEXT_PUBLIC_BUILDING_BLOCKS_LANDING_PAGE=$(nextPublicBuildingBlocksLandingPage)" --build-arg "NEXT_PUBLIC_FORMS_URL=$(nextPublicFormsUrl)" --build-arg "NEXT_PUBLIC_MATOMO_URL=$(nextPublicMatomoUrl)" --build-arg "NEXT_PUBLIC_LIFE_EVENTS_MATOMO_SITE_ID=$(nextPublicLifeEventsMatomoSiteId)" --build-arg "NEXT_PUBLIC_BUILDING_BLOCKS_MATOMO_SITE_ID=$(nextPublicBuildingBlocksMatomoSiteId)" --build-arg "NEXT_PUBLIC_PAYMENTS_MATOMO_SITE_ID=$(nextPublicPaymentsMatomoSiteId)" --build-arg "NEXT_PUBLIC_MATOMO_PROTOCOL=$(nextPublicMatomoProtocol)" --build-arg "NEXT_PUBLIC_PROFILE_SERVICE_ENTRY_POINT=$(nextPublicProfileServiceEntryPoint)" --build-arg "NEXT_PUBLIC_FORMS_SERVICE_ENTRY_POINT=$(nextPublicFormsServiceEntryPoint)" --build-arg "NEXT_PUBLIC_DESIGN_SYSTEM_SERVICE_ENTRY_POINT=$(nextPublicDesignSystemServiceEntryPoint)" --build-arg "NEXT_PUBLIC_JOURNEY_SERVICE_ENTRY_POINT=$(nextPublicJourneyServiceEntryPoint)" --build-arg "NEXT_PUBLIC_UPLOAD_SERVICE_ENTRY_POINT=$(nextPublicUploadServiceEntryPoint)" --build-arg "NEXT_PUBLIC_FORMSIE_ADMIN_SERVICE_ENTRY_POINT=$(nextPublicFormsieAdminServiceEntryPoint)"'
- stage: Push_${{ replace(serviceName, '-', '_') }}
displayName: Push ${{ serviceName }} to ECR
pool:
vmImage: ${{ parameters.vmImage }}
dependsOn:
- Build_${{ replace(serviceName, '-', '_') }}
condition: and(${{ variables.pushArtefacts }}, succeeded())
jobs:
- template: build/push_image_ecr.yml@pipeline-templates
parameters:
awsServiceConnection: ${{ variables.awsServiceConnection }}
awsRegion: ${{ variables.awsRegion }}
serviceName: ${{ serviceName }}
repositoryName: bb-${{ serviceName }}
pushTag: $(Build.BuildId)
- stage: EnvApproval
displayName: Approvals for deployments - ${{ upper(variables.environment) }}
dependsOn:
- ${{ each serviceName in split(replace(variables.services, ' ', ''), ',') }}:
- Push_${{ replace(serviceName, '-', '_') }}
condition: ${{ variables.pushArtefacts }}
jobs:
- deployment: VerifyDeployment
displayName: Verify conditions for deployment
environment: ${{ variables.environment }}
strategy:
runOnce:
deploy:
steps:
- download: none
- script: |
date
displayName: Show current date
- ${{ each serviceName in split(replace(variables.services, ' ', ''), ',') }}:
- stage: Deploy_Openshift_${{ replace(serviceName, '-', '_') }}
displayName: GitOps deploy ${{ serviceName }}
pool:
vmImage: ${{ parameters.vmImage }}
dependsOn:
- EnvApproval
- Push_${{ replace(serviceName, '-', '_') }}
condition: succeeded()
jobs:
- template: deploy/gitops.yml@pipeline-templates
parameters:
serviceName: ${{ serviceName }}
newName: ${{ variables.ecrEndpoint }}/bb-${{ serviceName }}
newTag: $(Build.BuildId)
${{ if containsValue(parameters.validEnvironments ,variables['Build.SourceBranchName']) }}:
environment: ${{ variables['Build.SourceBranchName'] }}
${{ else }}:
environment: dev
- stage: Smoke_Tests_${{ replace(serviceName, '-', '_') }}
displayName: Run smoke tests - ${{ serviceName }}
condition: ${{ variables.runSmokeTests }}
pool: 'Openshift'
dependsOn: Deploy_Openshift_${{ replace(serviceName, '-', '_') }}
jobs:
- template: test/smoke_test.yml@pipeline-templates
parameters:
serviceName: ${{ serviceName }}
testPath: './apps/'