Skip to content

Commit

Permalink
Prefer UBI and go download over library/golang
Browse files Browse the repository at this point in the history
- speed up build since there is less to download
- reduce external dependencies
- build and run on the same base image

REPOSITORY                TAG  IMAGE ID     CREATED         SIZE
my                        test 422e3c099772 10 seconds ago  366 MB
docker.io/library/golang  1.23 361d8b5c9aa5 3 weeks ago     862 MB
  • Loading branch information
bdunne committed Oct 1, 2024
1 parent 4765846 commit 104905d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 9 additions & 2 deletions manageiq-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Build the manager binary
FROM docker.io/library/golang:1.23 as builder
FROM registry.access.redhat.com/ubi9/ubi-minimal as builder

RUN microdnf -y install gzip tar && \
curl -f -L https://go.dev/dl/go1.23.1.linux-amd64.tar.gz | 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 +19,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

0 comments on commit 104905d

Please sign in to comment.