Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build bridge for arm64 #2521

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/actions/build-bridge/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build Binaries
description: "Builds Linux Binaries"

inputs:
target:
description: Build target architecture
required: true

runs:
using: "composite"
steps:
# Download Helper Image built in the previous jobs
- name: Downloading helper Image
uses: ishworkh/[email protected]
with:
image: "witnet-rust/${{ inputs.target }}:latest"

- name: Export Vars
shell: bash
run: |
echo PWD=`pwd` >> $GITHUB_ENV
echo TARGET=${{ inputs.target }} >> $GITHUB_ENV
- name: Build Binary
shell: bash
run: docker run -v `pwd`:/project:ro -v `pwd`/target:/target -v ~/.cargo:/root/.cargo -w /project -i witnet-rust/$TARGET bash -c "cargo build --release --target=$TARGET --target-dir=/target -p witnet-centralized-ethereum-bridge"

- name: List Directory
shell: bash
run: ls -lsa ./target/${{ inputs.target }}/release
172 changes: 128 additions & 44 deletions .github/workflows/bridge.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,156 @@
name: Bridge

on:
workflow_dispatch:
inputs:
force:
description: 'Force execution of this action'
type: boolean
required: false
default: true
push:
tags:
- '*-bridge*'

env:
CARGO_TERM_COLOR: always

jobs:
Bridge:
#?####################################################################################################?#
#? ?#
#? Build Helper Images ?#
#? ?#
#?####################################################################################################?#
aarch64:
runs-on: ubuntu-latest
environment: tags
if: ${{ github.event.workflow_run.conclusion == 'success' || inputs.force }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Protobuf
run: |
sudo apt install -y protobuf-compiler
protoc --version
- name: Building Docker Image
uses: ./.github/actions/build-helper
with:
imagename: aarch64-unknown-linux-gnu

- name: Build witnet-centralized-ethereum-bridge
run: |
cargo build -p witnet-centralized-ethereum-bridge --release
x86_64:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Move file to outside docker ignored
run: |
cp target/release/witnet-centralized-ethereum-bridge ./
- name: Building Docker Image
uses: ./.github/actions/build-helper
with:
imagename: x86_64-unknown-linux-gnu

- name: Check Pre-release
run: |
TAG=${{ github.ref_name }}
if [[ "$TAG" =~ - ]]; then
echo "prerelease=true" >> $GITHUB_ENV
else
echo "prerelease=false" >> $GITHUB_ENV
fi
#?####################################################################################################?#
#? ?#
#? Build Releases ?#
#? ?#
#?####################################################################################################?#

- name: Set Version
run: |
echo VERNUM=$(sed -nE 's/version\s?=\s?"([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9\.]+)?)"/\1/p' ./bridges/centralized-ethereum/Cargo.toml | head -1) >> $GITHUB_ENV
Build_aarch64:
needs: [aarch64]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Building aarch64 Binary
uses: ./.github/actions/build-bridge
with:
target: aarch64-unknown-linux-gnu

- name: see path
run: cd target && tree

- name: Upload Build
uses: actions/upload-artifact@v4
with:
name: aarch64-release
path: |
target/aarch64-unknown-linux-gnu/release/witnet-centralized-ethereum-bridge

Build_x86_64:
needs: [x86_64]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to Docker hub Registry
- name: Building x86_64 Binary
uses: ./.github/actions/build-bridge
with:
target: x86_64-unknown-linux-gnu

- name: see path
run: cd target && tree

- name: Upload Build
uses: actions/upload-artifact@v4
with:
name: x86_64-release
path: |
target/x86_64-unknown-linux-gnu/release/witnet-centralized-ethereum-bridge


#?####################################################################################################?#
#? ?#
#? Sign & Publish ?#
#? ?#
#?####################################################################################################?#
Publish:
needs: [Build_aarch64, Build_x86_64]
runs-on: ubuntu-latest
environment: tags
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Login to Docker Container Registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build & Push Tag Image
- name: Download aarch64 Build
uses: actions/download-artifact@v4
with:
name: aarch64-release
path: all-releases/aarch64/

- name: Download x86_64 Build
uses: actions/download-artifact@v4
with:
name: x86_64-release
path: all-releases/x86_64/

- name: Prepare aarch64
run: |
docker build -t witnet/witnet-centralized-ethereum-bridge:"$VERNUM" -f ./docker/bridge/Dockerfile .
docker push witnet/witnet-centralized-ethereum-bridge:"$VERNUM"
chmod +x ./all-releases/aarch64/witnet-centralized-ethereum-bridge
mv all-releases/aarch64/witnet-centralized-ethereum-bridge docker/bridge/witnet-centralized-ethereum-bridge-aarch64-unknown-linux-gnu

- name: Build & Push Latest if not Pre-Release
- name: Prepare x86_64
run: |
docker build -t witnet/witnet-centralized-ethereum-bridge:latest -f ./docker/bridge/Dockerfile .
docker push witnet/witnet-centralized-ethereum-bridge:latest
if: env.prerelease == 'false'
chmod +x ./all-releases/x86_64/witnet-centralized-ethereum-bridge
mv all-releases/x86_64/witnet-centralized-ethereum-bridge docker/bridge/witnet-centralized-ethereum-bridge-x86_64-unknown-linux-gnu

- name: List binaries
run: tree docker

Failure:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- run: echo '(Release Tag) workflow failed, EXITING!!!!' && exit 1
- name: Build Base
run: |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker buildx create --name multiarch --driver docker-container --use
docker buildx inspect --bootstrap

# Build Docker images (Latest & TAG)
- name: Build TAG
run: |
PRUNED_TAG=$(echo "${{github.ref_name}}" | sed 's/-bridge//')
docker buildx build -f docker/bridge/Dockerfile --progress=plain --platform linux/amd64,linux/arm64 --tag witnet/witnet-centralized-ethereum-bridge:$PRUNED_TAG docker/bridge

- name: Check Pre-release
run: |
TAG=${{ github.ref_name }}
if [[ "$TAG" =~ -rc ]]; then
echo "prerelease=true" >> $GITHUB_ENV
else
echo "prerelease=false" >> $GITHUB_ENV

- name: Build Latest if not Pre-Release
if: env.prerelease == 'false'
run: docker buildx build -f docker/bridge/Dockerfile --progress=plain --platform linux/amd64,linux/arm64 --tag witnet/witnet-centralized-ethereum-bridge:latest docker/bridge --push --no-cache
3 changes: 2 additions & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
tags:
- '*'
- '!*bridge*'

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -201,7 +202,7 @@ jobs:

- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
Expand Down
19 changes: 18 additions & 1 deletion docker/bridge/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
FROM witnet/witnet-rust:latest

COPY ./witnet-centralized-ethereum-bridge /
ARG TARGETPLATFORM

# Use a conditional COPY command based on the target platform
COPY witnet-centralized-ethereum-bridge-x86_64-unknown-linux-gnu /
COPY witnet-centralized-ethereum-bridge-aarch64-unknown-linux-gnu /

RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
echo "Current platform linux/amd64"; \
mv /witnet-centralized-ethereum-bridge-x86_64-unknown-linux-gnu /witnet-centralized-ethereum-bridge; \
rm /witnet-centralized-ethereum-bridge-aarch64-unknown-linux-gnu; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
echo "Current platform linux/arm64"; \
mv /witnet-centralized-ethereum-bridge-aarch64-unknown-linux-gnu /witnet-centralized-ethereum-bridge; \
rm /witnet-centralized-ethereum-bridge-x86_64-unknown-linux-gnu; \
else \
echo "Unsupported platform: $TARGETPLATFORM"; \
exit 1; \
fi

ENTRYPOINT ["/witnet-centralized-ethereum-bridge", "--env"]