@@ -35,16 +35,210 @@ sa_location=westus
3535kv_name=fabrikamkv
3636kv_location=westus
3737
38+ # Introspection Storage Account Setup
39+ sa_partition_key=" integration-test"
40+
41+ branchName=myFeatureBranch
42+ FrontEnd=fabrikam.acme.frontend
43+ BackEnd=fabrikam.acme.backend
44+ hld_dir=fabrikam-intro-hld
45+ manifests_dir=fabrikam-manifests
46+ vg_name=fabrikam-intro-vg
47+ services_dir=services
48+ mono_repo_dir=fabrikamintro2019
49+ services_full_dir=" $TEST_WORKSPACE /$mono_repo_dir /$services_dir "
50+
3851shopt -s expand_aliases
3952alias spk=$SPK_LOCATION
4053echo " SPK Version: $( spk --version) "
4154echo " Running from $( pwd) "
4255
56+ echo " Running from $( pwd) "
57+ if [ -d " $TEST_WORKSPACE " ]; then rm -Rf $TEST_WORKSPACE ; fi
58+
59+ if [ ! -d " $TEST_WORKSPACE " ]; then
60+ echo " Directory '$TEST_WORKSPACE ' does not exist"
61+ mkdir $TEST_WORKSPACE
62+ echo " Created '$TEST_WORKSPACE '"
63+ fi
64+
65+ cd $TEST_WORKSPACE
66+
4367# spk deployment onboard validation test
68+ sat_onboard_name=deployments
69+ subscription_id=$( az account list | jq ' .[] | select(.isDefault == true) | .id' -r)
70+ storage_account_exists $AZ_STORAGE_ACCOUNT $AZ_RESOURCE_GROUP " fail"
71+ storage_account_table_exists $sat_onboard_name $AZ_STORAGE_ACCOUNT " delete"
72+ spk deployment onboard -s $AZ_STORAGE_ACCOUNT -t $sat_onboard_name -l $sa_location -r $AZ_RESOURCE_GROUP --subscription-id $subscription_id --service-principal-id $SP_APP_ID --service-principal-password $SP_PASS --tenant-id $SP_TENANT
73+ storage_account_table_exists $sat_onboard_name $AZ_STORAGE_ACCOUNT " fail"
74+ storage_account_table_exists $sat_onboard_name $AZ_STORAGE_ACCOUNT " delete"
75+
76+ echo " Successfully validated spk deployment onboard."
77+
78+ # setup repo with pipelines
79+ # Manifest Repo Setup ------------------
80+ mkdir $manifests_dir
81+ cd $manifests_dir
82+ git init
83+ touch README.md
84+ echo " This is the Flux Manifest Repository." >> README.md
85+ file_we_expect=(" README.md" )
86+ validate_directory " $TEST_WORKSPACE /$manifests_dir " " ${file_we_expect[@]} "
87+
88+ git add -A
89+
90+ # See if the remote repo exists
91+ repo_exists $AZDO_ORG_URL $AZDO_PROJECT $manifests_dir
92+
93+ # Create the remote repo for the local repo
94+ created_repo_result=$( az repos create --name " $manifests_dir " --org $AZDO_ORG_URL --p $AZDO_PROJECT )
95+
96+ # Extract out remote repo URL from the above result
97+ remote_repo_url=$( echo $created_repo_result | jq ' .remoteUrl' | tr -d ' "' )
98+ echo " The remote_repo_url is $remote_repo_url "
99+
100+ # Remove the user from the URL
101+ repo_url=$( getHostandPath " $remote_repo_url " )
102+ manifest_repo_url=$repo_url
103+
104+ # We need to manipulate the remote url to insert a PAT token so we can add an origin git url
105+ git commit -m " inital commit"
106+ # git remote rm origin
107+ git remote add origin https://service_account:$ACCESS_TOKEN_SECRET @$repo_url
108+ echo " git push"
109+ git push -u origin --all
110+ cd ..
111+
112+ # HLD repo set up -----------------------
113+ mkdir $hld_dir
114+ cd $hld_dir
115+ git init
116+ spk hld init
117+ touch component.yaml
118+ file_we_expect=(" spk.log" " manifest-generation.yaml" " component.yaml" " .gitignore" )
119+ validate_directory " $TEST_WORKSPACE /$hld_dir " " ${file_we_expect[@]} "
120+
121+ git add -A
122+
123+ # See if the remote repo exists
124+ repo_exists $AZDO_ORG_URL $AZDO_PROJECT $hld_dir
125+
126+ # Create the remote repo for the local repo
127+ created_repo_result=$( az repos create --name " $hld_dir " --org $AZDO_ORG_URL --p $AZDO_PROJECT )
128+
129+ # Extract out remote repo URL from the above result
130+ remote_repo_url=$( echo $created_repo_result | jq ' .remoteUrl' | tr -d ' "' )
131+ echo " The remote_repo_url is $remote_repo_url "
132+
133+ # Remove the user from the URL
134+ repo_url=$( getHostandPath " $remote_repo_url " )
135+ hld_repo_url=$repo_url
136+
137+ # We need to manipulate the remote url to insert a PAT token so we can add an origin git url
138+ git commit -m " inital commit"
139+ # git remote rm origin
140+ git remote add origin https://service_account:$ACCESS_TOKEN_SECRET @$repo_url
141+ echo " git push"
142+ git push -u origin --all
143+ cd ..
144+
145+ # *** TODO: Get rid of duplication
146+
147+ # First we should check hld pipelines exist. If there is a pipeline with the same name we should delete it
148+ hld_to_manifest_pipeline_name=$hld_dir -to-$manifests_dir
149+ pipeline_exists $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name
150+
151+ # Create the hld to manifest pipeline
152+ echo " hld_dir $hld_dir "
153+ echo " hld_repo_url $hld_repo_url "
154+ echo " manifest_repo_url $manifest_repo_url "
155+ spk hld install-manifest-pipeline -o $AZDO_ORG -d $AZDO_PROJECT -p $ACCESS_TOKEN_SECRET -r $hld_dir -u https://$hld_repo_url -m https://$manifest_repo_url >> $TEST_WORKSPACE /log.txt
156+
157+ # Verify hld to manifest pipeline was created
158+ pipeline_created=$( az pipelines show --name $hld_to_manifest_pipeline_name --org $AZDO_ORG_URL --p $AZDO_PROJECT )
159+
160+ # Verify hld to manifest pipeline run was successful
161+ verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15
162+
163+ # App Code Mono Repo set up
164+ mkdir $mono_repo_dir
165+ cd $mono_repo_dir
166+ git init
167+
168+ mkdir $services_dir
169+ spk project init >> $TEST_WORKSPACE /log.txt
170+ file_we_expect=(" spk.log" " .gitignore" " bedrock.yaml" " maintainers.yaml" " hld-lifecycle.yaml" )
171+ validate_directory " $TEST_WORKSPACE /$mono_repo_dir " " ${file_we_expect[@]} "
172+
173+ # Does variable group already exist? Delete if so
174+ variable_group_exists $AZDO_ORG_URL $AZDO_PROJECT $vg_name " delete"
175+
176+ # Create variable group
177+ spk project create-variable-group $vg_name -r $ACR_NAME -d $hld_repo_url -u $SP_APP_ID -t $SP_TENANT -p $SP_PASS --org-name $AZDO_ORG --project $AZDO_PROJECT --personal-access-token $ACCESS_TOKEN_SECRET >> $TEST_WORKSPACE /log.txt
178+
179+ # Verify the variable group was created. Fail if not
180+ variable_group_exists $AZDO_ORG_URL $AZDO_PROJECT $vg_name " fail"
181+
182+ # Introspection Storage Account Setup
44183storage_account_exists $AZ_STORAGE_ACCOUNT $AZ_RESOURCE_GROUP " fail"
45- storage_account_table_exists $sat_name $AZ_STORAGE_ACCOUNT " delete"
46- spk deployment onboard -s $AZ_STORAGE_ACCOUNT -t $sat_name -l $sa_location -r $AZ_RESOURCE_GROUP --subscription-id $AZ_SUBSCRIPTION_ID --service-principal-id $SP_APP_ID --service-principal-password $SP_PASS --tenant-id $SP_TENANT
184+ storage_account_cors_enabled $AZ_STORAGE_ACCOUNT " enable"
185+ storage_account_cors_enabled $AZ_STORAGE_ACCOUNT " wait"
186+ storage_account_table_exists $sat_name $AZ_STORAGE_ACCOUNT " create"
47187storage_account_table_exists $sat_name $AZ_STORAGE_ACCOUNT " fail"
48- storage_account_table_exists $sat_name $AZ_STORAGE_ACCOUNT " delete"
188+ sa_access_key=$( az storage account keys list -n $AZ_STORAGE_ACCOUNT -g $AZ_RESOURCE_GROUP | jq ' .[0].value' )
189+
190+ # Add introspection variables to variable group
191+ variable_group_id=$( az pipelines variable-group list --org $AZDO_ORG_URL -p $AZDO_PROJECT | jq ' .[] | select(.name=="fabrikam-intro-vg") | .id' )
192+ variable_group_variable_create $variable_group_id $AZDO_ORG_URL $AZDO_PROJECT " ACCOUNT_KEY" $sa_access_key " secret"
193+ variable_group_variable_create $variable_group_id $AZDO_ORG_URL $AZDO_PROJECT " ACCOUNT_NAME" $AZ_STORAGE_ACCOUNT
194+ variable_group_variable_create $variable_group_id $AZDO_ORG_URL $AZDO_PROJECT " PARTITION_KEY" $sa_partition_key
195+ variable_group_variable_create $variable_group_id $AZDO_ORG_URL $AZDO_PROJECT " TABLE_NAME" $sat_name
196+
197+ spk service create $FrontEnd -d $services_dir >> $TEST_WORKSPACE /log.txt
198+ directory_to_check=" $services_full_dir /$FrontEnd "
199+ file_we_expect=(" .gitignore" " azure-pipelines.yaml" " Dockerfile" )
200+ validate_directory $directory_to_check " ${file_we_expect[@]} "
201+
202+ spk service create $BackEnd -d $services_dir >> $TEST_WORKSPACE /log.txt
203+ validate_directory " $services_full_dir /$BackEnd " " ${file_we_expect[@]} "
204+
205+ git add -A
206+
207+ # TODO: We aren't using the config file right now
208+ # spk init -f $SPK_CONFIG_FILE
209+
210+ # See if the remote repo exists
211+ repo_exists $AZDO_ORG_URL $AZDO_PROJECT $mono_repo_dir
212+
213+ # Create the remote repo for the local repo
214+ created_repo_result=$( az repos create --name " $mono_repo_dir " --org $AZDO_ORG_URL --p $AZDO_PROJECT )
215+
216+ # Extract out remote repo URL from the above result
217+ remote_repo_url=$( echo $created_repo_result | jq ' .remoteUrl' | tr -d ' "' )
218+ echo " The remote_repo_url is $remote_repo_url "
219+
220+ # Remove the user from the URL
221+ repo_url=$( getHostandPath " $remote_repo_url " )
222+
223+ # We need to manipulate the remote url to insert a PAT token so we can
224+
225+ git commit -m " inital commit"
226+ git remote add origin https://service_account:$ACCESS_TOKEN_SECRET @$repo_url
227+ echo " git push"
228+ git push -u origin --all
229+
230+ # First we should check lifecycle pipelines exist. If there is a pipeline with the same name we should delete it
231+ lifecycle_pipeline_name=" $mono_repo_dir -lifecycle"
232+ pipeline_exists $AZDO_ORG_URL $AZDO_PROJECT $lifecycle_pipeline_name
233+
234+ # Deploy lifecycle pipeline and verify it runs.
235+ spk project install-lifecycle-pipeline --org-name $AZDO_ORG --devops-project $AZDO_PROJECT --repo-url $repo_url --repo-name $mono_repo_dir --pipeline-name $lifecycle_pipeline_name --personal-access-token $ACCESS_TOKEN_SECRET >> $TEST_WORKSPACE /log.txt
236+
237+ # TODO: Verify the lifecycle pipeline sucessfully runs
238+ # Verify lifecycle pipeline was created
239+ pipeline_created=$( az pipelines show --name $lifecycle_pipeline_name --org $AZDO_ORG_URL --p $AZDO_PROJECT )
240+
241+ # Verify lifecycle pipeline run was successful
242+ verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $lifecycle_pipeline_name 180 15
49243
50244echo " Successfully reached the end of the introspection validations script."
0 commit comments