From fe9866bf7f237f00b526a49a086c7129b8a6a61a Mon Sep 17 00:00:00 2001 From: Gyubong Lee Date: Tue, 4 Jun 2024 12:27:37 +0000 Subject: [PATCH 1/4] ci: Add `arch` option to build.sh --- .../{release_x86_64.yml => release.yml} | 14 ++++++-- .github/workflows/release_aarch64.yml | 36 ------------------- build.sh | 16 +++++++-- 3 files changed, 25 insertions(+), 41 deletions(-) rename .github/workflows/{release_x86_64.yml => release.yml} (55%) delete mode 100644 .github/workflows/release_aarch64.yml diff --git a/.github/workflows/release_x86_64.yml b/.github/workflows/release.yml similarity index 55% rename from .github/workflows/release_x86_64.yml rename to .github/workflows/release.yml index 0b863e1..92e4265 100644 --- a/.github/workflows/release_x86_64.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Build and release x86_64 binaries +name: Build and release on: [push] @@ -8,14 +8,22 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - target: ["x86_64"] + target: ["x86_64", "aarch64"] os: ["ubuntu18.04", "ubuntu20.04", "ubuntu22.04", "alpine"] steps: - uses: actions/checkout@v4 + - name: Install QEMU + if: matrix.target == 'aarch64' + run: | + sudo apt-get update + sudo apt-get install -y qemu-user-static + sudo update-binfmts --enable qemu-arm + sudo update-binfmts --enable qemu-aarch64 + - name: Build libbaihook run: | - ./build.sh ${{ matrix.os }} + ./build.sh --arch ${{ matrix.target }} ${{ matrix.os }} - name: Release to GitHub uses: softprops/action-gh-release@v2 diff --git a/.github/workflows/release_aarch64.yml b/.github/workflows/release_aarch64.yml deleted file mode 100644 index c86bce2..0000000 --- a/.github/workflows/release_aarch64.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Build and release aarch64 binaries - -on: [push] - -jobs: - release: - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') - runs-on: ubuntu-latest - strategy: - matrix: - target: ["aarch64"] - os: ["ubuntu18.04", "ubuntu20.04", "ubuntu22.04", "alpine"] - steps: - - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build Docker image - uses: docker/build-push-action@v4 - with: - context: . - load: true - platforms: linux/arm64 - tags: lablup/backend.ai-hook:latest - - - name: Build libbaihook - run: | - docker run --rm -v "$(pwd)" lablup/backend.ai-hook:latest /bin/bash -c "./build.sh ${{ matrix.os }}" - - - name: Release to GitHub - uses: softprops/action-gh-release@v2 - with: - generate_release_notes: true - files: | - ./*.so diff --git a/build.sh b/build.sh index 3f29056..3591efc 100755 --- a/build.sh +++ b/build.sh @@ -14,15 +14,19 @@ usage() { echo "" echo "OPTIONS" echo " -h, --help Show this help message and exit." + echo " --arch Specify the target architecture (default: uname -m)." echo " --clean Run 'make clean' instead of 'make'." echo " --force-cmake Force to re-run cmake to refresh build scripts." } +arch=$(uname -m) + while [ $# -gt 0 ]; do case $1 in -h | --help) usage; exit 1 ;; --force-cmake) FORCE_CMAKE=1 ;; --clean) CLEAN=1 ;; + --arch) shift; arch=$1 ;; *) break esac @@ -30,7 +34,7 @@ while [ $# -gt 0 ]; do done distro="$1" -arch="$(uname -m)" + case $distro in ubuntu22.04) distro="ubuntu" @@ -56,7 +60,15 @@ user="$(id -u):$(id -g)" # to prevent "fatal: unable to look up current user in the passwd file: no such user" error from git git_fix="-e GIT_COMMITTER_NAME=devops -e GIT_COMMITTER_EMAIL=devops@lablup.com" -docker build -t lablup/hook-dev:${distro_ver} -f Dockerfile.${distro_ver} . +if [ "$arch" = "aarch64" ]; then + echo '{ "experimental": true }' | sudo tee /etc/docker/daemon.json + sudo systemctl restart docker + + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes +fi + +docker build --platform=linux/${arch} -t lablup/hook-dev:${distro_ver} -f Dockerfile.${distro_ver} . + docker_run="docker run --rm ${git_fix} -v "$(pwd):/root" -u ${user} -w=/root lablup/hook-dev:${distro_ver} /bin/sh -c" if [ "$FORCE_CMAKE" -eq 1 -o ! -f "Makefile" ]; then From 454ac24cbb89855828ee1f3bb58dbd5e52c3ceda Mon Sep 17 00:00:00 2001 From: Gyubong Lee Date: Tue, 4 Jun 2024 12:53:30 +0000 Subject: [PATCH 2/4] feat: Improve `ARCH` variable assignment --- build.sh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/build.sh b/build.sh index 3591efc..2673376 100755 --- a/build.sh +++ b/build.sh @@ -19,22 +19,20 @@ usage() { echo " --force-cmake Force to re-run cmake to refresh build scripts." } -arch=$(uname -m) +ARCH=$(uname -m) while [ $# -gt 0 ]; do case $1 in -h | --help) usage; exit 1 ;; --force-cmake) FORCE_CMAKE=1 ;; --clean) CLEAN=1 ;; - --arch) shift; arch=$1 ;; - *) - break + --arch) ARCH=$2; shift;; + --arch=*) ARCH="${1#*=}" ;; + *) distro="$1" esac shift done -distro="$1" - case $distro in ubuntu22.04) distro="ubuntu" @@ -60,14 +58,14 @@ user="$(id -u):$(id -g)" # to prevent "fatal: unable to look up current user in the passwd file: no such user" error from git git_fix="-e GIT_COMMITTER_NAME=devops -e GIT_COMMITTER_EMAIL=devops@lablup.com" -if [ "$arch" = "aarch64" ]; then +if [ "$ARCH" = "aarch64" ]; then echo '{ "experimental": true }' | sudo tee /etc/docker/daemon.json sudo systemctl restart docker docker run --rm --privileged multiarch/qemu-user-static --reset -p yes fi -docker build --platform=linux/${arch} -t lablup/hook-dev:${distro_ver} -f Dockerfile.${distro_ver} . +docker build --platform=linux/${ARCH} -t lablup/hook-dev:${distro_ver} -f Dockerfile.${distro_ver} . docker_run="docker run --rm ${git_fix} -v "$(pwd):/root" -u ${user} -w=/root lablup/hook-dev:${distro_ver} /bin/sh -c" @@ -80,9 +78,9 @@ if [ "$CLEAN" -eq 1 ]; then $docker_run 'make clean' rm -r CMakeFiles googletest-build googletest-download CMakeCache.txt cmake_install.cmake Makefile else - echo ">> Building for ${distro} ${arch} ..." + echo ">> Building for ${distro} ${ARCH} ..." $docker_run 'make' - cp "baihook/libbaihook.so" "libbaihook.${distro_ver}.${arch}.so" - cp "test/test-hook" "test-hook.${distro_ver}.${arch}.bin" - cp "test/test-hooked" "test-hooked.${distro_ver}.${arch}.bin" + cp "baihook/libbaihook.so" "libbaihook.${distro_ver}.${ARCH}.so" + cp "test/test-hook" "test-hook.${distro_ver}.${ARCH}.bin" + cp "test/test-hooked" "test-hooked.${distro_ver}.${ARCH}.bin" fi From ef39f55c16e229b9174a1d100db1fec29730c060 Mon Sep 17 00:00:00 2001 From: Gyubong Lee Date: Tue, 4 Jun 2024 13:04:44 +0000 Subject: [PATCH 3/4] chore: Remove useless if condition --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 92e4265..291a015 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,7 @@ on: [push] jobs: release: - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') + if: contains(github.ref, 'refs/tags/') runs-on: ubuntu-latest strategy: matrix: From 20a78256f4c5fc362ac7d9e2f1b1c3ae520a8bf7 Mon Sep 17 00:00:00 2001 From: Gyubong Lee Date: Tue, 4 Jun 2024 13:10:54 +0000 Subject: [PATCH 4/4] ci: Enable only the necessary targets --- .github/workflows/release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 291a015..083bf70 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,6 @@ jobs: run: | sudo apt-get update sudo apt-get install -y qemu-user-static - sudo update-binfmts --enable qemu-arm sudo update-binfmts --enable qemu-aarch64 - name: Build libbaihook