Skip to content

Commit

Permalink
Organization support in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kenmuse authored Aug 27, 2024
1 parent 6df1c11 commit 91ecd4a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,21 @@ jobs:
# The org variable should be non-empty and match the owner name if this is an organization.
$packageUrl = ($repoOwner -eq $orgName) ? "https://api.github.com/orgs/$repoOwner/packages/container/$repoName/versions" : "https://api.github.com/users/$repoOwner/packages/container/$repoName/versions"
$publishedImageVersions = $((Invoke-WebRequest -Headers @{ "Authorization"=$env:AUTH } -Uri $packageUrl).Content | ConvertFrom-Json) | %{ [PSCustomObject]@{ Id=$_.id; Url=$_.url;Tags=$_.metadata.container.tags } } | %{ $_.tags }
# PowerShell 7 syntax to avoid raising an exception.
$apiResults = Invoke-WebRequest -Headers @{ "Authorization"=$env:AUTH } -Uri $packageUrl -SkipHttpErrorCheck
if ($apiResults.StatusCode -eq 200) {
$content = $apiResults.Content | ConvertFrom-Json
}
elseif ($apiResults.StatusCode -eq 404) {
$content = @()
}
else {
Write-Host "Status Code: ${apiResults.StatusCode}"
Write-Host "Error: ${apiResults.Content}"
exit $apiResults.StatusCode
}
$publishedImageVersions = $($apiResults.Content | ConvertFrom-Json) | %{ [PSCustomObject]@{ Id=$_.id; Url=$_.url;Tags=$_.metadata.container.tags } } | %{ $_.tags }
$currentRunnerVersion = ((Invoke-WebRequest -Uri https://api.github.com/repos/actions/runner/releases/latest).Content | ConvertFrom-Json).tag_name -replace 'v',''
$currentHooksVersion = ((Invoke-WebRequest -Uri https://api.github.com/repos/actions/runner-container-hooks/releases/latest).Content | ConvertFrom-Json).tag_name -replace 'v',''
Expand Down
28 changes: 14 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPrefe

WORKDIR /home/runner

RUN `
RUN <<EOF
###############################################################################################
# Install Actions Runner
# You must always install the runner, and you want the latest version to avoid the restrictions
# applied to out-of-date runners.
# https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/autoscaling-with-self-hosted-runners#:~:text=Warning,-Any%20updates%20released
###############################################################################################

Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v${env:RUNNER_VERSION}/actions-runner-${env:RUNNER_OS}-${env:RUNNER_ARCH}-${env:RUNNER_VERSION}.zip -OutFile actions-runner.zip; `
Add-Type -AssemblyName System.IO.Compression.FileSystem; `
[System.IO.Compression.ZipFile]::ExtractToDirectory('actions-runner.zip', $PWD); `
Remove-Item -Path actions-runner.zip -Force; `
Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v${env:RUNNER_VERSION}/actions-runner-${env:RUNNER_OS}-${env:RUNNER_ARCH}-${env:RUNNER_VERSION}.zip -OutFile actions-runner.zip;
Add-Type -AssemblyName System.IO.Compression.FileSystem;
[System.IO.Compression.ZipFile]::ExtractToDirectory('actions-runner.zip', $PWD);
Remove-Item -Path actions-runner.zip -Force;

###############################################################################################
# Install Runner Container Hooks
Expand All @@ -32,9 +32,9 @@ RUN `
# and https://github.com/actions/runner/issues/904
###############################################################################################

# Invoke-WebRequest -OutFile runner-container-hooks.zip -Uri https://github.com/actions/runner-container-hooks/releases/download/v${env:RUNNER_CONTAINER_HOOKS_VERSION}/actions-runner-hooks-k8s-${env:RUNNER_CONTAINER_HOOKS_VERSION}.zip;`
# [System.IO.Compression.ZipFile]::ExtractToDirectory('runner-container-hooks.zip', (Join-Path -Path $PWD -ChildPath 'k8s')); `
# Remove-Item -Path runner-container-hooks.zip -Force; `
# Invoke-WebRequest -OutFile runner-container-hooks.zip -Uri https://github.com/actions/runner-container-hooks/releases/download/v${env:RUNNER_CONTAINER_HOOKS_VERSION}/actions-runner-hooks-k8s-${env:RUNNER_CONTAINER_HOOKS_VERSION}.zip;
# [System.IO.Compression.ZipFile]::ExtractToDirectory('runner-container-hooks.zip', (Join-Path -Path $PWD -ChildPath 'k8s'));
# Remove-Item -Path runner-container-hooks.zip -Force;

###############################################################################################
# Install Git Using Choco
Expand All @@ -43,11 +43,11 @@ RUN `
# You may want to include other tools and script engines as well.
###############################################################################################

Set-ExecutionPolicy Bypass -Scope Process -Force; `
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; `
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')); `
choco install git.install --params "'/GitAndUnixToolsOnPath'" -y; `
choco feature enable -n allowGlobalConfirmation; `
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'));
choco install git.install --params "'/GitAndUnixToolsOnPath'" -y;
choco feature enable -n allowGlobalConfirmation;

###############################################################################################
# Install Docker CLI Using Choco
Expand All @@ -57,4 +57,4 @@ RUN `
###############################################################################################

choco install docker-cli docker-compose -force;
EOF

0 comments on commit 91ecd4a

Please sign in to comment.