Skip to content

Commit 63b7bc4

Browse files
[macos] refactor XCode installation approach (#7858)
* [macos] refactor XCode installation approach xcversion does not work anymore, we are switching to storing XCode installers in intermediate Azure storage * remove xcode_install_user, xcode_install_password * rename xcode_install_storage --> xcode_install_storage_url * mark xcode installation variables sensitive * remove xcversion_auth_cookie variable * renamed forgotten xcode_install_storage --> xcode_install_storage_url * remove leftover xcode_install_user
1 parent 406a784 commit 63b7bc4

File tree

13 files changed

+57
-142
lines changed

13 files changed

+57
-142
lines changed

.github/workflows/macos-generation.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ jobs:
105105
-VIPassword ${{ secrets.VI_PASSWORD }} `
106106
-Cluster ${{ env.ESXI_CLUSTER }}
107107
108-
- name: Create xcversion session cookie file
109-
shell: bash
110-
run: |
111-
mkdir -p ${{ runner.temp }}/xcversion-cookie
112-
cookie='${{ secrets.XCVERSION_AUTH_COOKIE }}'
113-
echo "$cookie" > ${{ runner.temp }}/xcversion-cookie/cookie
114-
115108
- name: Build VM
116109
run: |
117110
$SensitiveData = @(
@@ -131,9 +124,6 @@ jobs:
131124
-var="github_api_pat=${{ secrets.GH_FEED_TOKEN }}" `
132125
-var="build_id=${{ env.VM_NAME }}" `
133126
-var="baseimage_name=${{ inputs.base_image_name }}" `
134-
-var="xcode_install_user=${{ secrets.XCODE_USER }}" `
135-
-var="xcode_install_password=${{ secrets.XCODE_PASSWORD }}" `
136-
-var="xcversion_auth_cookie=${{ env.XCVERSION_COOKIE_PATH }}" `
137127
-color=false `
138128
${{ inputs.template_path }} `
139129
| Where-Object {

images.CI/macos/azure-pipelines/image-generation.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ jobs:
8383
-var="github_api_pat=$(github_api_pat)" `
8484
-var="build_id=$(VirtualMachineName)" `
8585
-var="baseimage_name=${{ parameters.base_image_name }}" `
86-
-var="xcode_install_user=$(xcode-installation-user)" `
87-
-var="xcode_install_password=$(xcode-installation-password)" `
88-
-var="xcversion_auth_cookie=$(xcVersionCookie.secureFilePath)" `
86+
-var="xcode_install_storage_url=$(xcode_install_storage_url)" `
87+
-var="xcode_install_sas=$(xcode_install_sas)" `
8988
-color=false `
9089
${{ parameters.template_path }} `
9190
| Where-Object {

images/macos/helpers/Xcode.Installer.psm1

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@ function Invoke-DownloadXcodeArchive {
2424
[string]$Version
2525
)
2626

27-
$resolvedVersion = Resolve-ExactXcodeVersion -Version $Version
28-
if (-not $resolvedVersion) {
29-
throw "Version '$Version' can't be matched to any available version"
30-
}
31-
Write-Host "Downloading Xcode $resolvedVersion"
32-
Invoke-XCVersion -Arguments "install '$resolvedVersion' --no-install" | Out-Host
27+
Write-Host "Downloading Xcode $Version"
28+
29+
$tempXipDirectory = New-Item -Path $DownloadDirectory -Name "Xcode$Version" -ItemType "Directory"
30+
31+
$xcodeFileName = 'Xcode-{0}.xip' -f $Version
32+
$xcodeUri = '{0}{1}{2}'-f ${env:XCODE_INSTALL_STORAGE_URL}, $xcodeFileName, ${env:XCODE_INSTALL_SAS}
3333

34-
$xcodeXipName = "$resolvedVersion" -replace " ", "_"
35-
$xcodeXipFile = Get-ChildItem -Path $DownloadDirectory -Filter "Xcode_$xcodeXipName.xip" | Select-Object -First 1
36-
$tempXipDirectory = New-Item -Path $DownloadDirectory -Name "Xcode$xcodeXipName" -ItemType "Directory"
37-
Move-Item -Path "$xcodeXipFile" -Destination $tempXipDirectory
34+
Invoke-WebRequest -Uri $xcodeUri -OutFile (Join-Path $tempXipDirectory $xcodeFileName)
3835

3936
return $tempXipDirectory
4037

@@ -86,7 +83,7 @@ function Expand-XcodeXipArchive {
8683
[string]$TargetPath
8784
)
8885

89-
$xcodeXipPath = Get-ChildItem -Path $DownloadDirectory -Filter "Xcode_*.xip" | Select-Object -First 1
86+
$xcodeXipPath = Get-ChildItem -Path $DownloadDirectory -Filter "Xcode-*.xip" | Select-Object -First 1
9087

9188
Write-Host "Extracting Xcode from '$xcodeXipPath'"
9289
Push-Location $DownloadDirectory

images/macos/provision/core/xcode.ps1

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
# The script currently requires 2 external variables to be set: XCODE_INSTALL_USER
2-
# and XCODE_INSTALL_PASSWORD, in order to access the Apple Developer Center
3-
41
$ErrorActionPreference = "Stop"
52

63
Import-Module "$env:HOME/image-generation/helpers/Common.Helpers.psm1"
74
Import-Module "$env:HOME/image-generation/helpers/Xcode.Installer.psm1"
85

9-
if ([string]::IsNullOrEmpty($env:XCODE_INSTALL_USER) -or [string]::IsNullOrEmpty($env:XCODE_INSTALL_PASSWORD)) {
10-
throw "Required environment variables XCODE_INSTALL_USER and XCODE_INSTALL_PASSWORD are not set"
11-
}
12-
136
# Spaceship Apple ID login fails due to Apple ID prompting to be upgraded to 2FA.
147
# https://github.com/fastlane/fastlane/pull/18116
158
$env:SPACESHIP_SKIP_2FA_UPGRADE = 1

images/macos/templates/macOS-11.anka.pkr.hcl

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,16 @@ variable "github_api_pat" {
3434
default = ""
3535
}
3636

37-
variable "xcode_install_user" {
37+
variable "xcode_install_storage_url" {
3838
type = string
3939
sensitive = true
4040
}
4141

42-
variable "xcode_install_password" {
42+
variable "xcode_install_sas" {
4343
type = string
4444
sensitive = true
4545
}
4646

47-
variable "xcversion_auth_cookie" {
48-
type = string
49-
default = ""
50-
}
51-
5247
variable "vcpu_count" {
5348
type = string
5449
default = "6"
@@ -187,17 +182,11 @@ build {
187182
]
188183
execute_command = "chmod +x {{ .Path }}; source $HOME/.bash_profile; {{ .Vars }} {{ .Path }}"
189184
}
190-
provisioner "shell" {
191-
inline = [
192-
"mkdir -p ~/.fastlane/spaceship/${var.xcode_install_user}",
193-
"echo ${var.xcversion_auth_cookie} | base64 --decode > ~/.fastlane/spaceship/${var.xcode_install_user}/cookie"
194-
]
195-
}
196185
provisioner "shell" {
197186
script = "./provision/core/xcode.ps1"
198187
environment_vars = [
199-
"XCODE_INSTALL_USER=${var.xcode_install_user}",
200-
"XCODE_INSTALL_PASSWORD=${var.xcode_install_password}"
188+
"XCODE_INSTALL_STORAGE_URL=${var.xcode_install_storage_url}",
189+
"XCODE_INSTALL_SAS=${var.xcode_install_sas}"
201190
]
202191
execute_command = "chmod +x {{ .Path }}; source $HOME/.bash_profile; {{ .Vars }} pwsh -f {{ .Path }}"
203192
}

images/macos/templates/macOS-11.json

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
"vm_username": null,
1313
"vm_password": null,
1414
"github_api_pat": null,
15-
"xcode_install_user": null,
16-
"xcode_install_password": null,
17-
"xcversion_auth_cookie": null,
15+
"xcode_install_storage_url": null,
16+
"xcode_install_sas": null,
1817
"image_os": "macos11"
1918
},
2019
"builders": [
@@ -165,22 +164,13 @@
165164
"API_PAT={{user `github_api_pat`}}"
166165
]
167166
},
168-
{
169-
"type": "shell",
170-
"inline": "mkdir -p ~/.fastlane/spaceship/{{user `xcode_install_user`}}"
171-
},
172-
{
173-
"type": "file",
174-
"source": "{{user `xcversion_auth_cookie`}}",
175-
"destination": "~/.fastlane/spaceship/{{user `xcode_install_user`}}/cookie"
176-
},
177167
{
178168
"type": "shell",
179169
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}",
180170
"script": "./provision/core/xcode.ps1",
181171
"environment_vars": [
182-
"XCODE_INSTALL_USER={{user `xcode_install_user`}}",
183-
"XCODE_INSTALL_PASSWORD={{user `xcode_install_password`}}"
172+
"XCODE_INSTALL_STORAGE_URL={{user `xcode_install_storage_url`}}",
173+
"XCODE_INSTALL_SAS={{user `xcode_install_sas`}}"
184174
]
185175
},
186176
{

images/macos/templates/macOS-12.anka.pkr.hcl

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,16 @@ variable "github_api_pat" {
3434
default = ""
3535
}
3636

37-
variable "xcode_install_user" {
37+
variable "xcode_install_storage_url" {
3838
type = string
3939
sensitive = true
4040
}
4141

42-
variable "xcode_install_password" {
42+
variable "xcode_install_sas" {
4343
type = string
4444
sensitive = true
4545
}
4646

47-
variable "xcversion_auth_cookie" {
48-
type = string
49-
default = ""
50-
}
51-
5247
variable "vcpu_count" {
5348
type = string
5449
default = "6"
@@ -188,17 +183,11 @@ build {
188183
]
189184
execute_command = "chmod +x {{ .Path }}; source $HOME/.bash_profile; {{ .Vars }} {{ .Path }}"
190185
}
191-
provisioner "shell" {
192-
inline = [
193-
"mkdir -p ~/.fastlane/spaceship/${var.xcode_install_user}",
194-
"echo ${var.xcversion_auth_cookie} | base64 --decode > ~/.fastlane/spaceship/${var.xcode_install_user}/cookie"
195-
]
196-
}
197186
provisioner "shell" {
198187
script = "./provision/core/xcode.ps1"
199188
environment_vars = [
200-
"XCODE_INSTALL_USER=${var.xcode_install_user}",
201-
"XCODE_INSTALL_PASSWORD=${var.xcode_install_password}"
189+
"XCODE_INSTALL_STORAGE_URL=${var.xcode_install_storage_url}",
190+
"XCODE_INSTALL_SAS=${var.xcode_install_sas}"
202191
]
203192
execute_command = "chmod +x {{ .Path }}; source $HOME/.bash_profile; {{ .Vars }} pwsh -f {{ .Path }}"
204193
}

images/macos/templates/macOS-12.json

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
"vm_username": null,
1313
"vm_password": null,
1414
"github_api_pat": null,
15-
"xcode_install_user": null,
16-
"xcode_install_password": null,
17-
"xcversion_auth_cookie": null,
15+
"xcode_install_storage_url": null,
16+
"xcode_install_sas": null,
1817
"image_os": "macos12"
1918
},
2019
"builders": [
@@ -167,22 +166,13 @@
167166
"USER_PASSWORD={{user `vm_password`}}"
168167
]
169168
},
170-
{
171-
"type": "shell",
172-
"inline": "mkdir -p ~/.fastlane/spaceship/{{user `xcode_install_user`}}"
173-
},
174-
{
175-
"type": "file",
176-
"source": "{{user `xcversion_auth_cookie`}}",
177-
"destination": "~/.fastlane/spaceship/{{user `xcode_install_user`}}/cookie"
178-
},
179169
{
180170
"type": "shell",
181171
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}",
182172
"script": "./provision/core/xcode.ps1",
183173
"environment_vars": [
184-
"XCODE_INSTALL_USER={{user `xcode_install_user`}}",
185-
"XCODE_INSTALL_PASSWORD={{user `xcode_install_password`}}"
174+
"XCODE_INSTALL_STORAGE_URL={{user `xcode_install_storage_url`}}",
175+
"XCODE_INSTALL_SAS={{user `xcode_install_sas`}}"
186176
]
187177
},
188178
{

images/macos/templates/macOS-13.anka.pkr.hcl

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,16 @@ variable "github_api_pat" {
3434
default = ""
3535
}
3636

37-
variable "xcode_install_user" {
37+
variable "xcode_install_storage_url" {
3838
type = string
3939
sensitive = true
4040
}
4141

42-
variable "xcode_install_password" {
42+
variable "xcode_install_sas" {
4343
type = string
4444
sensitive = true
4545
}
4646

47-
variable "xcversion_auth_cookie" {
48-
type = string
49-
default = ""
50-
}
51-
5247
variable "vcpu_count" {
5348
type = string
5449
default = "6"
@@ -182,17 +177,11 @@ build {
182177
]
183178
execute_command = "chmod +x {{ .Path }}; source $HOME/.bash_profile; {{ .Vars }} {{ .Path }}"
184179
}
185-
provisioner "shell" {
186-
inline = [
187-
"mkdir -p ~/.fastlane/spaceship/${var.xcode_install_user}",
188-
"echo ${var.xcversion_auth_cookie} | base64 --decode > ~/.fastlane/spaceship/${var.xcode_install_user}/cookie"
189-
]
190-
}
191180
provisioner "shell" {
192181
script = "./provision/core/xcode.ps1"
193182
environment_vars = [
194-
"XCODE_INSTALL_USER=${var.xcode_install_user}",
195-
"XCODE_INSTALL_PASSWORD=${var.xcode_install_password}"
183+
"XCODE_INSTALL_STORAGE_URL=${var.xcode_install_storage_url}",
184+
"XCODE_INSTALL_SAS=${var.xcode_install_sas}"
196185
]
197186
execute_command = "chmod +x {{ .Path }}; source $HOME/.bash_profile; {{ .Vars }} pwsh -f {{ .Path }}"
198187
}

images/macos/templates/macOS-13.arm64.anka.pkr.hcl

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,16 @@ variable "github_api_pat" {
3434
default = ""
3535
}
3636

37-
variable "xcode_install_user" {
37+
variable "xcode_install_storage_url" {
3838
type = string
3939
sensitive = true
4040
}
4141

42-
variable "xcode_install_password" {
42+
variable "xcode_install_sas" {
4343
type = string
4444
sensitive = true
4545
}
4646

47-
variable "xcversion_auth_cookie" {
48-
type = string
49-
default = ""
50-
}
51-
5247
variable "vcpu_count" {
5348
type = string
5449
default = "6"
@@ -182,17 +177,11 @@ build {
182177
]
183178
execute_command = "chmod +x {{ .Path }}; source $HOME/.bash_profile; {{ .Vars }} {{ .Path }}"
184179
}
185-
provisioner "shell" {
186-
inline = [
187-
"mkdir -p ~/.fastlane/spaceship/${var.xcode_install_user}",
188-
"echo ${var.xcversion_auth_cookie} | base64 --decode > ~/.fastlane/spaceship/${var.xcode_install_user}/cookie"
189-
]
190-
}
191180
provisioner "shell" {
192181
script = "./provision/core/xcode.ps1"
193182
environment_vars = [
194-
"XCODE_INSTALL_USER=${var.xcode_install_user}",
195-
"XCODE_INSTALL_PASSWORD=${var.xcode_install_password}"
183+
"XCODE_INSTALL_STORAGE_URL=${var.xcode_install_storage_url}",
184+
"XCODE_INSTALL_SAS=${var.xcode_install_sas}"
196185
]
197186
execute_command = "chmod +x {{ .Path }}; source $HOME/.bash_profile; {{ .Vars }} pwsh -f {{ .Path }}"
198187
}

0 commit comments

Comments
 (0)