Skip to content

Commit

Permalink
Adding support for node:alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
avifenesh committed May 7, 2024
1 parent de07b3e commit 14074fa
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 7 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/install-shared-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ 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
Expand All @@ -35,12 +37,21 @@ 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' && inputs.target != 'x86_64-unknown-linux-musl' && inputs.target != 'aarch64-unknown-linux-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: "${{ inputs.target == 'x86_64-unknown-linux-musl' || inputs.target == 'aarch64-unknown-linux-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
- name: Install software dependencies for Amazon-Linux
shell: bash
Expand All @@ -49,11 +60,13 @@ runs:
yum install -y gcc pkgconfig openssl openssl-devel which curl redis6 gettext --allowerasing
- name: Install Rust toolchain
if: "${{ inputs.target != 'x86_64-unknown-linux-musl' && inputs.target != 'aarch64-unknown-linux-musl' }}"
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ inputs.target }}

- name: Install protoc (protobuf)
if: "${{ inputs.target != 'x86_64-unknown-linux-musl' && inputs.target != 'aarch64-unknown-linux-musl' }}"
uses: arduino/setup-protoc@v3
with:
version: "25.1"
Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,65 @@ jobs:
- name: Test compatibility
run: npm test -- -t "set and get flow works"
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 }}


build-linux-musl-latest:
needs: start-self-hosted-runner
if: github.repository_owner == 'aws'
name: Build and test Node wrapper on Linux musl
runs-on: [self-hosted, Linux, ARM64]
container:
image: node:alpine
options: --user root
volumes:
- ${{ github.workspace }}
strategy:
fail-fast: false
timeout-minutes: 15
steps:

- name: Install dependencies
run: |
apk update
apk add bash git envsubst
- name: Checkout repository
shell: bash
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git fetch --all
git submodule sync
git submodule update --init --recursive
git checkout ${{ github.sha }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_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 }}

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

130 changes: 128 additions & 2 deletions .github/workflows/npm-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ concurrency:
cancel-in-progress: true

jobs:

start-self-hosted-runner:
if: github.repository_owner == 'aws'
runs-on: ubuntu-latest
Expand All @@ -29,7 +30,7 @@ jobs:
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 }}
ec2-instance-id: ${{ secrets.AWS_EC2_INSTANCE_ID }}

publish-binaries:
needs: start-self-hosted-runner
Expand Down Expand Up @@ -100,7 +101,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 @@ -151,6 +152,131 @@ jobs:
name: ${{ matrix.build.TARGET }}
path: ./node/bin
if-no-files-found: error

publish-musl-binaries:
needs: start-self-hosted-runner
if: github.repository_owner == 'aws'
name: Publish packages to NPM
runs-on: ${{ matrix.build.RUNNER }}
container:
image: node:alpine
options: --user root
volumes:
- ${{ github.workspace }}
strategy:
fail-fast: false
matrix:
build:
- {
OS: ubuntu,
NAMED_OS: linux,
RUNNER: ubuntu-latest,
ARCH: x64,
TARGET: x86_64-unknown-linux-musl,
}
- {
OS: ubuntu,
NAMED_OS: linux,
RUNNER: [self-hosted, Linux, ARM64],
ARCH: arm64,
TARGET: aarch64-unknown-linux-musl,
CONTAINER: "2_28",
}
steps:

- name: Install dependencies
run: |
apk update
apk add bash envsubst git sed
- name: Checkout arm64
if: ${{ matrix.build.ARCH == 'arm64'}}
shell: bash
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git fetch --all
git submodule sync
git submodule update --init --recursive
git checkout ${{ github.sha }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout x86
if: ${{ matrix.build.ARCH == 'x64'}}
uses: actions/checkout@v4
with:
submodules: "true"

- name: Set the release version
shell: bash
run: |
export version=`if ${{ github.event_name == 'pull_request' }}; then echo '255.255.255'; else echo ${GITHUB_REF:11}; fi`
echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV
- name: Update package version in config.toml
uses: ./.github/workflows/update-glide-version
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:
os: ${{ matrix.build.OS }}
named_os: ${{ matrix.build.NAMED_OS }}
arch: ${{ matrix.build.ARCH }}
target: ${{ matrix.build.TARGET }}
npm_scope: ${{ vars.NPM_SCOPE }}
publish: "true"
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup node
run: |
npm config set registry https://registry.npmjs.org/
npm config set '//registry.npmjs.org/:_authToken' ${{ secrets.NPM_AUTH_TOKEN }}
npm config set scope ${{ vars.NPM_SCOPE }}
- name: Publish to NPM
if: github.event_name != 'pull_request'
shell: bash
working-directory: ./node
run: |
set +e
# Redirect only stderr
{ npm_publish_err=$(npm publish --access public 2>&1 >&3 3>&-); } 3>&1
if [[ "$npm_publish_err" == *"You cannot publish over the previously published versions"* ]]
then
echo "Skipping publishing, package already published"
elif [[ ! -z "$npm_publish_err" ]]
then
echo "Failed to publish with error: ${npm_publish_err}"
exit 1
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

- name: Pack the Node package
shell: bash
working-directory: ./node
run: |
# Remove the "cpu" and "os" fileds so the base package would be able to install it on ubuntu
sed -i '/"\/\/\/cpu": \[/,/]/d' ./package.json && sed -i '/"\/\/\/os": \[/,/]/d' ./package.json
mkdir -p bin
npm pack --pack-destination ./bin
ls ./bin
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

- name: Upload the Node package
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.build.TARGET }}
path: ./node/bin
if-no-files-found: error

publish-base-to-npm:
if: github.event_name != 'pull_request'
Expand Down
25 changes: 23 additions & 2 deletions node/npm/glide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0
*/

import { GLIBC, MUSL, familySync } from "detect-libc";
import { arch, platform } from "process";

let globalObject = global as unknown;
Expand All @@ -14,10 +15,30 @@ function loadNativeBinding() {
case "linux":
switch (arch) {
case "x64":
nativeBinding = require("@scope/glide-for-redis-linux-x64");
switch (familySync()) {
case GLIBC:
nativeBinding = require("@scope/glide-for-redis-linux-x64");
break;
case MUSL:
nativeBinding = require("@scope/glide-for-redis-linux-musl-x64");
break;
default:
nativeBinding = require("@scope/glide-for-redis-linux-x64");
break;
}
break;
case "arm64":
nativeBinding = require("@scope/glide-for-redis-linux-arm64");
switch (familySync()) {
case GLIBC:
nativeBinding = require("@scope/glide-for-redis-linux-arm64");
break;
case MUSL:
nativeBinding = require("@scope/glide-for-redis-linux-musl-arm64");
break;
default:
nativeBinding = require("@scope/glide-for-redis-linux-arm64");
break;
}
break;
default:
throw new Error(
Expand Down
7 changes: 6 additions & 1 deletion node/npm/glide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"${scope}glide-for-redis-darwin-arm64": "${package_version}",
"${scope}glide-for-redis-darwin-x64": "${package_version}",
"${scope}glide-for-redis-linux-arm64": "${package_version}",
"${scope}glide-for-redis-linux-x64": "${package_version}"
"${scope}glide-for-redis-linux-x64": "${package_version}",
"${scope}glide-for-redis-linux-musl-arm64": "${package_version}",
"@scope/glide-for-redis-linux-musl-x64": "${package_version}"
},
"eslintConfig": {
"extends": [
Expand All @@ -58,5 +60,8 @@
"build-ts/*"
],
"root": true
},
"dependencies": {
"detect-libc": "^2.0.3"
}
}

0 comments on commit 14074fa

Please sign in to comment.