From f3074f0a5f5d3fdceeffcd0f0d522c7efaddf18a Mon Sep 17 00:00:00 2001 From: Yadomin Jinta Date: Sun, 12 Nov 2023 14:46:34 +0800 Subject: [PATCH 1/4] add static build --- .github/workflows/build.yml | 26 ++++++++++++++++++++++++++ Dockerfile.build.static | 14 ++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 Dockerfile.build.static diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..44f0925 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,26 @@ +name: build static binary +on: + workflow_dispatch: + push: + pull_request: +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build + run: | + docker buildx build --file Dockerfile.build.static --output out . + - name: Upload to artifact + uses: actions/upload-artifact@v3 + with: + name: binary + path: ./out/dog + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: ./out/dog \ No newline at end of file diff --git a/Dockerfile.build.static b/Dockerfile.build.static new file mode 100644 index 0000000..05e4b1a --- /dev/null +++ b/Dockerfile.build.static @@ -0,0 +1,14 @@ +FROM alpine as build + +COPY ./ /source +WORKDIR /source + +RUN apk update && \ + apk add rustup git gcc openssl1.1-compat-dev openssl1.1-compat-libs-static && \ + rustup-init -y && \ + source "$HOME/.cargo/env" && \ + cargo build && \ + strip target/debug/dog + +FROM scratch AS export-stage +COPY --from=build /source/target/debug/dog . From ecd5d2ae9d6cb2f0c1d5af14034991b5de0232bf Mon Sep 17 00:00:00 2001 From: Yadomin Jinta Date: Mon, 13 Nov 2023 00:31:49 +0800 Subject: [PATCH 2/4] [feat] support multi build target in ci --- .github/workflows/build.yml | 75 ++++++++++++++++++++++++++++++++++--- Dockerfile.build.static | 7 ++-- 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 44f0925..2ea1afc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,25 +2,88 @@ name: build static binary on: workflow_dispatch: push: + branches: + - master pull_request: jobs: - build: + build-linux: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 - name: Setup Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build run: | - docker buildx build --file Dockerfile.build.static --output out . + docker buildx build --platform "linux/amd64,linux/arm64" --file Dockerfile.build.static --output out . + mv out/**/dog_* out/ + rm -r out/linux* - name: Upload to artifact uses: actions/upload-artifact@v3 with: - name: binary - path: ./out/dog + name: binary_linux + path: ./out/dog_* + build-macos: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Dependencies + run: | + rustup target add aarch64-apple-darwin + - name: Build + run: | + cargo build --target=aarch64-apple-darwin + cargo build --target=x86_64-apple-darwin + mkdir out + mv -v target/aarch64-apple-darwin/debug/dog out/dog_darwin_arm64 + mv -v target/x86_64-apple-darwin/debug/dog out/dog_darwin_x86_64 + - name: Upload to artifact + uses: actions/upload-artifact@v3 + with: + name: binary_macos + path: ./out/* + build-windows: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup rust + run: | + rustup target add aarch64-pc-windows-msvc + - name: Build + run: | + cargo build --target x86_64-pc-windows-msvc + cargo build --target aarch64-pc-windows-msvc + mkdir out + move target\x86_64-pc-windows-msvc\debug\dog.exe out\dog_windows_x86_64.exe + move target\aarch64-pc-windows-msvc\debug\dog.exe out\dog_windows_arm64.exe + - name: Upload to artifact + uses: actions/upload-artifact@v3 + with: + name: binary_windows + path: ./out/* + + release: + runs-on: ubuntu-latest + needs: + - build-linux + - build-windows + - build-macos + steps: + - name: Download Artifact + uses: actions/download-artifact@v3 + with: + path: ./artifacts + - name: organize files + run: | + tree artifacts + mkdir out + mv -v artifacts/**/dog_* out/ - name: Release - uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v1 with: - files: ./out/dog \ No newline at end of file + files: ./out/dog_* \ No newline at end of file diff --git a/Dockerfile.build.static b/Dockerfile.build.static index 05e4b1a..4584452 100644 --- a/Dockerfile.build.static +++ b/Dockerfile.build.static @@ -4,11 +4,12 @@ COPY ./ /source WORKDIR /source RUN apk update && \ - apk add rustup git gcc openssl1.1-compat-dev openssl1.1-compat-libs-static && \ + apk add rustup git gcc lld openssl1.1-compat-dev openssl1.1-compat-libs-static && \ rustup-init -y && \ source "$HOME/.cargo/env" && \ - cargo build && \ + RUSTFLAGS="-C link-args=-fuse-ld=lld" cargo build && \ strip target/debug/dog FROM scratch AS export-stage -COPY --from=build /source/target/debug/dog . +ARG TARGETARCH +COPY --from=build /source/target/debug/dog ./dog_linux_$TARGETARCH \ No newline at end of file From 8c3c88fbdff9a30888a685923e9290f054fff7c1 Mon Sep 17 00:00:00 2001 From: Yadomin Jinta Date: Mon, 13 Nov 2023 18:32:36 +0800 Subject: [PATCH 3/4] [fix] push tag trigger --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ea1afc..a163953 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,6 +4,8 @@ on: push: branches: - master + tags: + - '*' pull_request: jobs: build-linux: From 7259cdb5ebe1d948229b8a28205e6f6762f7ee93 Mon Sep 17 00:00:00 2001 From: Yadomin Jinta Date: Wed, 13 Dec 2023 23:57:07 +0800 Subject: [PATCH 4/4] [fix] specific alpine version --- Dockerfile.build.static | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.build.static b/Dockerfile.build.static index 4584452..e88cd0f 100644 --- a/Dockerfile.build.static +++ b/Dockerfile.build.static @@ -1,4 +1,4 @@ -FROM alpine as build +FROM alpine:3.18 as build COPY ./ /source WORKDIR /source