From 1a96f3ee57aab7a64e59de129c100760635e2522 Mon Sep 17 00:00:00 2001 From: Cameron Rozean Date: Thu, 11 Jul 2024 12:59:57 -0700 Subject: [PATCH] move golang versions to yaml, use yaml in Makefile, autoupdate yaml with upstream new versions --- eks-distro-base/Makefile | 14 +++--- eks-distro-base/golang_versions.yaml | 13 +++++ eks-distro-base/scripts/check_upstream_golang | 50 +++++++++++++++++++ 3 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 eks-distro-base/golang_versions.yaml create mode 100755 eks-distro-base/scripts/check_upstream_golang diff --git a/eks-distro-base/Makefile b/eks-distro-base/Makefile index bba360299..3d5734734 100644 --- a/eks-distro-base/Makefile +++ b/eks-distro-base/Makefile @@ -205,15 +205,14 @@ BASE_NODEJS_COMPILER_VARIANT_VERSIONS=$(foreach ver,$(BASE_COMPILER_VARIANT_VERS # ****************** GOLANG VARIANTS ************************* GOLANG_VARIANT_NAME=eks-distro-minimal-base-golang-compiler -BASE_GOLANG_VARIANT_VERSIONS=1.18 1.19 1.20 1.21 1.22 - -GOLANG_1.18_FULL_VERSION=1.18.10-8 -GOLANG_1.19_FULL_VERSION=1.19.13-14 -GOLANG_1.20_FULL_VERSION=1.20.14-16 -GOLANG_1.21_FULL_VERSION=1.21.12-0 -GOLANG_1.22_FULL_VERSION=1.22.5-0 +# This recreates the list of golang versions separated with ' ' from the golang_versions.yaml using xargs to strip the trailing whitespace. +BASE_GOLANG_VARIANT_VERSIONS=$(shell yq '.golang.variants | to_entries | .[] | .value' golang_versions.yaml | tr '\n' ' ' | xargs) BASE_GOLANG_COMPILER_VARIANT_VERSIONS=$(foreach ver,$(BASE_GOLANG_VARIANT_VERSIONS),$(addprefix $(ver)-,$(BASE_COMPILER_VARIANT_VERSIONS))) + +define SET_GOLANG_FULL_VERSIONS + $(shell yq '.golang.versions | to_entries | .[] | [.key,.value] | join("=")' $MAKE_ROOT/golang_versions.yaml) +endef # ************************************************************ ############# WINDOWS ############################# @@ -556,6 +555,7 @@ $(eval $(call COMPILER_TARGET_OVERRIDES,nodejs,false)) # ************************************************************ # ****************** GOLANG VARIANTS ************************ +$(eval $(call SET_GOLANG_FULL_VERSIONS)) $(eval $(call COMPILER_TARGET_OVERRIDES,golang,true)) # ************************************************************ diff --git a/eks-distro-base/golang_versions.yaml b/eks-distro-base/golang_versions.yaml new file mode 100644 index 000000000..7eb9213d5 --- /dev/null +++ b/eks-distro-base/golang_versions.yaml @@ -0,0 +1,13 @@ +golang: + variants: + - 1.18 + - 1.19 + - 1.20 + - 1.21 + - 1.22 + versions: + GOLANG_1.18_FULL_VERSION: 1.18.10-8 + GOLANG_1.19_FULL_VERSION: 1.19.13-14 + GOLANG_1.20_FULL_VERSION: 1.20.14-16 + GOLANG_1.21_FULL_VERSION: 1.21.12-0 + GOLANG_1.22_FULL_VERSION: 1.22.5-0 diff --git a/eks-distro-base/scripts/check_upstream_golang b/eks-distro-base/scripts/check_upstream_golang new file mode 100755 index 000000000..a9782b94d --- /dev/null +++ b/eks-distro-base/scripts/check_upstream_golang @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# Copyright Amazon.com Inc. or its affiliates. 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. + +set -e +set -o pipefail +set -x + +GO_PREFIX="go" +SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" +VERSIONS_YAML="${SCRIPT_ROOT}/../golang_versions.yaml" + +# Using YQ allows us to modify the existing tag or add the correct tag if it doesn't exist +function update::go::version { + local -r version=$1 + local -r minorversion=$(if [[ $(echo "$version" | awk -F'.' '{print NF}') -ge 3 ]]; then echo ${version%.*}; else echo ${version%-*}; fi) + + # Check if minor verion exists, if not add. + if [[ -z $(MINORVERSION=$minorversion yq 'eval(.golang.variants[] | select(. == env(MINORVERSION)))' $VERSIONS_YAML) ]]; then + MINORVERSION=$minorversion yq '.golang.variants += env(MINORVERSION)' -i $VERSIONS_YAML + fi + + # Patch Version update if needed + UPDATE=".golang.versions.[\"GOLANG_${minorversion}_FULL_VERSION\"]" VERSION="$version-0" yq 'eval(strenv(UPDATE)) = strenv(VERSION)' -i $VERSIONS_YAML +} + +# curl go.dev for the supported versions of go +ACTIVE_VERSIONS=$(curl https://go.dev/dl/?mode=json | jq -r '.[].version' | sed -e "s/^$GO_PREFIX//" | sort) + +for version in ${ACTIVE_VERSIONS}; do + # pull golang versions in the versions.yaml + MAJORVERSION=$(if [[ $(echo "$version" | awk -F'.' '{print NF}') -ge 3 ]]; then echo ${version%.*}; else echo ${version%-*}; fi) + MINIMAL_GO_VERSION=$(cat "${VERSIONS_YAML}" | grep -E "^GOLANG_${MAJORVERSION}_FULL_VERSION") || "" + # check builder-base versions for the upstream version of golang + # if the version doesn't exist in the builder base update the versions yaml. + if [[ ! $MINIMAL_GO_VERSION =~ $version ]]; then + update::go::version $version + fi +done