Skip to content

Commit

Permalink
feat: Dockerfile to test cargo and JS packages (#3684)
Browse files Browse the repository at this point in the history
# Description
Adds the start of a Dockerfile to build / test both cargo and JS
packages

## Problem\*

Resolves #3685

## Summary\*



## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: kevaundray <[email protected]>
  • Loading branch information
sklppy88 and kevaundray authored Dec 8, 2023
1 parent 9dd465c commit 513d619
Show file tree
Hide file tree
Showing 11 changed files with 459 additions and 4 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/test-cargo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test cargo

on:
push:
branches:
- 'master'

jobs:
build:
name: Test cargo
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get current date
id: date
run: echo "date=$(date +'%Y.%m.%d.%H.%M')" >> $GITHUB_STATE
- name: prepare docker images tags
id: prep
run: |
REGISTRY="ghcr.io"
IMG="${REGISTRY}/${{ github.repository }}"
IMAGE=$(echo "$IMG" | tr '[:upper:]' '[:lower:]')
TAGS="${IMAGE}:${{ github.sha }}"
TAGS="${TAGS},${IMAGE}:latest,${IMAGE}:v${{ steps.date.outputs.date }}"
echo ::set-output name=tags::${TAGS}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Test cargo
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.ci
tags: ${{ steps.prep.outputs.tags }}
target: test-cargo
cache-from: type=gha
cache-to: type=gha,mode=max
44 changes: 44 additions & 0 deletions .github/workflows/test-js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test JS packages

on:
push:
branches:
- 'master'

jobs:
build:
name: Test JS packages
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get current date
id: date
run: echo "date=$(date +'%Y.%m.%d.%H.%M')" >> $GITHUB_STATE
- name: prepare docker images tags
id: prep
run: |
REGISTRY="ghcr.io"
IMG="${REGISTRY}/${{ github.repository }}"
IMAGE=$(echo "$IMG" | tr '[:upper:]' '[:lower:]')
TAGS="${IMAGE}:${{ github.sha }}"
TAGS="${TAGS},${IMAGE}:latest,${IMAGE}:v${{ steps.date.outputs.date }}"
echo ::set-output name=tags::${TAGS}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Test JS packages
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.ci
tags: ${{ steps.prep.outputs.tags }}
target: test-js
cache-from: type=gha
cache-to: type=gha,mode=max
41 changes: 41 additions & 0 deletions Dockerfile.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM rust:1-slim-bookworm as test-base
RUN apt-get update && apt-get upgrade -y && apt-get install build-essential git -y
WORKDIR /usr/src/noir
COPY . .
RUN ./scripts/bootstrap_native.sh
ENV PATH="${PATH}:/usr/src/noir/target/release/"

FROM test-base as test-cargo
RUN apt-get install -y curl libc++-dev
RUN ./scripts/test_native.sh

FROM test-base as test-js
RUN apt-get install pkg-config libssl-dev -y
RUN ./scripts/install_wasm-bindgen.sh
RUN apt-get install -y ca-certificates curl gnupg
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update && apt-get install nodejs -y
RUN corepack enable
RUN yarn --immutable
RUN apt-get install -y jq
RUN yarn build
RUN yarn workspace @noir-lang/acvm_js test
RUN npx playwright install && npx playwright install-deps
RUN yarn workspace @noir-lang/acvm_js test:browser
RUN yarn workspace @noir-lang/noirc_abi test
RUN yarn workspace @noir-lang/noirc_abi test:browser
RUN yarn workspace @noir-lang/backend_barretenberg test
RUN ./scripts/nargo_compile_noir_js_assert_lt.sh
RUN rm -rf /usr/src/noir/tooling/noir_js/test/noir_compiled_examples/assert_lt/target/debug_assert_lt.json
RUN yarn workspace @noir-lang/noir_js test
RUN yarn workspace @noir-lang/source-resolver test
RUN ./scripts/nargo_compile_wasm_fixtures.sh
RUN yarn workspace @noir-lang/noir_wasm test:node
RUN yarn workspace @noir-lang/noir_wasm test:browser
RUN ./scripts/nargo_compile_noir_codegen_assert_lt.sh
RUN rm -rf /usr/src/noir/tooling/noir_codegen/test/assert_lt/target/debug_assert_lt.json
RUN yarn workspace @noir-lang/noir_codegen test
RUN apt-get install -y libc++-dev
RUN yarn test:integration
4 changes: 3 additions & 1 deletion Dockerfile.packages
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ RUN apk update \
npm \
yarn \
bash \
jq
jq \
git

WORKDIR /usr/src/noir
COPY . .
RUN ./scripts/bootstrap_packages.sh
Expand Down
4 changes: 4 additions & 0 deletions scripts/nargo_compile_noir_codegen_assert_lt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

cd ./tooling/noir_codegen/test/assert_lt
nargo compile
4 changes: 4 additions & 0 deletions scripts/nargo_compile_noir_js_assert_lt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

cd ./tooling/noir_js/test/noir_compiled_examples/assert_lt
nargo compile
8 changes: 8 additions & 0 deletions scripts/nargo_compile_wasm_fixtures.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

cd ./compiler/wasm/fixtures
for dir in $(ls -d */); do
pushd $dir/noir-script
nargo compile
popd
done
28 changes: 28 additions & 0 deletions scripts/test_js_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -eu

cd $(dirname "$0")/..

./scripts/install_wasm-bindgen.sh

# If this project has been subrepod into another project, set build data manually.
export SOURCE_DATE_EPOCH=$(date +%s)
export GIT_DIRTY=false
if [ -f ".gitrepo" ]; then
export GIT_COMMIT=$(awk '/commit =/ {print $3}' .gitrepo)
else
export GIT_COMMIT=$(git rev-parse --verify HEAD)
fi

export cargoExtraArgs="--features noirc_driver/aztec"

cargo build --features="noirc_driver/aztec" --release
export PATH="${PATH}:/usr/src/noir/target/release/"

yarn
yarn build
npx playwright install
npx playwright install-deps

./scripts/test.sh
yarn test
15 changes: 15 additions & 0 deletions scripts/test_native.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -eu

cd $(dirname "$0")/..

# If this project has been subrepod into another project, set build data manually.
export SOURCE_DATE_EPOCH=$(date +%s)
export GIT_DIRTY=false
if [ -f ".gitrepo" ]; then
export GIT_COMMIT=$(awk '/commit =/ {print $3}' .gitrepo)
else
export GIT_COMMIT=$(git rev-parse --verify HEAD)
fi

cargo test --workspace --locked --release
3 changes: 2 additions & 1 deletion tooling/noir_codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dev": "tsc-multi --watch",
"build": "tsc",
"test": "yarn test:codegen && yarn test:node && yarn test:clean",
"test:codegen": "ts-node --esm src/main.ts ./test/assert_lt/target/** --out-dir ./test/codegen",
"test:codegen": "tsx src/main.ts ./test/assert_lt/target/** --out-dir ./test/codegen",
"test:node": "mocha --timeout 25000 --exit --config ./.mocharc.json",
"test:clean": "rm -rf ./test/codegen",
"prettier": "prettier 'src/**/*.ts'",
Expand All @@ -50,6 +50,7 @@
"mocha": "^10.2.0",
"prettier": "3.0.3",
"ts-node": "^10.9.1",
"tsx": "^4.6.2",
"typescript": "^5.2.2"
}
}
Loading

0 comments on commit 513d619

Please sign in to comment.