From a018a1e3ae64733b5ec8d5070ffa1a03e5a0e050 Mon Sep 17 00:00:00 2001 From: xixi Date: Tue, 14 Sep 2021 17:50:57 +0800 Subject: [PATCH] cherry-pick(#15) add aarch64 release in ci (#16) --- .github/workflows/release.yaml | 37 +++++++++++++++++++++--------- Dockerfile | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 67a6e50..f30729a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -6,16 +6,12 @@ on: name: Create Release jobs: - build: + create_release: name: Create Release runs-on: ubuntu-latest + outputs: + upload_url: ${{ steps.create_release.outputs.upload_url }} steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Build - run: cargo build --release - - name: Pack - run: mv ./target/release/tproxy . && tar -czvf ./tproxy.tar.gz tproxy - name: Create Release id: create_release uses: actions/create-release@v1 @@ -26,13 +22,32 @@ jobs: release_name: Release ${{ github.ref }} draft: false prerelease: false + build: + name: Upload Release + needs: create_release + runs-on: ubuntu-latest + strategy: + matrix: + include: + - target: aarch64-unknown-linux-gnu + cc: gcc-aarch64-linux-gnu + - target: x86_64-unknown-linux-gnu + cc: gcc + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Build + run: | + DOCKER_BUILDKIT=1 docker build --build-arg CC=${{ matrix.cc }} --build-arg TARGET=${{ matrix.target }} --build-arg HTTP_PROXY=${HTTP_PROXY} --build-arg HTTPS_PROXY=${HTTPS_PROXY} . -t chaos-mesh/tproxy + docker run -v ${PWD}:/opt/mount:z --rm --entrypoint cp chaos-mesh/tproxy /tproxy /opt/mount/tproxy + tar -czvf ./tproxy-${{ matrix.target }}.tar.gz ./tproxy - name: Upload Release Asset id: upload-release-asset uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./tproxy.tar.gz - asset_name: tproxy-linux-amd64.tar.gz - asset_content_type: application/zip \ No newline at end of file + upload_url: ${{ needs.create_release.outputs.upload_url }} + asset_path: ./tproxy-${{ matrix.target }}.tar.gz + asset_name: tproxy-${{ matrix.target }}.tar.gz + asset_content_type: application/zip diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..24f5c86 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ + +# syntax=docker/dockerfile:experimental + +FROM debian:buster-slim + +ENV DEBIAN_FRONTEND noninteractive + +ARG HTTPS_PROXY +ARG HTTP_PROXY +ARG TARGET=x86_64-unknown-linux-gnu +ARG CC=gcc + +ENV http_proxy $HTTP_PROXY +ENV https_proxy $HTTPS_PROXY + +RUN apt-get update && apt-get install build-essential $CC curl git pkg-config -y && rm -rf /var/lib/apt/lists/* + +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +ENV PATH "/root/.cargo/bin:${PATH}" + +RUN rustup target add $TARGET + +RUN if [ -n "$HTTP_PROXY" ]; then echo "[http]\n\ +proxy = \"${HTTP_PROXY}\"\n\ +"\ +>> /root/.cargo/config ; fi + +RUN echo "[target.aarch64-unknown-linux-gnu]\n\ +linker = \"aarch64-linux-gnu-gcc\"\n\ +"\ +>> /root/.cargo/config + +COPY . /tproxy-build + +WORKDIR /tproxy-build + +RUN --mount=type=cache,target=/tproxy-build/target \ + --mount=type=cache,target=/root/.cargo/registry \ + cargo build --release --all --target $TARGET + +RUN --mount=type=cache,target=/tproxy-build/target \ + cp /tproxy-build/target/$TARGET/release/tproxy /tproxy