From 5899351581328f1541a12e8070593a05fab1f9e1 Mon Sep 17 00:00:00 2001 From: salasberryfin Date: Sat, 8 Apr 2023 20:38:45 +0200 Subject: [PATCH 1/4] automate ubuntu:focal latest version update --- deploy/kicbase/Dockerfile | 4 +- .../ubuntu_version/update_ubuntu_version.go | 88 +++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 hack/update/ubuntu_version/update_ubuntu_version.go diff --git a/deploy/kicbase/Dockerfile b/deploy/kicbase/Dockerfile index 22e015366f..c9e090a1cd 100644 --- a/deploy/kicbase/Dockerfile +++ b/deploy/kicbase/Dockerfile @@ -18,6 +18,8 @@ # https://systemd.io/CONTAINER_INTERFACE/ +# this ARG needs to be global to use it in `FROM` & is updated for new versions of ubuntu:focal-* +ARG UBUNTU_FOCAL_IMAGE="ubuntu:focal-20230308" # multi-stage docker build so we can build auto-pause for arm64 FROM golang:1.20.3 as auto-pause WORKDIR /src @@ -37,7 +39,7 @@ RUN if [ "$PREBUILT_AUTO_PAUSE" != "true" ]; then cd ./cmd/auto-pause/ && go bui # start from ubuntu 20.04, this image is reasonably small as a starting point # for a kubernetes node image, it doesn't contain much we don't need -FROM ubuntu:focal-20230308 as kicbase +FROM ${UBUNTU_FOCAL_IMAGE} as kicbase ARG BUILDKIT_VERSION="v0.11.4" ARG FUSE_OVERLAYFS_VERSION="v1.7.1" diff --git a/hack/update/ubuntu_version/update_ubuntu_version.go b/hack/update/ubuntu_version/update_ubuntu_version.go new file mode 100644 index 0000000000..a973aae644 --- /dev/null +++ b/hack/update/ubuntu_version/update_ubuntu_version.go @@ -0,0 +1,88 @@ +/* +Copyright 2022 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 ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "strings" + + "k8s.io/klog/v2" + + "k8s.io/minikube/hack/update" +) + +const ( + dockerHubUbuntuBaseURL = "https://hub.docker.com/v2/repositories/library/ubuntu/tags" +) + +var ( + schema = map[string]update.Item{ + "deploy/kicbase/Dockerfile": { + Replace: map[string]string{ + `UBUNTU_FOCAL_IMAGE=.*`: `UBUNTU_FOCAL_IMAGE="{{.LatestVersion}}"`, + }, + }, + } +) + +// Data holds latest Ubuntu focal version in semver format. +type Data struct { + LatestVersion string +} + +// Response is used to unmarshal the response from Docker Hub +type Response struct { + Results []struct { + Name string `json:"name"` + } +} + +func getLatestVersion() (string, error) { + resp, err := http.Get(dockerHubUbuntuBaseURL) + if err != nil { + klog.Fatalf("Unable to get Ubuntu focal's latest version: %v", err) + } + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + + var content Response + err = json.Unmarshal(body, &content) + if err != nil { + klog.Fatalf("Unable to unmarshall response from Docker Hub: %v", err) + } + + for _, i := range content.Results { + if strings.Contains(i.Name, "focal-") { + return i.Name, nil + } + } + + return "", fmt.Errorf("The response from Docker Hub does not contain a latest focal image\n") +} + +func main() { + // get Ubuntu Focal latest version + latest, err := getLatestVersion() + if err != nil { + klog.Fatalf("Unable to find latest ubuntu:focal version: %v\n", err) + } + data := Data{LatestVersion: fmt.Sprintf("ubuntu:%s", latest)} + klog.Infof("Ubuntu focal latest version: %s", latest) + + update.Apply(schema, data) +} From f71b903f4069dedf7770b10904f507cb2c749638 Mon Sep 17 00:00:00 2001 From: salasberryfin Date: Sat, 8 Apr 2023 20:53:13 +0200 Subject: [PATCH 2/4] add GitHub Action to check for ubuntu:focal updates periodically --- .github/workflows/update-ubuntu-version.yml | 48 +++++++++++++++++++ Makefile | 5 ++ .../golang_version/update_golang_version.go | 5 ++ .../ubuntu_version/update_ubuntu_version.go | 29 +++++++++-- 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/update-ubuntu-version.yml diff --git a/.github/workflows/update-ubuntu-version.yml b/.github/workflows/update-ubuntu-version.yml new file mode 100644 index 0000000000..5351c5fff7 --- /dev/null +++ b/.github/workflows/update-ubuntu-version.yml @@ -0,0 +1,48 @@ +name: "update-ubuntu-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.3' +permissions: + contents: read + +jobs: + bump-ubuntu-version: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 + - uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 + with: + go-version: ${{env.GO_VERSION}} + cache-dependency-path: ./go.sum + - name: Bump Ubuntu version + id: bumpUbuntu + run: | + echo "OLD_VERSION=$(DEP=ubuntu make get-dependency-version)" >> $GITHUB_OUTPUT + make update-ubuntu-version + echo "NEW_VERSION=$(DEP=ubuntu make get-dependency-version)" >> $GITHUB_OUTPUT + # 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<> $GITHUB_OUTPUT + echo "$(git status --porcelain)" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + - name: Create PR + if: ${{ steps.bumpUbuntu.outputs.changes != '' }} + uses: peter-evans/create-pull-request@5b4a9f6a9e2af26e5f02351490b90d01eb8ec1e5 + with: + token: ${{ secrets.MINIKUBE_BOT_PAT }} + commit-message: 'Site: Update ubuntu from ${{ steps.bumpUbuntu.outputs.OLD_VERSION }} to ${{ steps.bumpUbuntu.outputs.NEW_VERSION }}' + committer: minikube-bot + author: minikube-bot + branch: auto_bump_ubuntu_version + push-to-fork: minikube-bot/minikube + base: master + delete-branch: true + title: 'Site: Update ubuntu from ${{ steps.bumpUbuntu.outputs.OLD_VERSION }} to ${{ steps.bumpUbuntu.outputs.NEW_VERSION }}' + body: | + The ubuntu:focal image released a new version new version + + This PR was auto-generated by `make update-ubuntu-version` using [update-ubuntu-version.yml](https://github.com/kubernetes/minikube/tree/master/.github/workflows/update-ubuntu-version.yml) CI Workflow. diff --git a/Makefile b/Makefile index d1f1d5a555..8a1dc90053 100644 --- a/Makefile +++ b/Makefile @@ -1107,6 +1107,11 @@ update-docker-version: (cd hack/update/docker_version && \ go run update_docker_version.go) +.PHONY: update-ubuntu-version +update-ubuntu-version: + (cd hack/update/ubuntu_version && \ + go run update_ubuntu_version.go) + .PHONY: get-dependency-verison get-dependency-version: @(cd hack/update/get_version && \ diff --git a/hack/update/golang_version/update_golang_version.go b/hack/update/golang_version/update_golang_version.go index f21e6513b0..5e6f12a030 100644 --- a/hack/update/golang_version/update_golang_version.go +++ b/hack/update/golang_version/update_golang_version.go @@ -110,6 +110,11 @@ var ( `GO_VERSION: .*`: `GO_VERSION: '{{.StableVersion}}'`, }, }, + ".github/workflows/update-ubuntu-version.yml": { + Replace: map[string]string{ + `GO_VERSION: .*`: `GO_VERSION: '{{.StableVersion}}'`, + }, + }, ".github/workflows/update-cloud-spanner-emulator-version.yml": { Replace: map[string]string{ `GO_VERSION: .*`: `GO_VERSION: '{{.StableVersion}}'`, diff --git a/hack/update/ubuntu_version/update_ubuntu_version.go b/hack/update/ubuntu_version/update_ubuntu_version.go index a973aae644..c7ef03839a 100644 --- a/hack/update/ubuntu_version/update_ubuntu_version.go +++ b/hack/update/ubuntu_version/update_ubuntu_version.go @@ -1,3 +1,19 @@ +/* +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. +*/ + /* Copyright 2022 The Kubernetes Authors All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +32,7 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strings" @@ -54,16 +70,19 @@ type Response struct { func getLatestVersion() (string, error) { resp, err := http.Get(dockerHubUbuntuBaseURL) if err != nil { - klog.Fatalf("Unable to get Ubuntu focal's latest version: %v", err) + return "", fmt.Errorf("unable to get Ubuntu focal's latest version: %v", err) } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) + if err != nil { + return "", fmt.Errorf("unable to read HTTP response from Docker Hub: %v", err) + } var content Response err = json.Unmarshal(body, &content) if err != nil { - klog.Fatalf("Unable to unmarshall response from Docker Hub: %v", err) + return "", fmt.Errorf("unable to unmarshall response from Docker Hub: %v", err) } for _, i := range content.Results { @@ -72,7 +91,7 @@ func getLatestVersion() (string, error) { } } - return "", fmt.Errorf("The response from Docker Hub does not contain a latest focal image\n") + return "", fmt.Errorf("response from Docker Hub does not contain a latest focal image") } func main() { From 1909cf95c576865d3be5e3d566e6fb971a1f7401 Mon Sep 17 00:00:00 2001 From: salasberryfin Date: Mon, 24 Apr 2023 20:33:37 +0200 Subject: [PATCH 3/4] Add `update-ubuntu-version.yml` workflow configuration for automatic version bump --- .github/workflows/update-ubuntu-version.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/update-ubuntu-version.yml b/.github/workflows/update-ubuntu-version.yml index 5351c5fff7..7fca918610 100644 --- a/.github/workflows/update-ubuntu-version.yml +++ b/.github/workflows/update-ubuntu-version.yml @@ -22,27 +22,27 @@ jobs: - name: Bump Ubuntu version id: bumpUbuntu run: | - echo "OLD_VERSION=$(DEP=ubuntu make get-dependency-version)" >> $GITHUB_OUTPUT make update-ubuntu-version - echo "NEW_VERSION=$(DEP=ubuntu make get-dependency-version)" >> $GITHUB_OUTPUT - # 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 + c=$(git status --porcelain) + c="${c//$'\n'/'%0A'}" + c="${c//$'\r'/'%0D'}" echo "changes<> $GITHUB_OUTPUT - echo "$(git status --porcelain)" >> $GITHUB_OUTPUT + echo "$c" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - name: Create PR if: ${{ steps.bumpUbuntu.outputs.changes != '' }} uses: peter-evans/create-pull-request@5b4a9f6a9e2af26e5f02351490b90d01eb8ec1e5 with: token: ${{ secrets.MINIKUBE_BOT_PAT }} - commit-message: 'Site: Update ubuntu from ${{ steps.bumpUbuntu.outputs.OLD_VERSION }} to ${{ steps.bumpUbuntu.outputs.NEW_VERSION }}' + commit-message: update ubuntu:focal image version committer: minikube-bot author: minikube-bot branch: auto_bump_ubuntu_version push-to-fork: minikube-bot/minikube base: master delete-branch: true - title: 'Site: Update ubuntu from ${{ steps.bumpUbuntu.outputs.OLD_VERSION }} to ${{ steps.bumpUbuntu.outputs.NEW_VERSION }}' + title: 'Bump ubuntu:focal image version' body: | - The ubuntu:focal image released a new version new version + The ubuntu:focal image released a new version This PR was auto-generated by `make update-ubuntu-version` using [update-ubuntu-version.yml](https://github.com/kubernetes/minikube/tree/master/.github/workflows/update-ubuntu-version.yml) CI Workflow. From a804d16b98373677fc75d497bf651b4813e7ed14 Mon Sep 17 00:00:00 2001 From: salasberryfin Date: Wed, 3 May 2023 17:43:09 +0200 Subject: [PATCH 4/4] Fix: apply suggested changes --- .github/workflows/update-ubuntu-version.yml | 13 ++++++++++++- hack/update/ubuntu_version/update_ubuntu_version.go | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-ubuntu-version.yml b/.github/workflows/update-ubuntu-version.yml index 7fca918610..cb4f10fe9f 100644 --- a/.github/workflows/update-ubuntu-version.yml +++ b/.github/workflows/update-ubuntu-version.yml @@ -30,6 +30,7 @@ jobs: echo "$c" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - name: Create PR + id: createPR if: ${{ steps.bumpUbuntu.outputs.changes != '' }} uses: peter-evans/create-pull-request@5b4a9f6a9e2af26e5f02351490b90d01eb8ec1e5 with: @@ -41,8 +42,18 @@ jobs: push-to-fork: minikube-bot/minikube base: master delete-branch: true - title: 'Bump ubuntu:focal image version' + title: 'Kicbase: Bump ubuntu:focal image version' body: | The ubuntu:focal image released a new version This PR was auto-generated by `make update-ubuntu-version` using [update-ubuntu-version.yml](https://github.com/kubernetes/minikube/tree/master/.github/workflows/update-ubuntu-version.yml) CI Workflow. + - uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 + with: + github-token: ${{ secrets.MINIKUBE_BOT_PAT }} + script: | + github.rest.issues.createComment({ + issue_number: ${{ steps.createPR.outputs.pull-request-number }}, + owner: context.repo.owner, + repo: context.repo.repo, + body: 'ok-to-build-image' + }) diff --git a/hack/update/ubuntu_version/update_ubuntu_version.go b/hack/update/ubuntu_version/update_ubuntu_version.go index c7ef03839a..48768e88e0 100644 --- a/hack/update/ubuntu_version/update_ubuntu_version.go +++ b/hack/update/ubuntu_version/update_ubuntu_version.go @@ -82,7 +82,7 @@ func getLatestVersion() (string, error) { var content Response err = json.Unmarshal(body, &content) if err != nil { - return "", fmt.Errorf("unable to unmarshall response from Docker Hub: %v", err) + return "", fmt.Errorf("unable to unmarshal response from Docker Hub: %v", err) } for _, i := range content.Results {