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 c7613a0
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .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
defalt: "x86_64-unknown-linux-gnu"
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"
steps:
- 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"
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,15 @@ 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 +39,30 @@ 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
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: "${{ inputs.target != 'x86_64-unknown-linux-musl' && inputs.target != 'aarch64-unknown-linux-musl' }}"
uses: ./.github/workflows/install-rust-and-protoc
with:
version: "25.1"
repo-token: ${{ inputs.github-token }}
target: ${{ inputs.target }}
8 changes: 7 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,10 @@ inputs:
required: false
type: string
default: "@aws"
target:
description: "Specified target for rust toolchain, ex. x86_64-apple-darwin"
type: string
required: true

runs:
using: "composite"
Expand All @@ -42,6 +46,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 +56,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}-${node_arch}${MUSL_FLAG}"
# set the scope
export scope=`if [ "${{ inputs.npm_scope }}" != '' ]; then echo "${{ inputs.npm_scope }}/"; fi`
# set the registry scope
Expand Down
71 changes: 70 additions & 1 deletion .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,73 @@ 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 }}

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
strategy:
fail-fast: false
timeout-minutes: 15
steps:

- name: Install dependencies
run: |
apk update
apk add bash git envsubst
# Currently it is not possible to use the checkout action with self-hosted runners on alpine so we need to do it manually
- 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 clean -ffdx
git gc --prune=now
git remote prune origin
git fetch --depth=1 origin +refs/pull/*:refs/remotes/origin/pr/*
git checkout origin/pr/${{ github.ref_name }}
git submodule sync
git submodule update --init --recursive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Downgrade npm major version to 8
run: |
npm i -g npm@8
- 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 }}
publish: true

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

146 changes: 143 additions & 3 deletions .github/workflows/npm-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ concurrency:
cancel-in-progress: true

jobs:

start-self-hosted-runner:
if: github.repository_owner == 'aws'
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 }}
ec2-instance-id: ${{ secrets.AWS_EC2_INSTANCE_ID }}

publish-binaries:
needs: start-self-hosted-runner
Expand Down Expand Up @@ -100,7 +102,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 +153,144 @@ 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
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
# Currently it is not possible to use the checkout action with self-hosted runners on alpine so we need to do it manually
- 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 config --local --get remote.origin.url
git rev-parse --symbolic-full-name --verify --quiet HEAD
git clean -ffdx
git reset --hard HEAD
git config --local gc.auto 0
git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin ${{github.sha}}:refs/remotes/pull/${{github.ref_name}}
git sparse-checkout disable
git config --local --unset-all extensions.worktreeConfig
git checkout --progress --force refs/remotes/pull/${{github.ref_name}}
git submodule sync
git -c protocol.version=2 submodule update --init --force --depth=1
git submodule foreach git config --local gc.auto 0
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: Set the package name
shell: bash
run: |
export pkg_name=`if [ "${{ matrix.build.ARCH }}" == 'x64' ]; then echo "glide-for-redis-linux-musl-x64"; else echo "glide-for-redis-linux-musl-arm64"; fi`
echo "PKG_NAME=${pkg_name}" >> $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
working-directory: ./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
Loading

0 comments on commit c7613a0

Please sign in to comment.