Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
fix: multiarch docker image (#423)
Browse files Browse the repository at this point in the history
* fix: multiarch docker image

* fix: remove binutils gold

* fix: add binutils gold to xx-apk

* fix: add binutils to xx-apk

* fix: remove binutils to xx-apk

* fix: try refactoring Dockerfile and see if CI runs successfully

* fix: add binutils-gold

* fix: add binutils-gold explicit version

* fix: add binutils-gold explicit version

* fix: add binutils-cross

* fix: add binutils with explicit version

* fix: bump build-push-action, remove cache

* fix: remove cache

* fix: add qemu to github actions

* fix: update github actions

* fix: switch to debian based builder platform

* fix: arrange Dockerfile.backend

* documentation: add comment

* refactor: move CGO to env, wrap go, remove mounts

* fix: pass static flag to external linker
  • Loading branch information
adamtagscherer authored Jun 22, 2023
1 parent 46d0c44 commit b71ab70
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ COPY ui .
RUN npm i
RUN npm run build

FROM --platform=$BUILDPLATFORM golang:1.20.5-alpine AS builder
# xx is a helper for cross-compilation
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.2.1@sha256:8879a398dedf0aadaacfbd332b29ff2f84bc39ae6d4e9c0a1109db27ac5ba012 AS xx

RUN apk add --update --no-cache gcc g++ git binutils-gold
FROM --platform=$BUILDPLATFORM golang:1.20.5-bullseye AS builder

COPY --from=xx / /

ARG TARGETPLATFORM

RUN apt-get update && xx-apt-get install -y --no-install-recommends gcc libc6-dev

RUN xx-go --wrap

# Copy vmclarity code to /build
COPY . /build
Expand All @@ -20,17 +29,16 @@ WORKDIR /build/backend
ARG VERSION
ARG BUILD_TIMESTAMP
ARG COMMIT_HASH
ARG TARGETOS
ARG TARGETARCH

RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -ldflags="-s -w \
ENV CGO_ENABLED=1

RUN go build -ldflags="-s -w -extldflags -static \
-X 'github.com/openclarity/vmclarity/backend/pkg/version.Version=${VERSION}' \
-X 'github.com/openclarity/vmclarity/backend/pkg/version.CommitHash=${COMMIT_HASH}' \
-X 'github.com/openclarity/vmclarity/backend/pkg/version.BuildTimestamp=${BUILD_TIMESTAMP}'" -o backend ./cmd/backend/main.go

RUN xx-verify backend

FROM alpine:3.18

WORKDIR /app
Expand Down

0 comments on commit b71ab70

Please sign in to comment.