create automation to update buildkit version
parent
a05fd98943
commit
c0a79c3ca2
|
@ -0,0 +1,48 @@
|
|||
name: "update-buildkit-version"
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
# every Monday at around 3 am pacific/10 am UTC
|
||||
- cron: "0 10 * * 1"
|
||||
env:
|
||||
GOPROXY: https://proxy.golang.org
|
||||
GO_VERSION: '1.20.1'
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
bump-buildkit-version:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
|
||||
- uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568
|
||||
with:
|
||||
go-version: ${{env.GO_VERSION}}
|
||||
cache: true
|
||||
cache-dependency-path: ./go.sum
|
||||
- name: Bump buildkit Version
|
||||
id: bumpBuildkit
|
||||
run: |
|
||||
make update-buildkit-version
|
||||
# The following is to support multiline with GITHUB_OUTPUT, see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
|
||||
echo "changes<<EOF" >> $GITHUB_OUTPUT
|
||||
echo "$(git status --porcelain)" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
- name: Create PR
|
||||
if: ${{ steps.bumpBuildkit.outputs.changes != '' }}
|
||||
uses: peter-evans/create-pull-request@2b011faafdcbc9ceb11414d64d0573f37c774b04
|
||||
with:
|
||||
token: ${{ secrets.MINIKUBE_BOT_PAT }}
|
||||
commit-message: bump buildkit version
|
||||
committer: minikube-bot <minikube-bot@google.com>
|
||||
author: minikube-bot <minikube-bot@google.com>
|
||||
branch: auto_bump_buildkit_version
|
||||
push-to-fork: minikube-bot/minikube
|
||||
base: master
|
||||
delete-branch: true
|
||||
title: 'bump buildkit version'
|
||||
labels: ok-to-test
|
||||
body: |
|
||||
buildkit Project released a [new version](https://github.com/moby/buildkit/releases),
|
||||
|
||||
This PR was auto-generated by `make update-buildkit-version` using [update-buildkit-version.yml](https://github.com/kubernetes/minikube/tree/master/.github/workflows/update-buildkit-version.yml) CI Workflow.
|
5
Makefile
5
Makefile
|
@ -1082,6 +1082,11 @@ update-containerd-version:
|
|||
(cd hack/update/containerd_version && \
|
||||
go run update_containerd_version.go)
|
||||
|
||||
.PHONY: update-buildkit-version
|
||||
update-buildkit-version:
|
||||
(cd hack/update/buildkit_version && \
|
||||
go run update_buildkit_version.go)
|
||||
|
||||
.PHONY: generate-licenses
|
||||
generate-licenses:
|
||||
./hack/generate_licenses.sh
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
Copyright 2023 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/minikube/hack/update"
|
||||
)
|
||||
|
||||
const cxTimeout = 5 * time.Minute
|
||||
|
||||
var (
|
||||
schema = map[string]update.Item{
|
||||
"deploy/kicbase/Dockerfile": {
|
||||
Replace: map[string]string{
|
||||
`ARG BUILDKIT_VERSION=".*"`: `ARG BUILDKIT_VERSION="{{.Version}}"`,
|
||||
},
|
||||
},
|
||||
"deploy/iso/minikube-iso/arch/aarch64/package/buildkit-bin-aarch64/buildkit-bin.mk": {
|
||||
Replace: map[string]string{
|
||||
`BUILDKIT_BIN_AARCH64_VERSION = .*`: `BUILDKIT_BIN_AARCH64_VERSION = {{.Version}}`,
|
||||
`BUILDKIT_BIN_AARCH64_COMMIT = .*`: `BUILDKIT_BIN_AARCH64_COMMIT = {{.Commit}}`,
|
||||
},
|
||||
},
|
||||
"deploy/iso/minikube-iso/arch/x86_64/package/containerd-bin/containerd-bin.mk": {
|
||||
Replace: map[string]string{
|
||||
`BUILDKIT_BIN_VERSION = .*`: `BUILDKIT_BIN_VERSION = {{.Version}}`,
|
||||
`BUILDKIT_BIN_COMMIT = .*`: `BUILDKIT_BIN_COMMIT = {{.Commit}}`,
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
type Data struct {
|
||||
Version string
|
||||
Commit string
|
||||
}
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), cxTimeout)
|
||||
defer cancel()
|
||||
|
||||
stable, _, _, err := update.GHReleases(ctx, "moby", "buildkit")
|
||||
if err != nil {
|
||||
klog.Fatalf("Unable to get buildkit stable version: %v", err)
|
||||
}
|
||||
|
||||
data := Data{Version: stable.Tag, Commit: stable.Commit}
|
||||
|
||||
update.Apply(schema, data)
|
||||
|
||||
if err := updateHashFile(data.Version, "amd64", "x86_64/package/buildkit-bin/buildkit-bin.hash"); err != nil {
|
||||
klog.Fatalf("failed to update amd64 hash file: %v", err)
|
||||
}
|
||||
if err := updateHashFile(data.Version, "arm64", "aarch64/package/buildkit-bin-aarch64/buildkit-bin.hash"); err != nil {
|
||||
klog.Fatalf("failed to update arm64 hash file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func updateHashFile(version, arch, filePath string) error {
|
||||
filePath = "../../../deploy/iso/minikube-iso/arch/" + filePath
|
||||
b, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read hash file: %v", err)
|
||||
}
|
||||
if strings.Contains(string(b), version) {
|
||||
klog.Infof("hash file already contains %q", version)
|
||||
return nil
|
||||
}
|
||||
r, err := http.Get(fmt.Sprintf("https://github.com/moby/buildkit/releases/download/%s/buildkit-%s.linux-%s.tar.gz", version, version, arch))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to download source code: %v", err)
|
||||
}
|
||||
defer r.Body.Close()
|
||||
b, err = io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read response body: %v", err)
|
||||
}
|
||||
sum := sha256.Sum256(b)
|
||||
b, err = os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read hash file: %v", err)
|
||||
}
|
||||
if strings.Contains(string(b), version) {
|
||||
klog.Infof("hash file already contains %q", version)
|
||||
return nil
|
||||
}
|
||||
f, err := os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open hash file: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
if _, err := f.WriteString(fmt.Sprintf("sha256 %x buildkit-%s.linux-%s.tar.gz\n", sum, version, arch)); err != nil {
|
||||
return fmt.Errorf("failed to write to hash file: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -135,6 +135,11 @@ var (
|
|||
`GO_VERSION: .*`: `GO_VERSION: '{{.StableVersion}}'`,
|
||||
},
|
||||
},
|
||||
".github/workflows/update-buildkit-version.yml": {
|
||||
Replace: map[string]string{
|
||||
`GO_VERSION: .*`: `GO_VERSION: '{{.StableVersion}}'`,
|
||||
},
|
||||
},
|
||||
".github/workflows/sync-minikube.yml": {
|
||||
Replace: map[string]string{
|
||||
`GO_VERSION: .*`: `GO_VERSION: '{{.StableVersion}}'`,
|
||||
|
|
Loading…
Reference in New Issue