Skip to content

Commit

Permalink
Adding support for arm64 architecture for both linux and macos (#387)
Browse files Browse the repository at this point in the history
* init commit for adding arm64 support for both macos, and linux

* testing changes to release workflow

* testing changes to release workflow

* testing changes to release workflow

* fix for unique ids

* testing changes to release workflow

* testing changes to release workflow

* testing changes to release workflow

* updating install script, and adding fix for failing curl/wget reqs

* testing changes to install script

* typo

* fixing symlink step

* testing changes to install script

* removing echo

* removing testing url, and putting it back to main repo

* linting for install script

* more lints breaking CI

* updating release workflow to run sudo apt update before attempting to install gcc for aarch64 due to transient errors
  • Loading branch information
joshfried-aws committed Aug 3, 2023
1 parent c0f15ed commit 2389367
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 93 deletions.
101 changes: 64 additions & 37 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Rust
on:
release:
types: [ published ]
types: [published]
env:
CARGO_TERM_COLOR: always

Expand All @@ -12,39 +12,66 @@ jobs:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose --release
- name: Get release
id: get_release
uses: bruceadams/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Package release
id: package
uses: knicknic/[email protected]
with:
macos: |
rustup target add x86_64-apple-darwin
cargo build --release --target x86_64-apple-darwin
mkdir cfn-guard-v3-${{ matrix.os }}
cp ./target/x86_64-apple-darwin/release/cfn-guard ./cfn-guard-v3-${{ matrix.os }}/
cp README.md ./cfn-guard-v3-${{ matrix.os }}/
tar czvf ./cfn-guard-v3-${{ matrix.os }}.tar.gz ./cfn-guard-v3-${{ matrix.os }}
linux: |
rustup target add x86_64-unknown-linux-musl
cargo build --release --target x86_64-unknown-linux-musl
mkdir cfn-guard-v3-${{ matrix.os }}
cp ./target/x86_64-unknown-linux-musl/release/cfn-guard ./cfn-guard-v3-${{ matrix.os }}/
cp README.md ./cfn-guard-v3-${{ matrix.os }}/
tar czvf ./cfn-guard-v3-${{ matrix.os }}.tar.gz ./cfn-guard-v3-${{ matrix.os }}
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./cfn-guard-v3-${{ matrix.os }}.tar.gz
asset_name: cfn-guard-v3-${{ matrix.os }}.tar.gz
asset_content_type: application/octet-stream
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose --release
- name: Get release
id: get_release
uses: bruceadams/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Package release
id: package
uses: knicknic/[email protected]
with:
macos: |
rustup target add x86_64-apple-darwin
cargo build --release --target x86_64-apple-darwin
mkdir cfn-guard-v3-x86_64-${{ matrix.os }}
cp ./target/x86_64-apple-darwin/release/cfn-guard ./cfn-guard-v3-x86_64-${{ matrix.os }}/
cp README.md ./cfn-guard-v3-x86_64-${{ matrix.os }}/
tar czvf ./cfn-guard-v3-x86_64-${{ matrix.os }}.tar.gz ./cfn-guard-v3-x86_64-${{ matrix.os }}
rustup target add aarch64-apple-darwin
cargo build --release --target aarch64-apple-darwin
mkdir cfn-guard-v3-aarch64-${{ matrix.os }}
cp ./target/aarch64-apple-darwin/release/cfn-guard ./cfn-guard-v3-aarch64-${{ matrix.os }}/
cp README.md ./cfn-guard-v3-aarch64-${{ matrix.os }}/
tar czvf ./cfn-guard-v3-aarch64-${{ matrix.os }}.tar.gz ./cfn-guard-v3-aarch64-${{ matrix.os }}
linux: |
rustup target add x86_64-unknown-linux-musl
cargo build --release --target x86_64-unknown-linux-musl
mkdir cfn-guard-v3-x86_64-${{ matrix.os }}
cp ./target/x86_64-unknown-linux-musl/release/cfn-guard ./cfn-guard-v3-x86_64-${{ matrix.os }}/
cp README.md ./cfn-guard-v3-x86_64-${{ matrix.os }}/
tar czvf ./cfn-guard-v3-x86_64-${{ matrix.os }}.tar.gz ./cfn-guard-v3-x86_64-${{ matrix.os }}
sudo apt update
sudo apt install gcc-aarch64-linux-gnu
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc
rustup target add aarch64-unknown-linux-musl
cargo build --release --target aarch64-unknown-linux-musl
mkdir cfn-guard-v3-aarch64-${{ matrix.os }}
cp ./target/aarch64-unknown-linux-musl/release/cfn-guard ./cfn-guard-v3-aarch64-${{ matrix.os }}/
cp README.md ./cfn-guard-v3-aarch64-${{ matrix.os }}/
tar czvf ./cfn-guard-v3-aarch64-${{ matrix.os }}.tar.gz ./cfn-guard-v3-aarch64-${{ matrix.os }}
- name: Upload x86 Release Asset
id: upload-x86_64-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./cfn-guard-v3-x86_64-${{ matrix.os }}.tar.gz
asset_name: cfn-guard-v3-x86_64-${{ matrix.os }}.tar.gz
asset_content_type: application/octet-stream
- name: Upload arm64 Release Asset
id: upload-aarch64-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./cfn-guard-v3-aarch64-${{ matrix.os }}.tar.gz
asset_name: cfn-guard-v3-aarch64-${{ matrix.os }}.tar.gz
asset_content_type: application/octet-stream
136 changes: 80 additions & 56 deletions install-guard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,107 @@
# to the latest one

main() {
if ! ( check_cmd curl || check_cmd wget ); then
err "need 'curl' or 'wget' (command not found)"
fi
need_cmd awk
need_cmd mkdir
need_cmd rm
need_cmd uname
need_cmd tar
need_cmd ln
if ! (check_cmd curl || check_cmd wget); then
err "need 'curl' or 'wget' (command not found)"
fi
need_cmd awk
need_cmd mkdir
need_cmd rm
need_cmd uname
need_cmd tar
need_cmd ln

get_os_type
get_latest_release |
while read -r MAJOR_VER; read -r VERSION; do
mkdir -p ~/.guard/"$MAJOR_VER" ~/.guard/bin ||
err "unable to make directories ~/.guard/$MAJOR_VER, ~/.guard/bin"
get_os_type
download https://github.com/aws-cloudformation/cloudformation-guard/releases/download/"$VERSION"/cfn-guard-v"$MAJOR_VER"-"$OS_TYPE"-latest.tar.gz > /tmp/guard.tar.gz ||
err "unable to download https://github.com/aws-cloudformation/cloudformation-guard/releases/download/$VERSION/cfn-guard-v$MAJOR_VER-$OS_TYPE-latest.tar.gz"
tar -C ~/.guard/"$MAJOR_VER" -xzf /tmp/guard.tar.gz ||
err "unable to untar /tmp/guard.tar.gz"
ln -sf ~/.guard/"$MAJOR_VER"/cfn-guard-v"$MAJOR_VER"-"$OS_TYPE"-latest/cfn-guard ~/.guard/bin ||
err "unable to symlink to ~/.guard/bin directory"
~/.guard/bin/cfn-guard help ||
err "cfn-guard was not installed properly"
echo "Remember to SET PATH include PATH=\${PATH}:~/.guard/bin"
done
get_os_type
get_arch_type
get_latest_release |
while
read -r MAJOR_VER
read -r VERSION
do
mkdir -p ~/.guard/"$MAJOR_VER" ~/.guard/bin ||
err "unable to make directories ~/.guard/$MAJOR_VER, ~/.guard/bin"
get_os_type
download https://github.com/cloudformation-guard/releases/download/"$VERSION"/cfn-guard-v"$MAJOR_VER"-"$ARCH_TYPE"-"$OS_TYPE"-latest.tar.gz >/tmp/guard.tar.gz ||
err "unable to download https://github.com/aws-cloudformation/cloudformation-guard/releases/download/$VERSION/cfn-guard-v$MAJOR_VER-$ARCH_TYPE-$OS_TYPE-latest.tar.gz"
tar -C ~/.guard/"$MAJOR_VER" -xzf /tmp/guard.tar.gz ||
err "unable to untar /tmp/guard.tar.gz"
ln -sf ~/.guard/"$MAJOR_VER"/cfn-guard-v"$MAJOR_VER"-"$ARCH_TYPE"-"$OS_TYPE"-latest/cfn-guard ~/.guard/bin ||
err "unable to symlink to ~/.guard/bin directory"
~/.guard/bin/cfn-guard help ||
err "cfn-guard was not installed properly"
echo "Remember to SET PATH include PATH=\${PATH}:~/.guard/bin"
done
}

get_os_type() {
_ostype="$(uname -s)"
case "$_ostype" in
Darwin)
OS_TYPE="macos"
;;
_ostype="$(uname -s)"
case "$_ostype" in
Darwin)
OS_TYPE="macos"
;;

Linux)
# IS this RIGHT, we need to build for different ARCH as well.
# Need more ARCH level detections
OS_TYPE="ubuntu"
;;
Linux)
# IS this RIGHT, we need to build for different ARCH as well.
# Need more ARCH level detections
OS_TYPE="ubuntu"
;;

*)
err "unsupported OS type $_ostype"
;;
esac
*)
err "unsupported OS type $_ostype"
;;
esac
}

get_arch_type() {
_archtype="$(uname -m)"
case "$_archtype" in
arm64)
ARCH_TYPE="aarch64"
;;
aarch64)
ARCH_TYPE="aarch64"
;;
x86_64)
ARCH_TYPE="x86_64"
;;

*)
err "unsupported architecture type $_archtype"
;;
esac
}

get_latest_release() {
download https://api.github.com/repos/aws-cloudformation/cloudformation-guard/releases/latest |
awk -F '"' '/tag_name/ { print $4 }' |
awk -F '.' '{ print $1 "\n" $0 }'
download https://api.github.com/repos/aws-cloudformation/cloudformation-guard/releases/latest |
awk -F '"' '/tag_name/ { print $4 }' |
awk -F '.' '{ print $1 "\n" $0 }'
}

err() {
echo "$1" >&2
exit 1
echo "$1" >&2
exit 1
}

need_cmd() {
if ! check_cmd "$1"; then
err "need '$1' (command not found)"
fi
if ! check_cmd "$1"; then
err "need '$1' (command not found)"
fi
}

check_cmd() {
command -v "$1" > /dev/null 2>&1
command -v "$1" >/dev/null 2>&1
}

download()
{
if check_cmd curl; then
curl -fsSL "$1"
else
wget -qO- "$1"
fi
download() {
if check_cmd curl; then
if ! (curl -fsSL "$1"); then
err "error attempting to download from the github repository"
fi
else
if ! (wget -qO- "$1"); then
err "error attempting to download from the github repository"
fi
fi
}


main

0 comments on commit 2389367

Please sign in to comment.