From aeba12234579b6631a16729096ef66fad6c66336 Mon Sep 17 00:00:00 2001 From: Yves Brissaud Date: Thu, 10 Oct 2024 18:58:09 +0200 Subject: [PATCH] ci: release archives of docker-runx Signed-off-by: Yves Brissaud --- .github/workflows/release.yml | 2 +- Dockerfile | 20 ++++++++++++++++---- Taskfile.yaml | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c3181e..07d1193 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,4 +38,4 @@ jobs: uses: softprops/action-gh-release@v1 with: files: | - dist/*/docker-runx-* \ No newline at end of file + dist/docker-runx-* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index acff615..865683f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS b COPY --from=xx / / RUN apk add --no-cache curl RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin -RUN apk add --no-cache git ca-certificates openssh-client +RUN apk add --no-cache git ca-certificates openssh-client zip FROM build-base AS build ARG TARGETPLATFORM @@ -27,8 +27,10 @@ RUN --mount=type=ssh \ COPY . ./ FROM build AS binary -ENV CGO_ENABLED=0 +ARG TARGETOS +ARG TARGETARCH ARG BIN_NAME +ENV CGO_ENABLED=0 RUN --mount=type=cache,target=/root/.cache \ --mount=type=cache,target=/go/pkg/mod \ GIT_VERSION=$(git describe --tags | cut -c 2-) && \ @@ -37,10 +39,20 @@ RUN --mount=type=cache,target=/root/.cache \ -ldflags="-w -s \ -X {{.PKG_NAME}}/internal/constants.Version=$GIT_VERSION" \ ./cmd/${BIN_NAME} && \ - xx-verify dist/${BIN_NAME} + xx-verify dist/${BIN_NAME} && \ +# on windows add the .exe extension and zip the binary \ + if [ "${TARGETOS}" = "windows" ]; then \ + mv dist/${BIN_NAME} dist/${BIN_NAME}.exe && \ + cd dist && zip ${BIN_NAME}-${TARGETOS}-${TARGETARCH}.zip ${BIN_NAME}.exe; \ + fi && \ +# if target os is not windows, tar and gzip the binary \ + if [ "${TARGETOS}" != "windows" ]; then \ + tar -C dist -czf dist/${BIN_NAME}-${TARGETOS}-${TARGETARCH}.tar.gz ${BIN_NAME}; \ + fi FROM scratch AS export-bin ARG BIN_NAME ARG TARGETOS ARG TARGETARCH -COPY --from=binary /go/src/dist/${BIN_NAME} /${BIN_NAME}-${TARGETOS}-${TARGETARCH} +COPY --from=binary /go/src/dist/*.zip / +COPY --from=binary /go/src/dist/*.tar.gz / diff --git a/Taskfile.yaml b/Taskfile.yaml index d815c5a..44efc2f 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -51,7 +51,7 @@ tasks: -f Dockerfile \ --platform {{.BIN_PLATFORMS}} \ --target export-bin \ - -o type=local,dest=dist \ + -o type=local,dest=dist,platform-split=false \ . go:fmt: