Skip to content

Commit

Permalink
Merge pull request #22 from solarwindscloud/arm-action
Browse files Browse the repository at this point in the history
Proper arm64 testing
  • Loading branch information
raphael-theriault-swi authored Feb 28, 2023
2 parents 0a2727e + 6b09f4d commit e745afe
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 85 deletions.
9 changes: 6 additions & 3 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ The version should be bumped prior to starting the release workflow using `npm v

The library previously used `node-pre-gyp`, allowing the dependents to build it themselves if no prebuilt package was available for their platform. However this is no longer the case, as we already publish prebuilt packages for every supported platform, this change simply makes this policy more explicit.

Some workflows necessitate testing on arm64 platforms. These workflows have two additional steps that are implied in the following descriptions, to launch and terminate EC2 runners which will run the jobs using our [custom action](https://github.com/solarwindscloud/ec2-runner-action).

## Usage

### Prep - Push Dockerfile
Expand Down Expand Up @@ -166,7 +168,8 @@ manual (image?) ─► └──────────────────
* Creating a pull request will trigger [review.yml](./workflows/review.yml).
* Workflow will:
- Build the code for all supported platforms and Node versions.
- Run the tests on each platform in the x64 group.
- Start EC2 runners for testing on arm64 platforms.
- Run the tests on each platform in the test group for both x64 and arm64.
* Workflow confirms code can be built in each of the required variations.
* Manual trigger supported.
```
Expand All @@ -184,7 +187,7 @@ manual ──────────► └────────────
* Workflow will:
- Build the code for all supported platforms and Node versions.
- Publish each platform-specific packages generated in the `npm` directory.
- Run the tests on each platform in the x64 group using the published packages.
- Run the tests on each platform in the test group for both x64 and arm64 using the published packages.
- Publish the `solarwinds-apm-bindings` NPM package upon successful completion of all steps above. When version tag is `prerelease`, package will be NPM tagged same. When it is a release version, package will be NPM tagged `latest`.
* Workflow ensures `optionalDependencies` setup is working in *production* for a wide variety of potential customer configurations.
* Workflow publishing to NPM registry exposes the NPM package to the public.
Expand Down Expand Up @@ -214,7 +217,7 @@ manual ──────────►│Confirm Publishable│
### Definitions
* Local images are defined in [docker-node](./docker-node).
* [x64 Group](./config/x64.json) images include a wide variety of x64 (x86_64) OS and Node version combinations.
* [Test Group](./config/test-group.json) images include a wide variety of OS and Node version combinations.

### Adding an image to GitHub Container Registry

Expand Down
32 changes: 4 additions & 28 deletions .github/config/x64-group.json → .github/config/test-group.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,7 @@
"image": "node:14-alpine3.12"
},
{
"image": "node:14-alpine3.13"
},
{
"image": "node:14-alpine3.14"
},
{
"image": "node:14-alpine3.15"
},
{
"image": "node:14-alpine3.16"
},
{
"image": "node:14-alpine3.17"
"image": "node:14-alpine"
},
{
"image": "node:14-buster"
Expand All @@ -34,16 +22,10 @@
"image": "ghcr.io/$GITHUB_REPOSITORY/node:14-amazonlinux2"
},
{
"image": "node:16-alpine3.14"
"image": "node:16-alpine3.12"
},
{
"image": "node:16-alpine3.15"
},
{
"image": "node:16-alpine3.16"
},
{
"image": "node:16-alpine3.17"
"image": "node:16-alpine"
},
{
"image": "node:16-buster"
Expand All @@ -67,13 +49,7 @@
"image": "node:18-alpine3.14"
},
{
"image": "node:18-alpine3.15"
},
{
"image": "node:18-alpine3.16"
},
{
"image": "node:18-alpine3.17"
"image": "node:18-alpine"
},
{
"image": "node:18-buster"
Expand Down
10 changes: 10 additions & 0 deletions .github/scripts/matrix-from-json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,15 @@ for env_var in $(printenv); do
JSON="${JSON//\$${arr[0]}/"${arr[1]}"}"
done

JSON_WITH_ARCH=$(echo "$JSON" | jq -c '.include = [.include[] | .+{ arch: ["arm64", "x64"][] }]')
# temporary fix for gha not supporting old arm64 alpine whatsoever
JSON_WITH_ARCH=$(echo "$JSON_WITH_ARCH" | jq -c '.include = [.include[] | select((.arch == "arm64") and (.image | contains("alpine")) and (.image | endswith("alpine") | not) | not)]')

ARM64_IMAGES=$(echo "$JSON_WITH_ARCH" | jq -r '.include[] | select(.arch == "arm64") | .image')

# return a value
echo "matrix=$JSON" >> $GITHUB_OUTPUT
echo "matrix-with-arch=$JSON_WITH_ARCH" >> $GITHUB_OUTPUT
echo "arm64-images<<EOF" >> $GITHUB_OUTPUT
echo "$ARM64_IMAGES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
3 changes: 3 additions & 0 deletions .github/workflows/docker-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Log in to the Container registry
uses: docker/login-action@v2
Expand All @@ -62,4 +64,5 @@ jobs:
context: ./.github/docker-node/
file: ./.github/docker-node/${{ matrix.tag }}.Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ghcr.io/${{ github.repository }}/node:${{ matrix.tag }}
85 changes: 71 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,59 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

load-x64-group:
name: Load x64 Group Config JSON
load-test-group:
name: Load Test Group Config JSON
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
matrix: ${{ steps.set-matrix.outputs.matrix-with-arch }}
arm64-images: ${{ steps.set-matrix.outputs.arm64-images }}

steps:
- name: Checkout ${{ github.ref }}
uses: actions/checkout@v3

- name: Load x64 group data
- name: Load test group data
id: set-matrix
run: .github/scripts/matrix-from-json.sh .github/config/x64-group.json
run: .github/scripts/matrix-from-json.sh .github/config/test-group.json

x64-group-install:
name: x64 Group Install
runs-on: ubuntu-latest
needs: [load-x64-group, build-publish-prebuilt]
launch-arm64:
name: Launch arm64 Runners
runs-on: ubuntu-latest
needs: load-test-group
outputs:
matrix: ${{ steps.launch.outputs.matrix }}
steps:
- name: Setup AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.CI_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CI_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Launch Runners
id: launch
uses: solarwindscloud/ec2-runner-action@main
with:
action: launch
github-token: ${{ secrets.CI_GITHUB_TOKEN }}
matrix: ${{ needs.load-test-group.outputs.arm64-images }}
runner-user: github
runner-directory: /gh
instance-type: t4g.medium
ami-name: gha-arm64-ubuntu22-.*
ami-owner: ${{ secrets.CI_AMI_OWNER }}
subnet-id: ${{ secrets.CI_SUBNET }}
security-group-ids: ${{ secrets.CI_SECURITY_GROUP }}

test-group-install:
name: Test Group Install
runs-on: ${{ matrix.arch == 'arm64' && fromJson(needs.launch-arm64.outputs.matrix)[matrix.image].label || 'ubuntu-latest' }}
needs: [load-test-group, launch-arm64, build-publish-prebuilt]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.load-x64-group.outputs.matrix) }}
matrix: ${{ fromJson(needs.load-test-group.outputs.matrix) }}
container:
image: ${{ matrix.image }}
image: ${{ matrix.image }}

env:
SW_APM_SERVICE_KEY: ${{ secrets.SW_APM_SERVICE_KEY }}
Expand All @@ -115,6 +145,13 @@ jobs:
- name: Change Owner of Container Working Directory
run: chown root:root .
if: ${{ contains(matrix.image, 'ghcr.io/solarwindscloud/solarwinds-bindings-node/node') }}
# install deps and spoof os-release to get gha to work on arm64 alpine
# https://github.com/actions/runner/issues/801#issuecomment-1374967227
- name: Prepare Alpine arm64
run: |
apk add gcompat
sed -i "s/ID=alpine/ID=armpine/" /etc/os-release
if: ${{ matrix.arch == 'arm64' && contains(matrix.image, 'alpine') }}

- name: Checkout ${{ github.ref }}
uses: actions/checkout@v3
Expand All @@ -135,10 +172,30 @@ jobs:
- name: Run Tests
run: npm test

terminate-arm64:
name: Terminate arm64 Runners
runs-on: ubuntu-latest
needs: [launch-arm64, test-group-install]
if: always()
steps:
- name: Setup AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.CI_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CI_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Terminate Runners
uses: solarwindscloud/ec2-runner-action@main
with:
action: terminate
github-token: ${{ secrets.CI_GITHUB_TOKEN }}
matrix: ${{ needs.launch-arm64.outputs.matrix }}

npm-publish:
name: NPM Publish
runs-on: ubuntu-latest
needs: x64-group-install
needs: test-group-install

steps:
- name: Checkout ${{ github.ref }}
Expand Down Expand Up @@ -176,8 +233,8 @@ jobs:
unpublish-prebuilt:
name: Unpublish prebuilt platform-specific packages
runs-on: ubuntu-latest
needs: [build-publish-prebuilt, x64-group-install]
if: ${{ always() && contains(needs.*.result, 'failure') }}
needs: [build-publish-prebuilt, test-group-install]
if: always() && contains(needs.*.result, 'failure')
strategy:
matrix:
node: ['14', '16', '18']
Expand Down
Loading

0 comments on commit e745afe

Please sign in to comment.