-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: build multi-architecture images in by default
This feature utilizes cross-compiling to generate binary files for the amd64, s390x and arm64 architectures, followed by the creation of images. Signed-off-by: Nestor Acuna-Blanco <nestor.acuna@ibm.com>
- Loading branch information
1 parent
1ca631d
commit 52a0b1c
Showing
2 changed files
with
29 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,43 @@ | ||
FROM registry.access.redhat.com/ubi8/ubi-minimal as builder | ||
|
||
# create enviroment variables and files | ||
ENV ENVFILE=/tmp/envfile | ||
RUN echo "export ARCH=`uname -m | sed 's/x86_64/amd64/'`" >> ${ENVFILE} | ||
ENV PATH=$PATH:/usr/local/go/bin | ||
ARG TARGET_ARCH=amd64 | ||
FROM registry.access.redhat.com/ubi8/ubi-minimal as base | ||
ARG TARGET_ARCH | ||
|
||
# download packages | ||
RUN microdnf install -y make tar gzip which && microdnf clean all | ||
RUN export ARCH=$(uname -m | sed 's/x86_64/amd64/'); curl -L https://go.dev/dl/go1.21.6.linux-${ARCH}.tar.gz | tar -C /usr/local -xzf - | ||
|
||
|
||
FROM base as builder | ||
|
||
RUN . ${ENVFILE}; curl -L https://go.dev/dl/go1.21.6.linux-${ARCH}.tar.gz | tar -C /usr/local -xzf - | ||
# in multistage builds the ARG must be renewed | ||
ARG TARGET_ARCH | ||
|
||
# create enviroment variables | ||
ENV PATH=$PATH:/usr/local/go/bin | ||
|
||
# copy the Go Modules manifests and vendor directory | ||
WORKDIR /workspace | ||
# Copy the Go Modules manifests and vendor directory | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
COPY vendor/ vendor/ | ||
|
||
# Copy the go source | ||
# copy the go source | ||
COPY Makefile Makefile | ||
COPY main.go main.go | ||
COPY api/ api/ | ||
COPY pkg/ pkg/ | ||
|
||
# Build | ||
RUN . ${ENVFILE}; CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} GO111MODULE=on make build | ||
# compile for the TARGET_ARCH | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGET_ARCH} GO111MODULE=on make build | ||
|
||
|
||
FROM registry.access.redhat.com/ubi8/ubi-minimal | ||
FROM --platform=linux/${TARGET_ARCH} registry.access.redhat.com/ubi8/ubi-micro | ||
|
||
RUN microdnf update -y && microdnf clean all | ||
# in multistage builds the ARG must be renewed | ||
ARG TARGET_ARCH | ||
|
||
# copy binary from builder image | ||
WORKDIR / | ||
COPY --from=builder /workspace/bin/console . | ||
USER 1000 | ||
|
||
ENTRYPOINT ["/console"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters