Skip to content

Commit

Permalink
fix: multiarch docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
adamtagscherer committed Jun 19, 2023
1 parent e86dcdc commit e10ce45
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ COPY ui .
RUN npm i
RUN npm run build

FROM --platform=$BUILDPLATFORM golang:1.20.5-alpine AS builder
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-alpine@sha256:fd9d9d7194ec40a9a6ae89fcaef3e47c47de7746dd5848ab5343695dbbd09f8c AS builder

COPY --from=xx / /

RUN apk add --update --no-cache git clang lld binutils-gold

ARG TARGETPLATFORM

RUN xx-apk add --update --no-cache musl-dev gcc

ENV CGO_ENABLED=1

# Copy vmclarity code to /build
COPY . /build
Expand All @@ -20,16 +30,14 @@ 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 \
-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-go build -ldflags="-s -w \
-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

Expand Down

0 comments on commit e10ce45

Please sign in to comment.