Skip to content

Commit

Permalink
Merge pull request #31 from Xelon-AG/chore/dockerfile-optimization
Browse files Browse the repository at this point in the history
chore(docker): use multi-stage build approach
  • Loading branch information
pavel-github authored Jun 5, 2024
2 parents c007cec + 09f995d commit b671f27
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 43 deletions.
12 changes: 7 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Ignore everything
**

## Except build folder
!/build/**
.github/
build/
deploy/
test/
tools/
README.md
.golangci.yaml
60 changes: 22 additions & 38 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
# syntax=docker/dockerfile:1
FROM alpine:3.19
FROM golang:1.22 AS builder

ENV CGO_ENABLED=0

# copy manifest files only to cache layer with dependencies
WORKDIR /src/app/
COPY go.mod go.sum /src/app/
RUN go mod download
# copy source code
COPY cmd/ cmd/
COPY internal/ internal/

# build
RUN go build -o xelon-csi -ldflags="-s -w" -trimpath cmd/xelon-csi/main.go



FROM alpine:3.20 AS production

ARG VERSION

LABEL org.opencontainers.image.ref.name="xelon-csi" \
LABEL org.opencontainers.image.licenses="Apache-2.0" \
org.opencontainers.image.ref.name="xelon-csi" \
org.opencontainers.image.source="https://github.com/Xelon-AG/xelon-csi" \
org.opencontainers.image.vendor="Xelon AG" \
org.opencontainers.image.version="${VERSION:-local}"
Expand All @@ -20,40 +38,6 @@ RUN <<EOF
rm -rf /var/cache/apk/*
EOF

COPY --chmod=755 xelon-csi /bin/xelon-csi
COPY --from=builder --chmod=755 /src/app/xelon-csi /xelon-csi

ENTRYPOINT ["/bin/xelon-csi"]

# syntax=docker/dockerfile:1
#FROM golang:1.22 AS builder
#
#ENV CGO_ENABLED=0
#
## copy manifest files only to cache layer with dependencies
#WORKDIR /src/app/
#COPY go.mod go.sum /src/app/
#RUN go mod download
## copy source code
#COPY cmd/ cmd/
#COPY internal/ internal/
#
## build
#RUN go build -o xelon-cloud-controller-manager -ldflags="-s -w" -trimpath cmd/xelon-cloud-controller-manager/main.go
#
#
#
#FROM alpine:3.19 AS production
#
#ARG VERSION
#
#LABEL org.opencontainers.image.ref.name="xelon-csi" \
# org.opencontainers.image.source="https://github.com/Xelon-AG/xelon-csi" \
# org.opencontainers.image.vendor="Xelon AG" \
# org.opencontainers.image.version="${VERSION:-local}"
#
#WORKDIR /
#USER 65532:65532
#
#COPY --from=builder --chmod=755 /src/app/xelon-cloud-controller-manager /xelon-cloud-controller-manager
#
#ENTRYPOINT ["/xelon-cloud-controller-manager"]
ENTRYPOINT ["/xelon-csi"]

0 comments on commit b671f27

Please sign in to comment.