-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path.pipeline-config.yaml
210 lines (181 loc) · 7.13 KB
/
.pipeline-config.yaml
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
---
version: '1'
setup:
image: icr.io/continuous-delivery/pipeline/pipeline-base-ubi:3.46
script: |
#!/usr/bin/env bash
if [[ "$PIPELINE_DEBUG" == 1 ]]; then
trap env EXIT
env
set -x
fi
if [[ "$(get_env pipeline_namespace)" == *"pr"* || "$(get_env pipeline_namespace)" == *"ci"* ]]; then
source "${WORKSPACE}/$PIPELINE_CONFIG_REPO_PATH/scripts/code_setup.sh"
fi
test:
abort_on_failure: false
image: icr.io/continuous-delivery/pipeline/pipeline-base-ubi:3.46
script: |
#!/usr/bin/env bash
cd "${WORKSPACE}/$(load_repo app-repo path)/$(get_env source "")"
#npm ci
# save exit code for old evidence collection
exit_code=0
#npm test || exit_code=$?
# save status for new evidence collection
status="success"
if [ "$exit_code" != "0" ]; then
status="failure"
fi
collect-evidence \
--tool-type "jest" \
--status "$status" \
--evidence-type "com.ibm.unit_tests" \
--asset-type "repo" \
--asset-key "app-repo"
exit $exit_code
containerize:
dind: true
image: icr.io/continuous-delivery/pipeline/pipeline-base-ubi:3.46
script: |
#!/usr/bin/env bash
if [[ "$PIPELINE_DEBUG" == 1 ]]; then
trap env EXIT
env
set -x
fi
source "${WORKSPACE}/$PIPELINE_CONFIG_REPO_PATH/scripts/build_setup.sh"
CLUSTER_NAME="$(get_env cluster-name "")"
if [ -z "${CLUSTER_NAME}" ]; then
source "${WORKSPACE}/$PIPELINE_CONFIG_REPO_PATH/scripts/build_using_code_engine.sh"
else
source "${WORKSPACE}/$PIPELINE_CONFIG_REPO_PATH/scripts/build_using_docker.sh"
fi
deploy:
image: icr.io/continuous-delivery/pipeline/pipeline-base-image:2.59
script: |
#!/usr/bin/env bash
if [[ "$PIPELINE_DEBUG" == 1 ]]; then
trap env EXIT
env
set -x
fi
CLUSTER_NAME="$(get_env cluster-name "")"
# use different deployment process depending on CI or CD
if [[ "$(get_env pipeline_namespace)" == *"cd"* ]]; then
INVENTORY_PATH="$(get_env inventory-path)"
DEPLOYMENT_DELTA_PATH="$(get_env deployment-delta-path)"
echo "Target environment: $(get_env target-environment)"
echo "Deployment Delta (inventory entries with updated artifacts)"
jq '.' "$DEPLOYMENT_DELTA_PATH"
echo ""
#
# iterate over inventory deployment delta
#
for INVENTORY_ENTRY in $(jq -r '.[]' $DEPLOYMENT_DELTA_PATH); do
echo "==============================================="
echo "Deploying $INVENTORY_ENTRY"
set_env app-name "$(jq -r '.app_artifacts.name' ${INVENTORY_PATH}/${INVENTORY_ENTRY})"
IMAGE=$(jq -r '.provenance' ${INVENTORY_PATH}/${INVENTORY_ENTRY})
if [ -z "${CLUSTER_NAME}" ]; then
code_engine_deployment_type=$(jq -r '.app_artifacts.code_engine_deployment_type' ${INVENTORY_PATH}/${INVENTORY_ENTRY})
source "${WORKSPACE}/$PIPELINE_CONFIG_REPO_PATH/scripts/code_engine/deploy_setup.sh"
source "${WORKSPACE}/$PIPELINE_CONFIG_REPO_PATH/scripts/code_engine/deploy.sh"
else
source $WORKSPACE/$PIPELINE_CONFIG_REPO_PATH/scripts/roks/deploy_setup.sh
source $WORKSPACE/$PIPELINE_CONFIG_REPO_PATH/scripts/roks/deploy.sh
fi
done
echo ""
echo "==============================================="
else
IMAGE=$(load_artifact app-image name)
if [ -z "${CLUSTER_NAME}" ]; then
code_engine_deployment_type=$(jq -r '.app_artifacts.code_engine_deployment_type' ${INVENTORY_PATH}/${INVENTORY_ENTRY})
source "${WORKSPACE}/$PIPELINE_CONFIG_REPO_PATH/scripts/code_engine/deploy_setup.sh"
source "${WORKSPACE}/$PIPELINE_CONFIG_REPO_PATH/scripts/code_engine/deploy.sh"
else
source $WORKSPACE/$PIPELINE_CONFIG_REPO_PATH/scripts/roks/deploy_setup.sh
source $WORKSPACE/$PIPELINE_CONFIG_REPO_PATH/scripts/roks/deploy.sh
fi
fi
acceptance-test:
abort_on_failure: false
image: icr.io/continuous-delivery/pipeline/pipeline-base-ubi:3.46
script: |
#!/usr/bin/env bash
cd "${WORKSPACE}/$(load_repo app-repo path)/$(get_env source "")"
#npm ci
export APP_URL=$(get_env app-url)
# save exit code for old evidence collection
exit_code=0
#npm run acceptance-test || exit_code=$?
# save status for new evidence collection
status="success"
if [ "$exit_code" != "0" ]; then
status="failure"
fi
collect-evidence \
--tool-type "jest" \
--status "$status" \
--evidence-type "com.ibm.acceptance_tests" \
--asset-type "repo" \
--asset-key "app-repo"
exit $exit_code
dynamic-scan:
dind: true
abort_on_failure: false
image: icr.io/continuous-delivery/pipeline/pipeline-base-ubi:3.46
script: |
#!/usr/bin/env bash
if [[ "$PIPELINE_DEBUG" == 1 ]]; then
trap env EXIT
env
set -x
fi
if [ -z "$(get_env opt-in-dynamic-scan "")" ]; then
echo "If you want to enable this stage, add 'opt-in-dynamic-scan' parameter to your pipeline with any value. Also, please add 'opt-in-dynamic-api-scan' to your pipeline with any value to have api scans running, and 'opt-in-dynamic-ui-scan' with any value to have ui scans running" >&2
else
if [[ "$(get_env pipeline_namespace)" == *"cc"* ]]; then
source "${ONE_PIPELINE_PATH}"/tools/get_repo_params
INVENTORY_PATH="$(get_env inventory-path)"
INVENTORY_TOKEN_PATH="./inventory-token"
read -r INVENTORY_REPO_NAME INVENTORY_REPO_OWNER INVENTORY_SCM_TYPE INVENTORY_API_URL < <(get_repo_params "$(get_env INVENTORY_URL)" "$INVENTORY_TOKEN_PATH")
APP_ARTIFACTS=$(cocoa inventory get \
--entry="$(get_env app-name '')" \
--org="${INVENTORY_REPO_OWNER}" \
--repo="${INVENTORY_REPO_NAME}" \
--environment="$(get_env target-environment 'prod')" \
--git-provider="${INVENTORY_SCM_TYPE}" \
--git-token-path="${INVENTORY_TOKEN_PATH}" \
--git-api-url="${INVENTORY_API_URL}" \
--property="app_artifacts")
app_url=$(jq -r '.prod_app_url' <<< $APP_ARTIFACTS)
if [[ -z "${app_url}" ]]; then
echo "Please provide the app-url as the running application url. Recommended to use stage/test environment to run the Dynamic scan." >&2
exit 1
fi
source $WORKSPACE/$PIPELINE_CONFIG_REPO_PATH/scripts/zap/zap-cc-config
fi
source $WORKSPACE/$PIPELINE_CONFIG_REPO_PATH/scripts/zap/trigger_zap_scans
fi
release:
abort_on_failure: false
image: icr.io/continuous-delivery/pipeline/pipeline-base-ubi:3.46
script: |
#!/usr/bin/env bash
if [[ "$PIPELINE_DEBUG" == 1 ]]; then
trap env EXIT
env
set -x
fi
# Check the status of pipeline and then release the artifacts to inventory
ONE_PIPELINE_STATUS=$(get_env one-pipeline-status 0)
if [ "$(get_env skip-inventory-update-on-failure 1)" == "1" ]; then
if [ $ONE_PIPELINE_STATUS -eq 1 ]; then
echo "Skipping release stage as some of the pipeline stages are not successfull."
exit 1
fi
fi
cd "${WORKSPACE}/$(load_repo app-repo path)/$(get_env source "")"
source "${WORKSPACE}/$PIPELINE_CONFIG_REPO_PATH/scripts/release.sh"