Skip to content

Commit

Permalink
Adding support for node:alpine (#1379)
Browse files Browse the repository at this point in the history
* Added build for musl to node
  • Loading branch information
avifenesh committed May 21, 2024
1 parent d38e936 commit 5eeb673
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 28 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build-node-wrapper/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ runs:
named_os: ${{ inputs.named_os }}
arch: ${{ inputs.arch }}
npm_scope: ${{ inputs.npm_scope }}

target: ${{ inputs.target }}

- name: npm install
shell: bash
working-directory: ./node
run: |
rm -rf node_modules && npm install --frozen-lockfile
cd rust-client
npm install
npm install --frozen-lockfile
- name: Build
shell: bash
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/install-rust-and-protoc/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Install Rust tool chain and protoc

inputs:
target:
description: "Specified target for rust toolchain, ex. x86_64-apple-darwin"
type: string
required: false
default: "x86_64-unknown-linux-gnu"
options:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- x86_64-apple-darwin
- aarch64-apple-darwin
github-token:
description: "GitHub token"
type: string
required: true


runs:
using: "composite"
steps:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ inputs.target }}

- name: Install protoc (protobuf)
uses: arduino/setup-protoc@v3
with:
version: "25.1"
repo-token: ${{ inputs.github-token }}
30 changes: 19 additions & 11 deletions .github/workflows/install-shared-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ inputs:
- aarch64-unknown-linux-gnu
- x86_64-apple-darwin
- aarch64-apple-darwin
- aarch64-unknown-linux-musl
- x86_64-unknown-linux-musl
github-token:
description: "GITHUB_TOKEN, GitHub App installation access token"
required: true
type: string


runs:
using: "composite"
steps:
Expand All @@ -35,26 +38,31 @@ runs:
brew upgrade || true
brew install git gcc pkgconfig openssl redis coreutils
- name: Install software dependencies for Ubuntu
- name: Install software dependencies for Ubuntu GNU
shell: bash
if: "${{ inputs.os == 'ubuntu' }}"
if: "${{ inputs.os == 'ubuntu' && !contains(inputs.target, 'musl')}}"
run: |
sudo apt update -y
sudo apt install -y git gcc pkg-config openssl libssl-dev
- name: Install software dependencies for Ubuntu MUSL
shell: bash
if: "${{ contains(inputs.target, 'musl') }}"
run: |
apk update
wget -O - https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
apk add protobuf-dev musl-dev make gcc redis envsubst
- name: Install software dependencies for Amazon-Linux
shell: bash
if: "${{ inputs.os == 'amazon-linux' }}"
run: |
yum install -y gcc pkgconfig openssl openssl-devel which curl redis6 gettext --allowerasing
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ inputs.target }}

- name: Install protoc (protobuf)
uses: arduino/setup-protoc@v3
- name: Install Rust toolchain and protoc
if: "${{ !contains(inputs.target, 'musl') }}"
uses: ./.github/workflows/install-rust-and-protoc
with:
version: "25.1"
repo-token: ${{ inputs.github-token }}
target: ${{ inputs.target }}
github-token: ${{ inputs.github-token }}
15 changes: 9 additions & 6 deletions .github/workflows/lint-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
description: "folder that contains the target Cargo.toml file"
required: true
type: string
github-token:
description: "github token"
required: false
type: string

runs:
using: "composite"
Expand All @@ -14,13 +18,12 @@ runs:
with:
submodules: recursive

- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2

- name: Install protoc (protobuf)
uses: arduino/setup-protoc@v3
- name: Install Rust toolchain and protoc
uses: ./.github/workflows/install-rust-and-protoc
with:
version: "25.1"
github-token: ${{ inputs.github-token }}

- uses: Swatinem/rust-cache@v2

- run: cargo fmt --all -- --check
working-directory: ${{ inputs.cargo-toml-folder }}
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/node-create-package-file/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ inputs:
required: false
type: string
default: "@aws"
target:
description: "Specified target for rust toolchain, ex. x86_64-apple-darwin"
type: string
required: true
options:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- x86_64-apple-darwin
- aarch64-apple-darwin
- aarch64-unknown-linux-musl
- x86_64-unknown-linux-musl

runs:
using: "composite"
Expand All @@ -42,6 +53,8 @@ runs:
shell: bash
working-directory: ./node
run: |
# echo -musl if inputs.target is musl
export MUSL_FLAG=`if [[ "${{ inputs.target }}" =~ .*"musl".* ]]; then echo "-musl"; fi`
# set the package name
name="glide-for-redis"
# derive the OS and architecture from the inputs
Expand All @@ -50,7 +63,7 @@ runs:
# set the version
export package_version="${{ inputs.release_version }}"
# set the package name
export pkg_name="${name}-${node_os}-${node_arch}"
export pkg_name="${name}-${node_os}${MUSL_FLAG}-${node_arch}"
# set the scope
export scope=`if [ "${{ inputs.npm_scope }}" != '' ]; then echo "${{ inputs.npm_scope }}/"; fi`
# set the registry scope
Expand Down
73 changes: 72 additions & 1 deletion .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,75 @@ jobs:
- name: Test compatibility
run: npm test -- -t "set and get flow works"
working-directory: ./node
working-directory: ./node

start-self-hosted-runner:
if: github.repository_owner == 'aws'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Start self hosted EC2 runner
uses: ./.github/workflows/start-self-hosted-runner
with:
aws-access-key-id: ${{ secrets.AWS_EC2_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_EC2_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
ec2-instance-id: ${{ secrets.AWS_EC2_INSTANCE_ID }}

# Since we are running a docker on a self-hosted runner, we need to make sure that the docker container has the same permissions as the self-hosted runner
# This is done by changing the ownership of the actions-runner directory to the user that is running the docker container
# We also need to checkout the repository, but since it is not possible to use checkout action with musl on arm we are doing it outside of the container,
# and later on in the container we just need to reset the repo to make sure we get the clean checkout of the action.
checkout-self-hosted-runner:
if: github.repository_owner == 'aws'
runs-on: [self-hosted, Linux, ARM64]
needs: start-self-hosted-runner
steps:
- name: Setup self-hosted runner access
run: sudo chown -R $USER:$USER /home/ubuntu/actions-runner/_work/glide-for-redis
- name: Checkout
uses: actions/checkout@v4

build-and-test-linux-musl-latest:
if: github.repository_owner == 'aws'
needs: [start-self-hosted-runner, checkout-self-hosted-runner]
name: Build and test Node wrapper on Linux musl
runs-on: [self-hosted, Linux, ARM64]
container:
image: node:alpine
options: --user root --privileged --rm
steps:
- name: Setup musl on Linux ARM
uses: ./.github/workflows/setup-musl-on-linux
with:
workspace: $GITHUB_WORKSPACE
npm-scope: ${{ secrets.NPM_SCOPE }}
npm-auth-token: ${{ secrets.NPM_AUTH_TOKEN }}

- name: Build Node wrapper
uses: ./.github/workflows/build-node-wrapper
with:
os: ubuntu
named_os: linux
arch: arm64
target: aarch64-unknown-linux-musl
github-token: ${{ secrets.GITHUB_TOKEN }}
npm_scope: ${{ vars.NPM_SCOPE }}
publish: false

- name: Test compatibility
shell: bash
run: npm test -- -t "set and get flow works"
working-directory: ./node

# Reset the repository to make sure we get the clean checkout of the action later in other actions.
# It is not required since in other actions we are cleaning before the action, but it is a good practice to do it here as well.
- name: Reset repository
if: always()
shell: bash
run: |
git reset --hard
git clean -xdf
58 changes: 55 additions & 3 deletions .github/workflows/npm-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- .github/workflows/npm-cd.yml
- .github/workflows/build-node-wrapper/action.yml
- .github/workflows/start-self-hosted-runner/action.yml
- .github/workflows/install-rust-and-protoc/action.yml
push:
tags:
- "v*.*"
Expand All @@ -23,6 +24,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Start self hosted EC2 runner
uses: ./.github/workflows/start-self-hosted-runner
with:
Expand All @@ -36,6 +40,9 @@ jobs:
if: github.repository_owner == 'aws'
name: Publish packages to NPM
runs-on: ${{ matrix.build.RUNNER }}
container:
image: ${{ matrix.build.IMAGE || '' }}
options: ${{ matrix.build.CONTAINER_OPTIONS || 'none'}}
strategy:
fail-fast: false
matrix:
Expand All @@ -53,7 +60,6 @@ jobs:
RUNNER: [self-hosted, Linux, ARM64],
ARCH: arm64,
TARGET: aarch64-unknown-linux-gnu,
CONTAINER: "2_28",
}
- {
OS: macos,
Expand All @@ -69,15 +75,51 @@ jobs:
arch: arm64,
TARGET: aarch64-apple-darwin,
}
- {
OS: ubuntu,
NAMED_OS: linux,
ARCH: arm64,
TARGET: aarch64-unknown-linux-musl,
RUNNER: [self-hosted, Linux, ARM64],
IMAGE: 'node:alpine',
CONTAINER_OPTIONS: '--user root --privileged --rm',
}
- {
OS: ubuntu,
NAMED_OS: linux,
ARCH: x64,
TARGET: x86_64-unknown-linux-musl,
RUNNER: ubuntu-latest,
IMAGE: 'node:alpine',
CONTAINER_OPTIONS: '--user root --privileged',
}
steps:
- name: Setup self-hosted runner access
if: ${{ contains(matrix.build.RUNNER, 'self-hosted') }}
if: ${{ contains(matrix.build.RUNNER, 'self-hosted') && matrix.build.TARGET != 'aarch64-unknown-linux-musl' }}
run: sudo chown -R $USER:$USER /home/ubuntu/actions-runner/_work/glide-for-redis

# For MUSL on X64 we need to install git since we use the checkout action
- name: Install git for musl
if: ${{ contains(matrix.build.TARGET, 'x86_64-unknown-linux-musl')}}
run: |
apk update
apk add git
- name: Checkout
if: ${{ matrix.build.TARGET != 'aarch64-unknown-linux-musl' }}
uses: actions/checkout@v4
with:
submodules: "true"
fetch-depth: 0

- name: Setup for musl
if: ${{ contains(matrix.build.TARGET, 'musl')}}
uses: ./.github/workflows/setup-musl-on-linux
with:
workspace: $GITHUB_WORKSPACE
npm-scope: ${{ vars.NPM_SCOPE }}
npm-auth-token: ${{ secrets.NPM_AUTH_TOKEN }}
arch: ${{ matrix.build.ARCH }}

- name: Set the release version
shell: bash
Expand All @@ -86,6 +128,7 @@ jobs:
echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV
- name: Setup node
if: ${{ matrix.build.TARGET != 'aarch64-unknown-linux-musl' }}
uses: actions/setup-node@v3
with:
node-version: "16"
Expand All @@ -100,7 +143,7 @@ jobs:
with:
folder_path: "${{ github.workspace }}/node/rust-client/.cargo"
named_os: ${{ matrix.build.NAMED_OS }}

- name: Build Node wrapper
uses: ./.github/workflows/build-node-wrapper
with:
Expand Down Expand Up @@ -152,6 +195,15 @@ jobs:
path: ./node/bin
if-no-files-found: error

# Reset the repository to make sure we get the clean checkout of the action later in other actions.
# It is not required since in other actions we are cleaning before the action, but it is a good practice to do it here as well.
- name: Reset repository
if: ${{ matrix.build.ARCH == 'arm64' }}
shell: bash
run: |
git reset --hard
git clean -xdf
publish-base-to-npm:
if: github.event_name != 'pull_request'
name: Publish the base NPM package
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ jobs:
os: "ubuntu"
target: "x86_64-unknown-linux-gnu"

- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2

- name: Run tests
Expand Down Expand Up @@ -83,6 +82,7 @@ jobs:
- uses: ./.github/workflows/lint-rust
with:
cargo-toml-folder: ./glide-core
github-token: ${{ secrets.GITHUB_TOKEN }}
name: lint glide-core

- uses: ./.github/workflows/lint-rust
Expand Down
Loading

0 comments on commit 5eeb673

Please sign in to comment.