Skip to content

Commit

Permalink
Refactor: refactor vela-prism dockerfile for arm arch
Browse files Browse the repository at this point in the history
Signed-off-by: Yin Da <[email protected]>
  • Loading branch information
Somefive committed Jun 6, 2023
1 parent c12eae9 commit 88d2306
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ jobs:
with:
images: |
oamdev/vela-prism
ghcr.io/oam-dev/vela-prism
ghcr.io/kubevela/oamdev/vela-prism
tags: |
type=ref,event=branch
type=ref,event=tag
type=raw,value=latest,enable={{is_default_branch}}
- name: Login docker.io
Expand Down
36 changes: 13 additions & 23 deletions cmd/apiserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
ARG BASE_IMAGE
# Build the manager binary
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.19-alpine as builder
ARG GOPROXY
ENV GOPROXY=${GOPROXY:-https://goproxy.cn}
FROM golang:1.19-alpine as builder
ARG OS
ARG ARCH

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand All @@ -15,31 +16,20 @@ RUN go mod download
COPY cmd/apiserver/main.go cmd/apiserver/main.go
COPY pkg/ pkg/

# Build
ARG TARGETARCH

RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} \
go build -a -ldflags "-s -w" \
-o vela-prism-${TARGETARCH} cmd/apiserver/main.go

# Before copying the Go binary directly to the final image,
# add them to the intermdediate upx image
FROM gruebel/upx:latest as upx
ARG TARGETARCH
COPY --from=builder /workspace/vela-prism-${TARGETARCH} /workspace/vela-prism-${TARGETARCH}
# Compress the binary and copy it to final image
RUN upx --best --lzma -o /workspace/vela-prism-${TARGETARCH}-upx /workspace/vela-prism-${TARGETARCH}
RUN CGO_ENABLED=0 \
GOOS=${OS} \
GOARCH=${ARCH} \
go build \
-a -ldflags "-s -w" \
-o vela-prism \
cmd/apiserver/main.go

# Overwrite `BASE_IMAGE` by passing `--build-arg=BASE_IMAGE=gcr.io/distroless/static:nonroot`

FROM ${BASE_IMAGE:-alpine:3.15}
FROM alpine:3.17
# This is required by daemon connnecting with cri
RUN apk add --no-cache ca-certificates bash expat
RUN apk add curl

WORKDIR /

ARG TARGETARCH
COPY --from=upx /workspace/vela-prism-${TARGETARCH}-upx /usr/local/bin/vela-prism
COPY --from=builder /workspace/vela-prism /usr/local/bin/vela-prism

CMD ["vela-prism"]

0 comments on commit 88d2306

Please sign in to comment.