Skip to content

Commit 2773ed8

Browse files
chore: automate signing (#174)
1 parent b67409f commit 2773ed8

File tree

3 files changed

+141
-3
lines changed

3 files changed

+141
-3
lines changed

.github/workflows/release.yml

+19
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,25 @@ jobs:
180180
- name: Run build installer script
181181
run: |
182182
.\build_installer.ps1 x64 ${{ env.BUILD_TYPE}} "${{env.CMAKE_GENERATOR}}" C:/mysql-${{ vars.MYSQL_VERSION }}-winx64
183+
184+
- name: Configure AWS credentials
185+
uses: aws-actions/[email protected]
186+
with:
187+
role-skip-session-tagging: true
188+
aws-access-key-id: ${{ secrets.AWS_BUILD_KEY }}
189+
aws-secret-access-key: ${{ secrets.AWS_BUILD_SECRET_KEY }}
190+
aws-region: us-west-2
191+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
192+
role-external-id: ${{ secrets.AWS_ROLE_EXTERNAL_ID }}
193+
role-duration-seconds: 3600
194+
195+
- name: Run signer script
196+
shell: pwsh
197+
working-directory: ./scripts
198+
run: |
199+
choco upgrade jq -y
200+
. ".\sign_installer.ps1"
201+
Invoke-SignInstaller ${{ github.workspace }}\wix winx64a ${{github.ref_name}} ${{ secrets.AWS_UNSIGNED_BUCKET }} ${{ secrets.AWS_SIGNED_BUCKET }} ${{ secrets.AWS_S3_KEY }}aws-mysql-odbc-${{github.ref_name}}-winx64a.msi
183202
184203
- name: Upload Windows installer as artifact
185204
if: success()

docs/building-the-aws-driver/BuildingTheAwsDriver.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
cmake -S . -B build -G "Visual Studio 16 2019" -DMYSQL_DIR="C:\Program Files\MySQL\MySQL Server 8.0" -DMYSQLCLIENT_STATIC_LINKING=TRUE
1616
cmake --build build --config Release
1717
```
18-
4. To build the installer, MySQL 8.0.31 is required. Other MySQL versions may not work. Download the [MySQL 8.0.31](https://downloads.mysql.com/archives/community/) ZIP archive or msi installer. If the zip archive is used, unzip it to a folder before using it.
18+
4. To build the installer, MySQL 8.0.36 is required. Other MySQL versions may not work. Download the [MySQL 8.0.36](https://downloads.mysql.com/archives/community/) ZIP archive or msi installer. If the zip archive is used, unzip it to a folder before using it.
1919
20-
Run `build_installer.ps1` with specified MySQL 8.0.31 installation or unzipped folder path in a developer powershell. For example
20+
Run `build_installer.ps1` with specified MySQL 8.0.36 installation or unzipped folder path in a developer powershell. For example
2121
```
22-
.\build_installer.ps1 x64 Release "Visual Studio 16 2019" "C:\Users\Roy\Downloads\mysql-8.0.31-winx64\mysql-8.0.31-winx64"
22+
.\build_installer.ps1 x64 Release "Visual Studio 16 2019" "C:\Users\MyUser\Downloads\mysql-8.0.36-winx64\mysql-8.0.36-winx64"
2323
```
2424
2525
### Troubleshooting:

scripts/sign_installer.ps1

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Sign a single file
2+
function Invoke-SignFile {
3+
[OutputType([Boolean])]
4+
Param(
5+
# The path to the file to sign
6+
[Parameter(Mandatory=$true)]
7+
[string]$SourcePath,
8+
# The path to the signed file
9+
[Parameter(Mandatory=$true)]
10+
[string]$TargetPath,
11+
# The name of the unsigned AWS bucket
12+
[Parameter(Mandatory=$true)]
13+
[string]$AwsUnsignedBucket,
14+
[Parameter(Mandatory=$true)]
15+
# The name of the signed AWS bucket
16+
[string]$AwsSignedBucket,
17+
# The name of the AWS key
18+
[Parameter(Mandatory=$true)]
19+
[string]$AwsKey,
20+
[Parameter(Mandatory=$false)]
21+
[bool]$AsMockResponse=$false
22+
)
23+
24+
Write-Host "Signing is enabled. Will attempt to sign"
25+
26+
# Remember to install 'jq' dependency before
27+
if ($AsMockResponse) {
28+
Copy-Item $SourcePath $TargetPath
29+
return $true
30+
}
31+
32+
# Upload unsigned .msi to S3 Bucket
33+
Write-Host "Obtaining version id and uploading unsigned .msi to S3 Bucket"
34+
$versionId = $( aws s3api put-object --bucket $AwsUnsignedBucket --key $AwsKey --body $SourcePath --acl bucket-owner-full-control | jq '.VersionId' )
35+
$jobId = ""
36+
37+
if ([string]::IsNullOrEmpty($versionId)) {
38+
Write-Host "Failed to PUT unsigned file in bucket."
39+
return $false
40+
}
41+
42+
# Attempt to get Job ID from bucket tagging, will retry up to 3 times before exiting with a failure code.
43+
# Will sleep for 5 seconds between retries.
44+
Write-Host "Attempt to get Job ID from bucket tagging, will retry up to 3 times before exiting with a failure code."
45+
for ( $i = 0; $i -lt 3; $i++ ) {
46+
# Get job ID
47+
$id=$( aws s3api get-object-tagging --bucket $AwsUnsignedBucket --key $AwsKey --version-id $versionId | jq -r '.TagSet[0].Value' )
48+
if ( $id -ne "null" ) {
49+
$jobId = $id
50+
break
51+
}
52+
53+
Write-Host "Will sleep for 5 seconds between retries."
54+
Start-Sleep -Seconds 5
55+
}
56+
57+
if ( $jobId -eq "" ) {
58+
Write-Host "Exiting because unable to retrieve job ID"
59+
return $false
60+
}
61+
62+
# Poll signed S3 bucket to see if the signed artifact is there
63+
Write-Host "Poll signed S3 bucket to see if the signed artifact is there"
64+
aws s3api wait object-exists --bucket $AwsSignedBucket --key $AwsKey-$jobId
65+
66+
# Get signed msi from S3
67+
Write-Host "Get signed msi from S3 to $TargetPath"
68+
aws s3api get-object --bucket $AwsSignedBucket --key $AwsKey-$jobId $TargetPath
69+
70+
Write-Host "Signing completed"
71+
return $true
72+
}
73+
74+
# Sign the installer file for architecture and ODBC version
75+
function Invoke-SignInstaller {
76+
[OutputType([Boolean])]
77+
Param(
78+
# The path to the build directory.
79+
[Parameter(Mandatory=$true)]
80+
[string]$BuildDir,
81+
# The architecture name.
82+
[Parameter(Mandatory=$true)]
83+
[string]$Architecture,
84+
# The ODBC version.
85+
[Parameter(Mandatory=$true)]
86+
[string]$OdbcVersion,
87+
# The name of the unsigned AWS bucket
88+
[Parameter(Mandatory=$true)]
89+
[string]$AwsUnsignedBucket,
90+
[Parameter(Mandatory=$true)]
91+
# The name of the signed AWS bucket
92+
[string]$AwsSignedBucket,
93+
# The name of the AWS key
94+
[Parameter(Mandatory=$true)]
95+
[string]$AwsKey,
96+
[Parameter(Mandatory=$false)]
97+
[bool]$AsMockResponse=$false
98+
)
99+
100+
$unsignedInstallerPath=$(Join-Path $BuildDir "aws-mysql-odbc-$OdbcVersion-$Architecture.msi")
101+
$signedInstallerPath=$(Join-Path $BuildDir "aws-mysql-odbc-$OdbcVersion-$Architecture-signed.msi")
102+
103+
Write-Host "unsignedInstallerPath=${unsignedInstallerPath}"
104+
Write-Host "signedInstallerPath=${signedInstallerPath}"
105+
106+
# Sign the installer
107+
Write-Host "Signing the installer."
108+
if ( !(Invoke-SignFile $unsignedInstallerPath $signedInstallerPath $AwsUnsignedBucket $AwsSignedBucket $AwsKey -AsMockResponse $AsMockResponse) ) {
109+
Write-Host "Failed to sign installer file."
110+
return $false
111+
}
112+
113+
# Remove unsigned installer and remove "-signed" in signed installer name
114+
Write-Host "Removing unsigned executable."
115+
Remove-Item -Path $unsignedInstallerPath
116+
Rename-Item -Path $signedInstallerPath -NewName "awsmysql-odbc-$OdbcVersion-$Architecture.msi"
117+
118+
return $true
119+
}

0 commit comments

Comments
 (0)