diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..d54b56b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,227 @@ +name: Release +on: + push: + branches: [master] + tags: + - "v*.*.*" + create: + tags: + - "v*.*.*" + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + AGENT_NAME: agent + RELAYER_NAME: relayer + ARTIFACT_DIR: release-builds + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-release: + name: build-release + runs-on: ${{ matrix.os }} + env: + RUST_BACKTRACE: 1 + strategy: + matrix: + build: + - linux gnu x64 + - linux musl x64 + - linux gnu aarch64 + - linux musl aarch64 + - linux gnueabihf arm + - linux gnueabihf armv7 + - linux gnu mips + - linux gnuabi64 mips64 + - linux gnuabi64 mips64el + - linux gnu mipsel + - macos x64 + - macos aarch64 + include: + - build: linux gnu x64 + os: ubuntu-latest + rust: stable + target: x86_64-unknown-linux-gnu + cross: false + - build: linux musl x64 + os: ubuntu-latest + rust: stable + target: x86_64-unknown-linux-musl + cross: false + - build: linux gnu aarch64 + os: ubuntu-latest + rust: stable + target: aarch64-unknown-linux-gnu + cross: true + - build: linux musl aarch64 + os: ubuntu-latest + rust: stable + target: aarch64-unknown-linux-musl + cross: true + - build: linux gnueabihf arm + os: ubuntu-latest + rust: stable + target: arm-unknown-linux-gnueabihf + cross: true + - build: linux gnueabihf armv7 + os: ubuntu-latest + rust: stable + target: armv7-unknown-linux-gnueabihf + cross: true + - build: linux gnu mips + os: ubuntu-latest + rust: 1.71.1 + target: mips-unknown-linux-gnu + cross: true + - build: linux gnuabi64 mips64 + os: ubuntu-latest + rust: 1.71.1 + target: mips64-unknown-linux-gnuabi64 + cross: true + - build: linux gnuabi64 mips64el + os: ubuntu-latest + rust: 1.71.1 + target: mips64el-unknown-linux-gnuabi64 + cross: true + - build: linux gnu mipsel + os: ubuntu-latest + rust: 1.71.1 + target: mipsel-unknown-linux-gnu + cross: true + - build: linux musl aarch64 + os: ubuntu-latest + rust: stable + target: aarch64-unknown-linux-musl + cross: true + - build: macos x64 + os: macos-latest + rust: stable + target: x86_64-apple-darwin + cross: false + - build: macos aarch64 + os: macos-latest + rust: stable + target: aarch64-apple-darwin + cross: true + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + target: ${{ matrix.target }} + + - name: Install dev-tools + if: matrix.os == 'ubuntu-latest' + run: sudo apt-get install -y --no-install-recommends pkg-config musl-dev musl-tools + + - name: Build agent + uses: actions-rs/cargo@v1 + with: + use-cross: ${{ matrix.cross }} + command: build + args: --verbose --release --package ${{ env.AGENT_NAME }} --target ${{ matrix.target }} + + - name: Build relayer + uses: actions-rs/cargo@v1 + with: + use-cross: ${{ matrix.cross }} + command: build + args: --verbose --release --package ${{ env.RELAYER_NAME }} --target ${{ matrix.target }} + + - name: Rename file + run: | + mv ./target/${{ matrix.target }}/release/${{ env.AGENT_NAME }} ${{ env.AGENT_NAME }}-${{ matrix.target }} + mv ./target/${{ matrix.target }}/release/${{ env.RELAYER_NAME }} ${{ env.RELAYER_NAME }}-${{ matrix.target }} + + - name: Upload Artifact to Summary + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.target }} + path: | + ${{ env.AGENT_NAME }}-${{ matrix.target }} + ${{ env.RELAYER_NAME }}-${{ matrix.target }} + + - name: Upload agent binaries to release + if: startsWith(github.ref, 'refs/tags/') + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ env.AGENT_NAME }}-${{ matrix.target }} + asset_name: ${{ env.AGENT_NAME }}-${{ matrix.target }} + tag: ${{ github.ref }} + overwrite: true + + - name: Upload relayer binaries to release + if: startsWith(github.ref, 'refs/tags/') + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ env.RELAYER_NAME }}-${{ matrix.target }} + asset_name: ${{ env.RELAYER_NAME }}-${{ matrix.target }} + tag: ${{ github.ref }} + overwrite: true + + create-release: + # only run if not a tags build + if: startsWith(github.ref, 'refs/tags/') == false + needs: build-release + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v3 + - name: Display structure of downloaded files + run: ls -R + - name: create_release + id: create_release + uses: marvinpinto/action-automatic-releases@latest + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: ${{ github.event_name == 'workflow_dispatch' && 'latest' || (github.ref == 'refs/heads/master' && 'latest') || github.ref }} + title: Build ${{ github.event_name == 'workflow_dispatch' && 'development' || github.ref }} + files: | + */* + prerelease: true + + deploy-docker: + needs: build-release + runs-on: ubuntu-latest + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Checkout repository + uses: actions/checkout@v4 + - uses: actions/download-artifact@v3 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..3528295 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,24 @@ +name: Rust + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Install dev-tools + run: sudo apt-get install -y --no-install-recommends build-essential pkg-config libssl-dev + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..69e5f2e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM ubuntu:22.04 as base +ARG TARGETPLATFORM +COPY . /tmp +WORKDIR /tmp + +RUN echo $TARGETPLATFORM +RUN ls -R /tmp/ +# move the binary to root based on platform +RUN case $TARGETPLATFORM in \ + "linux/amd64") BUILD=x86_64-unknown-linux-gnu ;; \ + "linux/arm64") BUILD=aarch64-unknown-linux-gnu ;; \ + *) exit 1 ;; \ + esac; \ + mv /tmp/$BUILD/agent-$BUILD /agent; \ + mv /tmp/$BUILD/relayer-$BUILD /relayer; \ + chmod +x /agent \ + chmod +x /relayer + +FROM ubuntu:22.04 + +COPY --from=base /relayer /relayer +COPY --from=base /agent /agent + +ENTRYPOINT ["/relayer"] \ No newline at end of file