Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to check and update builder base for new Golang version #1449

Merged
merged 11 commits into from
Jul 12, 2024
73 changes: 73 additions & 0 deletions builder-base/scripts/check_upstream_golang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/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}/../versions.yaml"
TAG_FILE="${SCRIPT_ROOT}/../../EKS_DISTRO_TAG_FILE.yaml"

function update::go::version {
local -r version=$1
local -r majorversion=$(if [[ $(echo "$version" | awk -F'.' '{print NF}') -ge 3 ]]; then echo ${version%.*}; else echo ${version%-*}; fi)

local -r cur_builder_base_version=$(cat "${VERSIONS_YAML}" | grep -E "^GOLANG_VERSION_${majorversion//./}")

gsed -i "s/${cur_builder_base_version}/GOLANG_VERSION_${majorversion//./}: ${version}-0/g" "${VERSIONS_YAML}"
}

function add::go::version {
local -r version=$1
local -r majorversion=$(if [[ $(echo "$version" | awk -F'.' '{print NF}') -ge 3 ]]; then echo ${version%.*}; else echo ${version%-*}; fi)

echo "GOLANG_VERSION_${majorversion//./}: $version-0" >>$VERSIONS_YAML
}

# Using YQ allows us to modify the existing tag or add the correct tag if it doesn't exist
function modify::go::minimal_image {
local -r version=$1
local -r majorversion=$(if [[ $(echo "$version" | awk -F'.' '{print NF}') -ge 3 ]]; then echo ${version%.*}; else echo ${version%-*}; fi)

# AL2 updates
AL2BASE=".al2.[\"eks-distro-minimal-base-golang-compiler-${majorversion}-base\"]" yq 'eval(strenv(AL2BASE)) = null' -i $TAG_FILE
AL2YUM=".al2.[\"eks-distro-minimal-base-golang-compiler-${majorversion}-yum\"]" yq 'eval(strenv(AL2YUM)) = null' -i $TAG_FILE
AL2GCC=".al2.[\"eks-distro-minimal-base-golang-compiler-${majorversion}-gcc\"]" yq 'eval(strenv(AL2GCC)) = null' -i $TAG_FILE

# AL2023 updates
AL2023BASE=".al2023.[\"eks-distro-minimal-base-golang-compiler-${majorversion}-base\"]" yq 'eval(strenv(AL2023BASE)) = null' -i $TAG_FILE
AL2023YUM=".al2023.[\"eks-distro-minimal-base-golang-compiler-${majorversion}-yum\"]" yq 'eval(strenv(AL2023YUM)) = null' -i $TAG_FILE
AL2023GCC=".al2023.[\"eks-distro-minimal-base-golang-compiler-${majorversion}-gcc\"]" yq 'eval(strenv(AL2023GCC)) = null' -i $TAG_FILE
}

# 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)
BUILDER_BASE_GO_VERSION=$(cat "${VERSIONS_YAML}" | grep -E "^GOLANG_VERSION_${MAJORVERSION//./}") || ""
# 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 [[ -n $BUILDER_BASE_GO_VERSION && ! $BUILDER_BASE_GO_VERSION =~ $version ]]; then
update::go::version $version
modify::go::minimal_image $version
elif [[ -z $BUILDER_BASE_GO_VERSION ]]; then
add::go::version $version
modify::go::minimal_image $version
fi
done
14 changes: 7 additions & 7 deletions eks-distro-base/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
$(foreach ver,$(BASE_GOLANG_VARIANT_VERSIONS),$(eval $(eval GOLANG_$(ver)_FULL_VERSION=$(shell yq ".golang.versions.[\"GOLANG_$(ver)_FULL_VERSION\"]" $(MAKE_ROOT)/golang_versions.yaml))))
endef
# ************************************************************

############# WINDOWS #############################
Expand Down Expand Up @@ -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))

# ************************************************************
Expand Down
13 changes: 13 additions & 0 deletions eks-distro-base/golang_versions.yaml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions eks-distro-base/scripts/check_upstream_golang
Original file line number Diff line number Diff line change
@@ -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
Loading