Skip to content

Commit

Permalink
Add Docker publish automation
Browse files Browse the repository at this point in the history
  • Loading branch information
olljanat committed Sep 17, 2024
1 parent 8b252c9 commit 88ddcda
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 5 deletions.
Empty file added .github/docker-versions-to-skip
Empty file.
81 changes: 81 additions & 0 deletions .github/publish-docker.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
$files = Get-ChildItem -Path ./d -Include "docker-*" -Exclude "docker-compose.yml" -Recurse
$filesShorted = $files | Sort-Object -Descending
$latestPublished = $filesShorted[0].Name -replace "docker-","" -replace ".yml",""

[array]$dockerVersionsToSkip = Get-Content ./.github/docker-versions-to-skip

Write-Host "Getting latest Docker release tag to publish"
$dockerReleases = Invoke-RestMethod -UseBasicParsing https://api.github.com/repos/moby/moby/releases
$nonPreviewReleases = $dockerReleases | Where-Object {$_.prerelease -eq $false}
$versionsShorted = $nonPreviewReleases.name | Sort-Object -Descending
$latestMajor = ""
$latestToPublish = ""
forEach($v in $versionsShorted) {
if ($latestMajor -eq "") {
$latestMajor = ($v -split "\.")[0] -replace "^v",""
}
if ($v -like "v$($latestMajor).*") {
continue
}
$latestToPublish = $v -replace "^v",""
break
}

if ($latestToPublish -eq $latestPublished) {
Write-Host "Version $latestToPublish is latest and already published"
echo "CREATE_PR=false" >> "$GITHUB_ENV"
return
}
if ($latestToPublish -in $dockerVersionsToSkip) {
Write-Host "Version $latestToPublish is in skip list"
echo "CREATE_PR=false" >> "$GITHUB_ENV"
return
}
Write-Host "Version $latestToPublish is latest, trying to publish"
try {
$tarUrl = "https://download.docker.com/linux/static/stable/x86_64/docker-" + $latestToPublish + ".tgz"
Invoke-RestMethod -Uri $tarUrl -Method HEAD
} catch {
Write-Host "Package $tarUrl is not available"
$latestToPublish | Out-File ./.github/docker-versions-to-skip -Append
echo "CREATE_PR=true" >> "$GITHUB_ENV"
echo "PR_TITLE=Skip Docker $latestToPublish" >> "$GITHUB_ENV"
return
}

"- docker-$latestToPublish" | Out-File ./index.yml -Append

$dockerYML = @'
docker:
image: ${REGISTRY_DOMAIN}/burmilla/os-docker:
'@

$dockerYML += $latestToPublish
$dockerYML += @'
${SUFFIX}
command: ros user-docker
environment:
- HTTP_PROXY
- HTTPS_PROXY
- NO_PROXY
labels:
io.rancher.os.scope: system
io.rancher.os.after: console
net: host
pid: host
ipc: host
uts: host
privileged: true
restart: always
volumes_from:
- all-volumes
volumes:
- /sys:/host/sys
- /var/lib/system-docker:/var/lib/system-docker:shared
'@
$dockerYML | Out-File "./d/docker-$latestToPublish.yml" -Append
ln -s docker "./images/10-docker-$latestToPublish"

echo "CREATE_PR=true" >> "$GITHUB_ENV"
echo "PR_TITLE=Add Docker $latestToPublish" >> "$GITHUB_ENV"
3 changes: 2 additions & 1 deletion .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ on:
push:
branches:
- v2.0.1
- v2.0.x

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: '0'

Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: build-docker

on:
workflow_dispatch:
schedule:
- cron: '38 01 * * 1,3'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Publish Docker
shell: pwsh
run: . ./.github/publish-docker.ps1

- name: Create Pull Request
if: env.CREATE_PR == 'true'
uses: peter-evans/create-pull-request@v7
with:
branch: v2.0.x
title: ${{ env.PR_TITLE }}
body: ${{ env.PR_TITLE }}
add-paths: .
2 changes: 1 addition & 1 deletion .github/workflows/pull-request-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Test with dapper
run: |
Expand Down
1 change: 1 addition & 0 deletions images/10-docker-26.1.4
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ ARCH=$2
if [ "$ARCH" == "amd64" ]; then
DOCKERARCH="x86_64"
URL="https://download.docker.com/linux/static/stable/${DOCKERARCH}/docker-${VERSION}.tgz"
#ROOTLESS_URL="https://download.docker.com/linux/static/stable/${DOCKERARCH}/docker-rootless-extras-${VERSION}.tgz"
COMPLETION_URL="https://raw.githubusercontent.com/docker/cli/v${VERSION}/contrib/completion/bash/docker"
fi

DEST="./images/10-docker-${VERSION}${SUFFIX}"

mkdir -p $DEST
curl -sL ${URL} | tar xzf - -C $DEST
#curl -sL ${ROOTLESS_URL} | tar xzf - -C $DEST
curl -sL -o $DEST/docker/completion ${COMPLETION_URL}
mv $DEST/docker $DEST/engine
#mv $DEST/docker-rootless-extras/* $DEST/engine

0 comments on commit 88ddcda

Please sign in to comment.