Miles Dai | 6d96cdf | 2022-03-09 18:45:49 -0500 | [diff] [blame] | 1 | # Copyright lowRISC contributors. |
| 2 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | |
| 5 | # Azure template for uploading artifacts to a Google Cloud Platform (GCP) |
| 6 | # bucket. |
| 7 | # |
| 8 | # This template first installs gsutil to interact with GCP resources. Then, |
| 9 | # files located under parentDir and at paths specified by includeFiles will be |
| 10 | # packed into archiveName (a tar.gz file) and uploaded to a GCP bucket located |
| 11 | # at bucketURI using gsutil. |
| 12 | # |
| 13 | # Writing to a GCP bucket requires a GCP service account key with sufficient |
| 14 | # permisions. This key must be uploaded to Azure as a Secure File. The name of |
| 15 | # the key file should be provided as gcpKeyFile. |
| 16 | # |
| 17 | |
| 18 | parameters: |
| 19 | - name: parentDir |
| 20 | type: string |
| 21 | default: "" |
| 22 | - name: includeFiles |
| 23 | type: object |
| 24 | default: [] |
Miles Dai | 6d96cdf | 2022-03-09 18:45:49 -0500 | [diff] [blame] | 25 | - name: gcpKeyFile |
| 26 | type: string |
| 27 | default: "" |
| 28 | - name: bucketURI |
| 29 | type: string |
| 30 | default: "" |
| 31 | |
| 32 | steps: |
| 33 | - task: DownloadSecureFile@1 |
| 34 | name: gcpkey |
| 35 | inputs: |
| 36 | secureFile: ${{ parameters.gcpKeyFile }} |
| 37 | - bash: | |
| 38 | echo "Installing gsutil" |
| 39 | sudo apt-get install -y apt-transport-https ca-certificates gnupg |
| 40 | echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | \ |
| 41 | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list |
| 42 | echo "vvvvvvvvv cat /etc/apt/sources.list.d/google-cloud-sdk.list" |
| 43 | cat /etc/apt/sources.list.d/google-cloud-sdk.list |
| 44 | echo "^^^^^^^^" |
| 45 | curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo tee /usr/share/keyrings/cloud.google.gpg |
| 46 | sudo apt-get update || { |
| 47 | error "Failed to run apt-get update" |
| 48 | } |
| 49 | sudo apt-get install -y google-cloud-cli |
| 50 | |
| 51 | . util/build_consts.sh |
| 52 | printf "$(date -u +%Y-%m-%dT%H:%M:%S)\n$(Build.SourceVersion)" > latest.txt |
Miles Dai | ca6be0f | 2022-04-06 15:27:05 -0400 | [diff] [blame] | 53 | printf "${{ join('\n', parameters.includeFiles) }}" > include_files.txt |
| 54 | tar -C ${{ parameters.parentDir }} -zcvf bitstream-latest.tar.gz -T include_files.txt |
Miles Dai | 6d96cdf | 2022-03-09 18:45:49 -0500 | [diff] [blame] | 55 | |
| 56 | gsutil -o Credentials:gs_service_key_file=$(gcpkey.secureFilePath) \ |
| 57 | cp latest.txt ${{ parameters.bucketURI }}/latest.txt |
| 58 | gsutil -o Credentials:gs_service_key_file=$(gcpkey.secureFilePath) \ |
Miles Dai | ca6be0f | 2022-04-06 15:27:05 -0400 | [diff] [blame] | 59 | cp -r bitstream-latest.tar.gz ${{ parameters.bucketURI }}/bitstream-latest.tar.gz |
| 60 | gsutil -o Credentials:gs_service_key_file=$(gcpkey.secureFilePath) \ |
| 61 | cp -r ${{ parameters.bucketURI }}/bitstream-latest.tar.gz ${{ parameters.bucketURI }}/bitstream-$(Build.SourceVersion).tar.gz |
Miles Dai | 6d96cdf | 2022-03-09 18:45:49 -0500 | [diff] [blame] | 62 | condition: succeeded() |
Miles Dai | ca6be0f | 2022-04-06 15:27:05 -0400 | [diff] [blame] | 63 | continueOnError: true |
| 64 | displayName: Upload bitstreams to GCP bucket |
Miles Dai | 6d96cdf | 2022-03-09 18:45:49 -0500 | [diff] [blame] | 65 | |