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

Prefer UBI and go download over library/golang #1173

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions manageiq-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Build the manager binary
FROM docker.io/library/golang:1.23 as builder
FROM registry.access.redhat.com/ubi9/ubi-minimal as builder

COPY go.mod /go.mod
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used to detect the desired Go major.minor version, but could be changed to an ENV var if we want to extract this to a script for reuse.

Fryguy marked this conversation as resolved.
Show resolved Hide resolved

RUN microdnf -y install gzip jq tar && \
arch=$(uname -m | sed 's/x86_64/amd64/') && \
goversion=$(sed -nr 's/^go\s+(.*)/go\1/p' /go.mod) && \
file=$(curl -s 'https://go.dev/dl/?mode=json&include=all' | jq -r --arg GOVERSION "${goversion}" --arg ARCH "${arch}" 'first(.[] | select(.version | startswith($GOVERSION))).files[] | select(.arch == $ARCH and .os == "linux").filename') && \
curl -s -f -L https://go.dev/dl/${file} | tar -C / -xzf -

ENV PATH=/go/bin:/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -14,9 +24,11 @@ COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/

# Build
# Build go executable
RUN CGO_ENABLED=0 go build -a -o manager cmd/main.go


# Build operator image
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest

LABEL name="ManageIQ Operator" \
Expand Down
8 changes: 3 additions & 5 deletions spec/manageiq-operator/go_version_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
describe "Go Version" do
it "matches go.mod" do
require 'awesome_spawn'
dockerfile_version = File.read(ROOT.join("manageiq-operator", "Dockerfile")).match(/^FROM.+golang:(\d+\.\d+).+/)[1]
mod_version = File.read(ROOT.join("manageiq-operator", "go.mod")).match(/^go\s(\d+\.\d+)/)[1]
running_version = AwesomeSpawn.run!("go version", :chdir => ROOT.join("manageiq-operator")).output.match(/.*\sgo(\d+\.\d+).*/)[1]
mod_version = File.read(ROOT.join("manageiq-operator", "go.mod")).match(/^go\s(\d+\.\d+)/)[1]
running_version = AwesomeSpawn.run!("go version", :chdir => ROOT.join("manageiq-operator")).output.match(/.*\sgo(\d+\.\d+).*/)[1]

expect(dockerfile_version).to eq(mod_version)
expect(running_version).to eq(mod_version)
expect(running_version).to eq(mod_version)
end
end
Loading