This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 920
99 lines (88 loc) · 3.33 KB
/
prebuild-docker.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
name: Prebuild Docker image
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Azure login
uses: Azure/login@v1
with:
creds: ${{ secrets.ACR_CREDENTIALS }}
- name: Docker Login
run: az acr login -n qdkimages
- name: Build and push Docker image
# Would be nice to invoke "test-docker-image-build.yml" workflow here to avoid the code duplication,
# but the other workflows can only be invoked in a separate job (with no extra steps),
# rather than in a separate step.
# And different jobs use different runners (build agents), i.e. if one job invokes a workflow
# then the subsequent job cannot just use the binaries produced by that workflow.
# One job can only pass the binaries to the other job by means of artifacts, upload by one job and
# download by another job. But artifacts upload is alien for that workflow.
# https://docs.github.com/actions/using-workflows/storing-workflow-data-as-artifacts
run: |
$Now = [DateTime]::Now;
$ImageTag = "${{ github.sha }}"
$RepoName = "public/quantum/samples"
$LocalTag = "${RepoName}:${ImageTag}"
$RemoteRepo = "${{ secrets.ACR_REGISTRY }}/${RepoName}"
docker build Build/images/samples --tag $LocalTag
docker tag $LocalTag "${RemoteRepo}:${ImageTag}"
docker push "${RemoteRepo}:${ImageTag}"
docker tag $LocalTag "${RemoteRepo}:latest"
docker push "${RemoteRepo}:latest"
shell: pwsh
- name: Wait for image to publish
run: |
function Test-Manifest() {
try {
$manifest = Invoke-RestMethod `
"https://mcr.microsoft.com/v2/quantum/samples/manifests/${{ github.sha }}" `
-ErrorAction Continue;
Write-Verbose $manifest;
return $true;
} catch {
return $false;
}
}
$ImageAvailable = $false;
$CheckInterval = 30; # [seconds]
while (-not $ImageAvailable) {
if (Test-Manifest) {
Write-Host "##[info] Image $ImageTag now available on mcr.microsoft.com, proceeding."
$ImageAvailable = $true;
} else {
Write-Host "##[info] Image $ImageTag not yet available on mcr.microsoft.com, waiting $CheckInterval seconds.";
}
Start-Sleep -Seconds $CheckInterval;
}
shell: pwsh
- name: Update Binder configuration
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
$ThisCommit = "${{ github.sha }}"
git checkout ⭐binder
git reset --hard $ThisCommit
$Dockerfile = Get-Content ./Dockerfile;
$Dockerfile `
| ForEach-Object {
if ($_.StartsWith("FROM ")) {
"FROM mcr.microsoft.com/quantum/samples:$ThisCommit" | Write-Output;
} else {
$_ | Write-Output;
}
} `
| Set-Content ./Dockerfile
git add Dockerfile
git commit -m "Updated Binder to use $ThisCommit."
shell: pwsh
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
force: true
branch: ⭐binder