forked from jfrog/terraform-provider-artifactory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTFproviderTest.yml
193 lines (192 loc) · 10.4 KB
/
TFproviderTest.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
resources:
- name: GitHubTFProviderRepoJFrog
type: GitRepo
configuration:
gitProvider: Partnership_GitHub
path: jfrog/terraform-provider-artifactory # if path is modified, change the name as well, per Pipelines doc
branches:
include: master
buildOn:
commit: false
pullRequestCreate: true
cancelPendingRunsOn:
pullRequestUpdate: true
pipelines:
- name: tf_provider_artifactory
steps:
- name: build_and_run_tf_provider
type: Bash
configuration:
priority: 1
timeoutSeconds: 1800 # 30 minutes
runtime:
type: host
integrations:
- name: partnersSlack
- name: Partnership_GitHub
- name: PartnershipArtifactory
inputResources:
- name: GitHubTFProviderRepoJFrog
environmentVariables:
USE_LATEST_RT_VERSION: "true"
ARTIFACTORY_TEST_VERSION: 7.35.1
GO_VERSION: 1.18
execution:
onStart:
- echo "Preparing for work. Install Helm, Go and Teraform"
- ls -al && pwd
- echo "Helm 3 install"
- curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 && chmod 700 get_helm.sh
- echo "Run Helm installation script" && ./get_helm.sh && rm get_helm.sh
- helm version
- apt update
- export GO_ARCH="amd64"
- rm -rf go*.tar.gz go
- curl -O -L "https://golang.org/dl/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz"
- ls -l
- tar -xf "go${GO_VERSION}.linux-${GO_ARCH}.tar.gz"
- sudo chown -R root:root ./go
- >-
if [ -d /usr/local/go ]; then
echo "Removing existing version of Go"
rm -rf /usr/local/go || true
fi
- sudo mv -v go /usr/local
- echo "export GOPATH=$HOME/go" >> ~/.bash_profile
- echo "export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin" >> ~/.bash_profile
- source ~/.bash_profile
- cat ~/.bash_profile
- go version
- echo "Install Terraform"
- sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DA418C88A3219F7B
- sudo apt-add-repository "deb [arch=$(dpkg --print-architecture)] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
- sudo apt install terraform && terraform -version
onExecute:
- add_run_variables gitHubRepoUrl=${res_GitHubTFProviderRepoJFrog_gitRepoRepositorySshUrl}
- add_run_variables TFProviderRepo=$(echo ${gitHubRepoUrl} | sed -e 's/git@/@/g' -e 's/:/\//g')
- add_run_variables repoFolder=$(echo "${res_GitHubTFProviderRepoJFrog_gitRepoFullName}" | sed -e 's/.*\///g')
- cd ${res_GitHubTFProviderRepoJFrog_resourcePath} # since we run it on the host, we need to manually move into the resource path
- echo "Verify the code contents merged feature branch with master branch (detached mode)"
- git branch && ls -al
- export PROVIDER_VERSION=$(git tag --sort=-v:refname | head -1 | sed -n 's/v\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1.\2.\3/p')
- export NEXT_PROVIDER_VERSION=$(echo ${PROVIDER_VERSION}| awk -F '.' '{print $1 "." $2 "." $3 +1 }')
- echo $PROVIDER_VERSION
- echo $NEXT_PROVIDER_VERSION
- echo "Rename the build to make it work on Ubuntu"
- cat GNUmakefile | sed -e "s/darwin_amd64/linux_amd64/g" > GNUmakefile.tmp
- cp GNUmakefile.tmp GNUmakefile && rm GNUmakefile.tmp
- cat GNUmakefile
- cat sample.tf | sed -e "s/version =.*/version = \"${NEXT_PROVIDER_VERSION}\"/g" > sample.tf.tmp
- cp sample.tf.tmp sample.tf && rm sample.tf.tmp
- cat sample.tf
- echo "Download RT licenses from Partners RT instanse to scripts folder"
- jfrog config show && jfrog --version
- jfrog rt dl fozzie/native-steps/license/artifactory.cluster.license scripts/
- ls -al && pwd
- cp scripts/native-steps/license/artifactory.cluster.license scripts/artifactory.lic
- echo "Set Artifactory version, run RT in a container"
- >-
if [[ ${USE_LATEST_RT_VERSION} == "true" ]]; then
helm repo add artifactory https://charts.jfrog.io
helm repo update
add_run_variables ARTIFACTORY_VERSION=$(helm search repo | grep "artifactory " | awk '{$1=$1};1' | cut -f3 -d " ")
echo "Artifactory version: "${ARTIFACTORY_VERSION}
else
add_run_variables ARTIFACTORY_VERSION=${ARTIFACTORY_TEST_VERSION}
echo "Artifactory version: "${ARTIFACTORY_VERSION}
fi
- >-
docker run -i -t -d --rm -v "${res_GitHubTFProviderRepoJFrog_resourcePath}/scripts/artifactory.lic:/artifactory_extra_conf/artifactory.lic:ro" \
-p8081:8081 -p8082:8082 -p8080:8080 releases-docker.jfrog.io/jfrog/artifactory-pro:${ARTIFACTORY_VERSION}
- echo "Waiting for Artifactory to start (doesn't reflect the start of the UI!)"
- >-
until curl -sf -u admin:password http://localhost:8081/artifactory/api/system/licenses/; do
printf '.'
sleep 4
done
- echo "Add variables needed to run Terraform Provider"
- export ARTIFACTORY_URL="http://localhost:8082"
- export ARTIFACTORY_USERNAME=admin
- export ARTIFACTORY_PASSWORD=password
- echo "Get cookie to generate Access token. We need a pause to let UI come up to get cookies"
- sleep 180
- sudo curl http://localhost:8082/router/api/v1/system/health
- >-
export COOKIES=$(curl -c - "${ARTIFACTORY_URL}/ui/api/v1/ui/auth/login?_spring_security_remember_me=false" \
--header "accept: application/json, text/plain, */*" \
--header "content-type: application/json;charset=UTF-8" \
--header "x-requested-with: XMLHttpRequest" \
-d '{"user":"admin","password":"'"${ARTIFACTORY_PASSWORD}"'","type":"login"}' | grep FALSE)
- export REFRESHTOKEN=$(echo $COOKIES | grep REFRESHTOKEN | awk '{print $7 }')
- export ACCESSTOKEN=$(echo $COOKIES | grep ACCESSTOKEN | awk '{print $14 }') # awk returns null on Mac, and the actual key on Ubuntu
- >-
export ACCESS_KEY=$(curl -g --request GET "${ARTIFACTORY_URL}/ui/api/v1/system/security/token?services[]=all" \
--header "accept: application/json, text/plain, */*" \
--header "x-requested-with: XMLHttpRequest" \
--header "cookie: ACCESSTOKEN=${ACCESSTOKEN}; REFRESHTOKEN=${REFRESHTOKEN}")
- add_run_variables ARTIFACTORY_ACCESS_TOKEN=${ACCESS_KEY}
- echo "Unset ARTIFACTORY_PASSWORD, acceptance test will use ARTIFACTORY_ACCESS_TOKEN instead"
- unset ARTIFACTORY_PASSWORD
- export TF_ACC=true
- make acceptance
- make install
onSuccess:
- echo "Success"
- send_notification partnersSlack --text "Terraform Provider run is completed. Version ${NEXT_PROVIDER_VERSION}."
onFailure:
- echo "Failure"
- send_notification partnersSlack --text "Pipeline failed on <${step_url}|${step_name}> step"
onComplete:
- echo "Complete"
- name: pr_info_add_rt_version
type: Bash
configuration:
integrations:
- name: partnersSlack
- name: partnership_jfrog_io
- name: Partnership_GitHub
inputSteps:
- name: build_and_run_tf_provider
inputResources:
- name: GitHubTFProviderRepoJFrog
execution:
onStart:
- echo "Preparing for work..."
- echo "Create and push a new tag, associated with the lates changes on develpment branch"
onExecute:
- printenv
- export PR_URL=${res_GitHubTFProviderRepoJFrog_commitUrl}
- export PR_COMMITTER=${res_GitHubTFProviderRepoJFrog_committerLogin}
- export PR_BRANCH=${res_GitHubTFProviderRepoJFrog_headCommitRef}
- export PR_TITLE=$(echo ${res_GitHubTFProviderRepoJFrog_commitMessage:0:100}... | sed 's/[^[:print:]\t]//g')
- >-
if [[ "${PR_URL}" == null ]]; then
echo "PR was not created (already exists from this head branch?). PR link is empty!"
exit 1
fi
- cd ${res_GitHubTFProviderRepoJFrog_resourcePath}
- git checkout -b ${res_GitHubTFProviderRepoJFrog_headCommitRef}
- sed -i -E "0,/(##\s.+\..+\..+\s\(.+\)).*/ s/(##\s.+\..+\..+\s\(.+\)).*/\1. Tested on Artifactory ${ARTIFACTORY_VERSION}/" CHANGELOG.md
- git add CHANGELOG.md
- export REGEX="Changes to be committed*"
- export GIT_STATUS=$(git status)
- >-
if [[ ${GIT_STATUS} =~ ${REGEX} ]]; then
echo "Adding Artifactory version to CHANGELOG.md"
git commit -m "JFrog Pipelines - Add Artifactory version to CHANGELOG.md"
git push https://${res_GitHubTFProviderRepoJFrog_gitProvider_token}${TFProviderRepo}
else
echo "There is nothing to commit, Artifactory version didn't change since last commit"
fi
onSuccess:
- echo "Success"
- send_notification partnersSlack --text "<${res_GitHubTFProviderRepoJFrog_gitRepoRepositoryHttpsUrl}|Terraform Provider>. A new PR was submitted by *${PR_COMMITTER}* - <${PR_URL}|${PR_TITLE}>, branch *${PR_BRANCH}*. Changes tested successfully. <@U01DWTXV01M> please, review and merge."
onFailure:
- >-
if [[ "${PR_URL}" == null ]]; then
send_notification partnersSlack --text "${step_name} step is failed. PR was not created (already exists from this head branch?)"
else
send_notification partnersSlack --text "Pipeline failed on <${step_url}|${step_name}> step"
fi
onComplete:
- echo "Cleaning up"