From d10447c8af0286a2af80fe5179262cbbe6a5df1e Mon Sep 17 00:00:00 2001 From: Thibault NORMAND Date: Wed, 12 Jan 2022 12:00:06 +0100 Subject: [PATCH] chore(ci): updtae goboring to 1.17.5 --- .github/workflows/docker-tools.yml | 30 +++++++-------- build/mage/docker/build.go | 14 ------- build/mage/docker/const.go | 7 ++-- build/mage/docker/release.go | 15 +------- build/mage/docker/tools.go | 61 +++++++++++++++++++----------- 5 files changed, 58 insertions(+), 69 deletions(-) diff --git a/.github/workflows/docker-tools.yml b/.github/workflows/docker-tools.yml index 80927119..3e4c5b80 100644 --- a/.github/workflows/docker-tools.yml +++ b/.github/workflows/docker-tools.yml @@ -3,16 +3,7 @@ name: Build and push docker tools env: REGISTRY: ghcr.io -on: - push: - branches: - - main - paths: - - 'build/**' - - 'tools/**' - - '.github/workflows/docker-tools.yml' - release: - types: [published] +on: workflow_dispatch jobs: build-push: @@ -26,12 +17,14 @@ jobs: matrix: include: # normal - - golang-image: "golang" - golang-version: "1.17" + - golang-image: "golang:1.17" + golang-version: "1.17.5" + goboring-version: "" tools-image: harp-tools # fips - - golang-image: "goboring/golang" - golang-version: "1.16.7b7" + - golang-image: "goboring/golang:1.16.7b7" + golang-version: "1.17.5" + goboring-version: "1.17.5b7" tools-image: harp-tools-fips steps: - @@ -65,11 +58,13 @@ jobs: echo "DOCKERFILE_ONLY=1" >> $GITHUB_ENV echo "GOLANG_IMAGE=$GOLANG_IMAGE" >> $GITHUB_ENV echo "GOLANG_VERSION=$GOLANG_VERSION" >> $GITHUB_ENV + echo "GOBORING_VERSION=$GOBORING_VERSION" >> $GITHUB_ENV echo "DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME" >> $GITHUB_ENV env: DOCKERFILE_ONLY: 1 GOLANG_IMAGE: ${{ matrix.golang-image }} GOLANG_VERSION: ${{ matrix.golang-version }} + GOBORING_VERSION: ${{ matrix.goboring-version }} DOCKER_IMAGE_NAME: ${{ matrix.tools-image }} - name: Generate Dockerfile @@ -96,7 +91,7 @@ jobs: tags: | ghcr.io/elastic/harp/${{ matrix.tools-image }}:latest cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new build-args: | GOLANG_IMAGE=${{ matrix.golang-image }} GOLANG_VERSION=${{ matrix.golang-version }} @@ -124,3 +119,8 @@ jobs: env: COSIGN_KEY: ${{ secrets.COSIGN_KEY }} COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }} + - + name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/build/mage/docker/build.go b/build/mage/docker/build.go index ee610152..079dfbd3 100644 --- a/build/mage/docker/build.go +++ b/build/mage/docker/build.go @@ -41,8 +41,6 @@ ARG VCS_REF={{.VcsRef}} # Builder arguments ARG TOOLS_IMAGE={{.ToolImageName}} -ARG GOLANG_IMAGE={{.GolangImage}} -ARG GOLANG_VERSION={{.GolangVersion}} FROM $TOOLS_IMAGE as compiler @@ -125,16 +123,6 @@ func Build(cmd *artifact.Command) func() error { return func() error { mg.Deps(git.CollectInfo) - // Retrieve golang attributes - golangImage := golangImage - if os.Getenv("GOLANG_IMAGE") != "" { - golangImage = os.Getenv("GOLANG_IMAGE") - } - golangVersion := golangVersion - if os.Getenv("GOLANG_VERSION") != "" { - golangVersion = os.Getenv("GOLANG_VERSION") - } - // Docker image name toolImageName := toolImage if os.Getenv("TOOL_IMAGE_NAME") != "" { @@ -146,8 +134,6 @@ func Build(cmd *artifact.Command) func() error { "BuildDate": time.Now().Format(time.RFC3339), "Version": git.Tag, "VcsRef": git.Revision, - "GolangImage": golangImage, - "GolangVersion": golangVersion, "Cmd": cmd, }) if err != nil { diff --git a/build/mage/docker/const.go b/build/mage/docker/const.go index 0563fde4..d5cec1d7 100644 --- a/build/mage/docker/const.go +++ b/build/mage/docker/const.go @@ -19,7 +19,8 @@ package docker const ( // Standard build mode - golangImage = "golang" - golangVersion = "1.17" - toolImage = "elastic/harp-tools:latest" + golangImage = "golang:1.17" + golangVersion = "1.17.5" + goBoringVersion = "1.17.5b7" + toolImage = "elastic/harp-tools:latest" ) diff --git a/build/mage/docker/release.go b/build/mage/docker/release.go index 6a955f34..f5d7d1b9 100644 --- a/build/mage/docker/release.go +++ b/build/mage/docker/release.go @@ -44,8 +44,6 @@ ARG VCS_REF={{.VcsRef}} # Builder arguments ARG TOOLS_IMAGE={{.ToolImageName}} -ARG GOLANG_IMAGE={{.GolangImage}} -ARG GOLANG_VERSION={{.GolangVersion}} ARG RELEASE={{.Release}} FROM $TOOLS_IMAGE as compiler @@ -132,16 +130,6 @@ func Release(cmd *artifact.Command) func() error { return func() error { mg.Deps(git.CollectInfo) - // Retrieve golang attributes - golangImage := golangImage - if os.Getenv("GOLANG_IMAGE") != "" { - golangImage = os.Getenv("GOLANG_IMAGE") - } - golangVersion := golangVersion - if os.Getenv("GOLANG_VERSION") != "" { - golangVersion = os.Getenv("GOLANG_VERSION") - } - // Docker image name toolImageName := toolImage if os.Getenv("TOOL_IMAGE_NAME") != "" { @@ -161,8 +149,6 @@ func Release(cmd *artifact.Command) func() error { "BuildDate": time.Now().Format(time.RFC3339), "Version": git.Tag, "VcsRef": git.Revision, - "GolangImage": golangImage, - "GolangVersion": golangVersion, "Cmd": cmd, "Release": release, }) @@ -176,6 +162,7 @@ func Release(cmd *artifact.Command) func() error { } // Prepare command + //nolint:gosec // Expected behavior c := exec.Command("docker", "build", "-t", fmt.Sprintf("elastic/%s:artifacts-%s", cmd.Kebab(), relVer.String()), "-f", "-", diff --git a/build/mage/docker/tools.go b/build/mage/docker/tools.go index 722d4f0d..48af7a1e 100644 --- a/build/mage/docker/tools.go +++ b/build/mage/docker/tools.go @@ -38,13 +38,13 @@ ARG BUILD_DATE={{.BuildDate}} ARG VERSION={{.Version}} ARG VCS_REF={{.VcsRef}} -# Builder argumentsgolang -ARG GOLANG_IMAGE={{.GolangImage}} +# Builder arguments +ARG GOLANG_BASE_IMAGE={{.GolangImage}} ARG GOLANG_VERSION={{.GolangVersion}} ## ------------------------------------------------------------------------------------------------- -FROM ${GOLANG_IMAGE}:${GOLANG_VERSION} +FROM ${GOLANG_BASE_IMAGE} # Arguments ARG BUILD_DATE={{.BuildDate}} @@ -57,14 +57,21 @@ ARG GOLANG_VERSION={{.GolangVersion}} LABEL \ org.opencontainers.image.created=$BUILD_DATE \ - org.opencontainers.image.title="Harp SDK Environment" \ - org.opencontainers.image.description="Harp SDK Tools used to build harp and all related tools" \ - org.opencontainers.image.url="https://github.com/elastic/harp" \ - org.opencontainers.image.source="https://github.com/elastic/harp.git" \ - org.opencontainers.image.revision=$VCS_REF \ - org.opencontainers.image.vendor="Elastic" \ - org.opencontainers.image.version=$VERSION \ - org.opencontainers.image.licences="ASL2" + org.opencontainers.image.title="Harp SDK Environment (Go {{.GolangVersion}})" \ + org.opencontainers.image.description="Harp SDK Tools used to build harp and all related tools" \ + org.opencontainers.image.url="https://github.com/elastic/harp" \ + org.opencontainers.image.source="https://github.com/elastic/harp.git" \ + org.opencontainers.image.revision=$VCS_REF \ + org.opencontainers.image.vendor="Elastic" \ + org.opencontainers.image.version=$VERSION \ + org.opencontainers.image.licences="ASL2" + +{{ if .OverrideGoBoringVersion }} +# Override goboring version +RUN wget https://storage.googleapis.com/go-boringcrypto/go{{ .GoBoringVersion }}.linux-amd64.tar.gz \ + && rm -rf /usr/local/go && tar -C /usr/local -xzf go{{ .GoBoringVersion }}.linux-amd64.tar.gz \ + rm go{{ .GoBoringVersion }}.linux-amd64.tar.gz +{{ end }} # hadolint ignore=DL3008 RUN set -eux; \ @@ -105,11 +112,11 @@ ENV USER golang # Clean go mod cache RUN set -eux; \ - go clean -modcache + go clean -modcache # Checkout mage RUN set -eux; \ - git clone https://github.com/magefile/mage .mage + git clone https://github.com/magefile/mage .mage # Go to tools WORKDIR $GOPATH/src/workspace/.mage @@ -128,7 +135,7 @@ WORKDIR $GOPATH/src/workspace/tools # Install tools RUN set -eux; \ - mage + mage # Set path for tools usages ENV PATH=$GOPATH/src/workspace/tools/bin:$PATH @@ -139,21 +146,29 @@ func Tools() error { mg.Deps(git.CollectInfo) // Retrieve golang attributes - golangImage := golangImage - if os.Getenv("GOLANG_IMAGE") != "" { - golangImage = os.Getenv("GOLANG_IMAGE") + golangBaseImage := golangImage + if os.Getenv("GOLANG_BASE_IMAGE") != "" { + golangBaseImage = os.Getenv("GOLANG_BASE_IMAGE") } golangVersion := golangVersion if os.Getenv("GOLANG_VERSION") != "" { golangVersion = os.Getenv("GOLANG_VERSION") } + goBoringVersion := goBoringVersion + overrideGoBoringVersion := false + if os.Getenv("GOBORING_VERSION") != "" { + goBoringVersion = os.Getenv("GOBORING_VERSION") + overrideGoBoringVersion = true + } - buf, err := merge(dockerToolTemplate, map[string]string{ - "BuildDate": time.Now().Format(time.RFC3339), - "Version": git.Tag, - "VcsRef": git.Revision, - "GolangImage": golangImage, - "GolangVersion": golangVersion, + buf, err := merge(dockerToolTemplate, map[string]interface{}{ + "BuildDate": time.Now().Format(time.RFC3339), + "Version": git.Tag, + "VcsRef": git.Revision, + "GolangImage": golangBaseImage, + "GolangVersion": golangVersion, + "OverrideGoBoringVersion": overrideGoBoringVersion, + "GoBoringVersion": goBoringVersion, }) if err != nil { return err