Skip to content

Commit

Permalink
chore(release): adjust Dockerfile for goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
Zebradil committed Dec 25, 2023
1 parent 2574a32 commit 0334beb
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 41 deletions.
74 changes: 33 additions & 41 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,56 +1,45 @@
# Stage 1 Build myks
FROM --platform=$BUILDPLATFORM golang:1.21 AS builder
ARG TARGETOS
ARG TARGETARCH
WORKDIR /app

COPY . .

RUN go mod download \
&& go mod verify

RUN CGO_ENABLED=0 \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -o myks main.go


# Stage 2 Download tools
FROM --platform=$BUILDPLATFORM debian:bookworm AS download-tools

ARG TARGETOS
ARG TARGETARCH
# renovate: datasource=github-releases depName=helm/helm
ARG HELM_VERSION=v3.13.3
# renovate: datasource=github-releases depName=carvel-dev/vendir
ARG VENDIR_VERSION=v0.38.0
# renovate: datasource=github-releases depName=carvel-dev/ytt
ARG YTT_VERSION=v0.46.3

FROM --platform=$BUILDPLATFORM debian:bookworm-slim AS downloader
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
WORKDIR /tools
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
ca-certificates \
curl \
unzip

WORKDIR /tools
unzip \
&& rm -rf /var/lib/apt/lists/*

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

FROM downloader AS helm
ARG TARGETOS
ARG TARGETARCH
# renovate: datasource=github-releases depName=helm/helm
ARG HELM_VERSION=v3.13.3
RUN curl -fsSL \
https://get.helm.sh/helm-v${HELM_VERSION}-${TARGETOS}-${TARGETARCH}.tar.gz \
https://get.helm.sh/helm-${HELM_VERSION}-${TARGETOS}-${TARGETARCH}.tar.gz \
| tar -xzf - --strip-components=1 ${TARGETOS}-${TARGETARCH}/helm


FROM downloader AS vendir
ARG TARGETOS
ARG TARGETARCH
# renovate: datasource=github-releases depName=carvel-dev/vendir
ARG VENDIR_VERSION=v0.38.0
RUN curl -fsSL \
https://github.com/vmware-tanzu/carvel-vendir/releases/download/v${VENDIR_VERSION}/vendir-${TARGETOS}-${TARGETARCH} \
https://github.com/carvel-dev/vendir/releases/download/${VENDIR_VERSION}/vendir-${TARGETOS}-${TARGETARCH} \
> vendir


FROM downloader AS ytt
ARG TARGETOS
ARG TARGETARCH
# renovate: datasource=github-releases depName=carvel-dev/ytt
ARG YTT_VERSION=v0.46.3
RUN curl -fsSL \
https://github.com/vmware-tanzu/carvel-ytt/releases/download/v${YTT_VERSION}/ytt-${TARGETOS}-${TARGETARCH} \
https://github.com/carvel-dev/ytt/releases/download/${YTT_VERSION}/ytt-${TARGETOS}-${TARGETARCH} \
> ytt
RUN chmod +x *


# Stage 3: Bring it all together
FROM --platform=$BUILDPLATFORM debian:bookworm

WORKDIR /app
FROM --platform=$BUILDPLATFORM debian:bookworm-slim

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
Expand All @@ -61,8 +50,11 @@ RUN apt-get update \
tini \
&& rm -rf /var/lib/apt/lists/*

COPY --from=download-tools /tools/* /usr/local/bin/
COPY --from=builder /app/myks /usr/local/bin/
COPY --link --chmod=700 --from=helm /tools/helm /usr/local/bin/
COPY --link --chmod=700 --from=vendir /tools/vendir /usr/local/bin/
COPY --link --chmod=700 --from=ytt /tools/ytt /usr/local/bin/
# This copies myks binary built by goreleaser
COPY --link myks /usr/local/bin/

WORKDIR /app

Expand Down
69 changes: 69 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Stage 1 Build myks
FROM --platform=$BUILDPLATFORM golang:1.21 AS builder
ARG TARGETOS
ARG TARGETARCH
WORKDIR /app

COPY . .

RUN go mod download \
&& go mod verify

RUN CGO_ENABLED=0 \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -o myks main.go


# Stage 2 Download tools
FROM --platform=$BUILDPLATFORM debian:bookworm AS download-tools

ARG TARGETOS
ARG TARGETARCH
# renovate: datasource=github-releases depName=helm/helm
ARG HELM_VERSION=v3.13.3
# renovate: datasource=github-releases depName=carvel-dev/vendir
ARG VENDIR_VERSION=v0.38.0
# renovate: datasource=github-releases depName=carvel-dev/ytt
ARG YTT_VERSION=v0.46.3

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
ca-certificates \
curl \
unzip

WORKDIR /tools

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN curl -fsSL \
https://get.helm.sh/helm-v${HELM_VERSION}-${TARGETOS}-${TARGETARCH}.tar.gz \
| tar -xzf - --strip-components=1 ${TARGETOS}-${TARGETARCH}/helm
RUN curl -fsSL \
https://github.com/vmware-tanzu/carvel-vendir/releases/download/v${VENDIR_VERSION}/vendir-${TARGETOS}-${TARGETARCH} \
> vendir
RUN curl -fsSL \
https://github.com/vmware-tanzu/carvel-ytt/releases/download/v${YTT_VERSION}/ytt-${TARGETOS}-${TARGETARCH} \
> ytt
RUN chmod +x *


# Stage 3: Bring it all together
FROM --platform=$BUILDPLATFORM debian:bookworm

WORKDIR /app

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
ca-certificates \
git \
gnupg2 \
ssh \
tini \
&& rm -rf /var/lib/apt/lists/*

COPY --from=download-tools /tools/* /usr/local/bin/
COPY --from=builder /app/myks /usr/local/bin/

WORKDIR /app

ENTRYPOINT ["tini", "--", "myks"]

0 comments on commit 0334beb

Please sign in to comment.