Skip to content

Commit

Permalink
Build container using x.y.z golang version
Browse files Browse the repository at this point in the history
Won't work on older versions due to a change in toolchain and 'must match format 1.23' error
  • Loading branch information
razo7 committed Mar 14, 2024
1 parent 0038a4b commit 4b455d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
21 changes: 4 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
# Build the manager binary
FROM quay.io/centos/centos:stream8 AS builder
RUN dnf install -y golang jq git \
&& dnf clean all -y

WORKDIR /workspace
# Copy the Go Modules manifests for detecting Go version
COPY go.mod go.mod
COPY go.sum go.sum

RUN \
# get Go version from mod file
export GO_VERSION=$(grep -E "go [[:digit:]]\.[[:digit:]][[:digit:]]" go.mod | awk '{print $2}') && \
echo ${GO_VERSION} && \
# find filename for latest z version from Go download page
export GO_FILENAME=$(curl -sL 'https://go.dev/dl/?mode=json&include=all' | jq -r "[.[] | select(.version | startswith(\"go${GO_VERSION}\"))][0].files[] | select(.os == \"linux\" and .arch == \"amd64\") | .filename") && \
echo ${GO_FILENAME} && \
# download and unpack
curl -sL -o go.tar.gz "https://golang.org/dl/${GO_FILENAME}" && \
tar -C /usr/local -xzf go.tar.gz && \
rm go.tar.gz

# add Go directory to PATH
ENV PATH="${PATH}:/usr/local/go/bin"
RUN go version
# Install Golang based on the version from go.mod
RUN GO_VERSION=$(grep -E "go [[:digit:]]\.[[:digit:]][[:digit:]]" go.mod | awk '{print $2}') \
&& dnf install golang-${GO_VERSION} git -y && go version \
&& dnf clean all -y

# Copy the go source
COPY main.go main.go
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/medik8s/fence-agents-remediation

go 1.20
go 1.21.7

require (
github.com/go-logr/logr v1.4.1
Expand Down

0 comments on commit 4b455d4

Please sign in to comment.