Skip to content

Commit

Permalink
chore: update Dockerfile and GitHub Actions workflow to support confi…
Browse files Browse the repository at this point in the history
…gurable binary name

The Dockerfile has been updated to use the `BINARY_NAME` build argument to specify the name of the binary to be copied into the image. The `ENTRYPOINT` has also been updated to use the `BINARY_NAME` environment variable.

The GitHub Actions workflow has been updated to pass the `BINARY_NAME` environment variable as a build argument to the Docker build step.
  • Loading branch information
Mogyuchi committed Feb 9, 2024
1 parent 6fb6a8d commit c07a0db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
24 changes: 13 additions & 11 deletions .github/files/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
FROM --platform=$BUILDPLATFORM busybox:1.36.1-uclibc@sha256:cc71f45a5a48738c4c295314b2bc9bcc18eb0c33e7bb127c3735b751b724141b AS env
ARG TARGETPLATFORM
RUN --mount=type=bind,source=artifact,target=artifact \
if [ "$TARGETPLATFORM" = 'darwin/amd64' ]; then\
cp artifact/x86_64-apple-darwin/binary .\
;elif [ "$TARGETPLATFORM" = 'darwin/arm64' ]; then\
cp artifact/aarch64-apple-darwin/binary .\
;elif [ "$TARGETPLATFORM" = 'linux/amd64' ]; then\
cp artifact/x86_64-unknown-linux-musl/binary .\
;elif [ "$TARGETPLATFORM" = 'linux/arm64' ]; then\
cp artifact/aarch64-unknown-linux-musl/binary .\
;fi
if [ "$TARGETPLATFORM" = 'darwin/amd64' ]; then\
cp artifact/x86_64-apple-darwin/binary .\
;elif [ "$TARGETPLATFORM" = 'darwin/arm64' ]; then\
cp artifact/aarch64-apple-darwin/binary .\
;elif [ "$TARGETPLATFORM" = 'linux/amd64' ]; then\
cp artifact/x86_64-unknown-linux-musl/binary .\
;elif [ "$TARGETPLATFORM" = 'linux/arm64' ]; then\
cp artifact/aarch64-unknown-linux-musl/binary .\
;fi

FROM --platform=$BUILDPLATFORM scratch as runner
COPY --from=env --chmod=755 binary .
ENTRYPOINT ["./binary"]
ARG BINARY_NAME
ENV BINARY_NAME=${BINARY_NAME}
COPY --from=env --chmod=755 binary "${BINARY_NAME}"
ENTRYPOINT ["./${BINARY_NAME}"]
3 changes: 2 additions & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
needs: build
permissions:
packages: write
runs-on: 'ubuntu-latest'
runs-on: "ubuntu-latest"
outputs:
image_tags: ${{ steps.meta.outputs.tags }}
env:
Expand Down Expand Up @@ -138,6 +138,7 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
with:
build-args: BINARY_NAME=${{ env.BINARY_NAME }}
context: .
file: .github/files/build/Dockerfile
platforms: darwin/amd64,darwin/arm64,linux/amd64,linux/arm64
Expand Down

0 comments on commit c07a0db

Please sign in to comment.