Skip to content

Commit

Permalink
ci: release archives of docker-runx
Browse files Browse the repository at this point in the history
Signed-off-by: Yves Brissaud <[email protected]>
  • Loading branch information
eunomie committed Oct 10, 2024
1 parent cbdfb63 commit aeba122
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
uses: softprops/action-gh-release@v1
with:
files: |
dist/*/docker-runx-*
dist/docker-runx-*
20 changes: 16 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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-) && \
Expand All @@ -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 /
2 changes: 1 addition & 1 deletion Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit aeba122

Please sign in to comment.