From f3974d2b18b997c77d2e3cfc913a785c294d5c4c Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Fri, 8 Mar 2024 00:00:04 +0000 Subject: [PATCH] build(rust-compiler): retire the container image and the test cases 1. This started off with me trying to fix the CVEs in the rust-compiler image. 2. I was able to get rid of most of them by changing the base image to ubuntu-24.04 3. The remaining high and critical ones were due to wasm-pack so went to see if we could upgrade that but we are already on the latest which is 8 months old. The vulnerabilities were reported on the wasm-pack repo 6 months ago along with a pull request that fixes them, neither the issue nor the pull request fixing it received any attention from the wasm-pack maintainers which lead me to believe that it is a liability to depend on it right now and we should instead look into a different tooling where the maintenance happens to have a little more resources dedicated to it. Java/Kotlin might be the way to go. 4. I've also looked into possible alternatives to wasm-pack but the only other tool I found that does the same thing is cargo-web which hasn't had a new release for 4 years and counting and has even more CVEs plaguing it than wasm-pack. 5. The official web assembly site links to wasm-pack when it comes to compiling to it from Rust so there's probably not a better maintained tool out there, but if someone finds something I'd love to start using it. In the meantime I'll just archive/retire/delete the rust compiler image and the tests associated with it because it's a maintenance burden that we don't need to carry. Signed-off-by: Peter Somogyvari --- .github/workflows/ci.yaml | 15 -- .github/workflows/rust-compiler-publish.yaml | 60 ----- .../src/main/typescript/public-api.ts | 8 - .../rustc-container/rustc-build-cmd.ts | 16 -- .../rustc-container/rustc-container.ts | 221 ------------------ .../rustc-container-target-bundler.test.ts | 132 ----------- .../rustc-container-target-nodejs.test.ts | 136 ----------- tools/docker/rust-compiler/Dockerfile | 7 - tools/docker/rust-compiler/README.md | 17 -- 9 files changed, 612 deletions(-) delete mode 100644 .github/workflows/rust-compiler-publish.yaml delete mode 100644 packages/cactus-test-tooling/src/main/typescript/rustc-container/rustc-build-cmd.ts delete mode 100644 packages/cactus-test-tooling/src/main/typescript/rustc-container/rustc-container.ts delete mode 100644 packages/cactus-test-tooling/src/test/typescript/integration/rustc-container/rustc-container-target-bundler.test.ts delete mode 100644 packages/cactus-test-tooling/src/test/typescript/integration/rustc-container/rustc-container-target-nodejs.test.ts delete mode 100644 tools/docker/rust-compiler/Dockerfile delete mode 100644 tools/docker/rust-compiler/README.md diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2bf143c9b9..5315eed85d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2358,21 +2358,6 @@ jobs: ignore-unfixed: true vuln-type: 'os,library' severity: 'CRITICAL,HIGH' - ghcr-rust-compiler: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3.5.2 - - name: ghcr.io/hyperledger/cactus-rust-compiler - run: DOCKER_BUILDKIT=1 docker build ./tools/docker/rust-compiler/ -f ./tools/docker/rust-compiler/Dockerfile -t cactus-rust-compiler - - name: Run Trivy vulnerability scan for cactus-rust-compiler - uses: aquasecurity/trivy-action@0.11.2 - with: - image-ref: 'cactus-rust-compiler' - format: 'table' - exit-code: '1' - ignore-unfixed: true - vuln-type: 'os,library' - severity: 'CRITICAL,HIGH' ghcr-test-npm-registry: runs-on: ubuntu-20.04 steps: diff --git a/.github/workflows/rust-compiler-publish.yaml b/.github/workflows/rust-compiler-publish.yaml deleted file mode 100644 index 001a3fdf2f..0000000000 --- a/.github/workflows/rust-compiler-publish.yaml +++ /dev/null @@ -1,60 +0,0 @@ -name: rust-compiler-publish - -on: - push: - # Publish `main` as Docker `latest` image. - branches: - - main - - # Publish `v1.2.3` tags as releases. - tags: - - v* - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -env: - IMAGE_NAME: cactus-rust-compiler - -jobs: - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ - build-tag-push-container: - runs-on: ubuntu-20.04 - env: - DOCKER_BUILDKIT: 1 - DOCKERFILE_PATH: ./tools/docker/rust-compiler/Dockerfile - DOCKER_BUILD_DIR: ./tools/docker/rust-compiler/ - permissions: - packages: write - contents: read - - steps: - - uses: actions/checkout@v3.5.2 - - - name: Build image - run: docker build $DOCKER_BUILD_DIR --file $DOCKERFILE_PATH --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" - - - name: Log in to registry - # This is where you will update the PAT to GITHUB_TOKEN - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - - name: Push image - run: | - SHORTHASH=$(git rev-parse --short "$GITHUB_SHA") - TODAYS_DATE="$(date +%F)" - DOCKER_TAG="$TODAYS_DATE-$SHORTHASH" - IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - # Strip "v" prefix from tag name - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - # Do not use the `latest` tag at all, tag with date + git short hash if there is no git tag - [ "$VERSION" == "main" ] && VERSION=$DOCKER_TAG - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION diff --git a/packages/cactus-test-tooling/src/main/typescript/public-api.ts b/packages/cactus-test-tooling/src/main/typescript/public-api.ts index ed5bff1d84..699fe00d42 100755 --- a/packages/cactus-test-tooling/src/main/typescript/public-api.ts +++ b/packages/cactus-test-tooling/src/main/typescript/public-api.ts @@ -166,12 +166,6 @@ export { SampleCordappEnum, } from "./corda/sample-cordapp-enum"; -export { - IRustcContainerOptions, - K_DEFAULT_RUSTC_CONTAINER_CMD, - RustcContainer, -} from "./rustc-container/rustc-container"; - export { ISawtoothTestLedgerOptions, SAWTOOTH_LEDGER_DEFAULT_OPTIONS, @@ -183,8 +177,6 @@ export { SubstrateTestLedger, } from "./substrate-test-ledger/substrate-test-ledger"; -export { RustcBuildCmd } from "./rustc-container/rustc-build-cmd"; - export { Streams } from "./common/streams"; export { isRunningInGithubAction } from "./github-actions/is-running-in-github-action"; diff --git a/packages/cactus-test-tooling/src/main/typescript/rustc-container/rustc-build-cmd.ts b/packages/cactus-test-tooling/src/main/typescript/rustc-container/rustc-build-cmd.ts deleted file mode 100644 index 9639903861..0000000000 --- a/packages/cactus-test-tooling/src/main/typescript/rustc-container/rustc-build-cmd.ts +++ /dev/null @@ -1,16 +0,0 @@ -export const RustcBuildCmd = { - CARGO_BUILD_RELEASE: ["cargo", "build", "--release"], - WASM_PACK_BUILD_BUNDLER: [ - "wasm-pack", - "build", - "--release", - "--target=bundler", - ], - WASM_PACK_BUILD_NODEJS: [ - "wasm-pack", - "build", - "--release", - "--target=nodejs", - ], - WASM_PACK_BUILD_WEB: ["wasm-pack", "build", "--release", "--target=web"], -}; diff --git a/packages/cactus-test-tooling/src/main/typescript/rustc-container/rustc-container.ts b/packages/cactus-test-tooling/src/main/typescript/rustc-container/rustc-container.ts deleted file mode 100644 index 06fd24d7ae..0000000000 --- a/packages/cactus-test-tooling/src/main/typescript/rustc-container/rustc-container.ts +++ /dev/null @@ -1,221 +0,0 @@ -import type { EventEmitter } from "events"; -import fs from "fs-extra"; -import { Optional } from "typescript-optional"; -import { RuntimeError } from "run-time-error-cjs"; -import type { Container } from "dockerode"; -import Docker from "dockerode"; -import { Logger, Checks, Bools } from "@hyperledger/cactus-common"; -import type { LogLevelDesc } from "@hyperledger/cactus-common"; -import { LoggerProvider } from "@hyperledger/cactus-common"; -import { Containers } from "../common/containers"; -import { RustcBuildCmd } from "./rustc-build-cmd"; - -export const K_DEFAULT_RUSTC_CONTAINER_WORKDIR = "/usr/src/host-sources-dir/"; - -export const K_DEFAULT_RUSTC_CONTAINER_CMD = - RustcBuildCmd.WASM_PACK_BUILD_BUNDLER; - -export interface IRustcContainerOptions { - readonly logLevel?: LogLevelDesc; - readonly imageName?: string; - readonly imageTag?: string; - /** - * The path on the host machine's file-system where the carbo build should - * occur. Note that host machine in this context means the machine that runs - * the test using this class, the one launching the containers. - */ - readonly hostSourceDir?: string; - readonly emitContainerLogs?: boolean; - readonly envVars?: Map; - readonly workDir?: string; -} - -/** - * Helper class designed to enable test cases compiling Rust code without needing - * to depend on Rust being installed. - * - * At it's core, it is meant to be a programamatic substitute for doing something - * like this on your local machine: - * - * ```sh - * $ docker run --rm --user "$(id -u)":"$(id -g)" -v "$PWD":/usr/src/myapp -w /usr/src/myapp rust:1.52.0 cargo build --release - * ``` - * - * @see https://developer.mozilla.org/en-US/docs/WebAssembly/Rust_to_wasm - */ -export class RustcContainer { - public static readonly CLASS_NAME = "RustcContainer"; - - public readonly logLevel: LogLevelDesc; - public readonly imageName: string; - public readonly imageTag: string; - public readonly imageFqn: string; - public readonly log: Logger; - public readonly emitContainerLogs: boolean; - public readonly hostSourceDir: Optional; - public readonly workDir: string; - public readonly envVars: Map; - - private _containerId: Optional; - - public get containerId(): Optional { - return this._containerId; - } - - public get cwd(): string { - return this.workDir; - } - - public get container(): Optional { - const docker = new Docker(); - return this.containerId.isPresent() - ? Optional.ofNonNull(docker.getContainer(this.containerId.get())) - : Optional.empty(); - } - - public get className(): string { - return RustcContainer.CLASS_NAME; - } - - constructor(public readonly opts: IRustcContainerOptions) { - const fnTag = `${this.className}#constructor()`; - Checks.truthy(opts, `${fnTag} arg options`); - - if (opts.hostSourceDir) { - Checks.nonBlankString(opts.hostSourceDir, `${fnTag} opts.hostSourceDir`); - } - - this._containerId = Optional.empty(); - this.hostSourceDir = Optional.ofNullable(opts.hostSourceDir); - this.imageName = - opts.imageName || "ghcr.io/hyperledger/cactus-rust-compiler"; - this.imageTag = opts.imageTag || "2023-06-26-8e59648"; - this.imageFqn = `${this.imageName}:${this.imageTag}`; - this.envVars = opts.envVars || new Map(); - this.emitContainerLogs = Bools.isBooleanStrict(opts.emitContainerLogs) - ? (opts.emitContainerLogs as boolean) - : true; - - this.workDir = opts.workDir - ? opts.workDir - : K_DEFAULT_RUSTC_CONTAINER_WORKDIR; - - Checks.nonBlankString(this.workDir, `${fnTag} non-blank str this.workDir`); - - this.logLevel = opts.logLevel || "INFO"; - - const level = this.logLevel; - const label = this.className; - this.log = LoggerProvider.getOrCreate({ level, label }); - - this.log.debug(`Created instance of ${this.className} OK`); - } - - public async start(omitPull = false): Promise { - if (this.hostSourceDir.isPresent()) { - await this.checkHostSourceDirExists(); - } - - const docker = new Docker(); - if (this.containerId.isPresent()) { - this.log.warn(`Container ID provided. Will not start new one.`); - const container = docker.getContainer(this.containerId.get()); - return container; - } - if (!omitPull) { - this.log.debug(`Pulling image ${this.imageFqn}...`); - await Containers.pullImage(this.imageFqn, {}, this.opts.logLevel); - this.log.debug(`Pulled image ${this.imageFqn} OK`); - } - - const dockerEnvVars: string[] = new Array(...this.envVars).map( - (pairs) => `${pairs[0]}=${pairs[1]}`, - ); - - const Binds = this.hostSourceDir.isPresent() - ? [`${this.hostSourceDir.get()}:${this.cwd}`] - : []; - - const createOptions = { - WorkingDir: this.workDir, - Env: dockerEnvVars, - Healthcheck: { - Test: [ - "CMD-SHELL", - `rustup --version && rustc --version && cargo --version`, - ], - Interval: 1000000000, // 1 second - Timeout: 3000000000, // 3 seconds - Retries: 10, - StartPeriod: 1000000000, // 1 second - }, - HostConfig: { - AutoRemove: true, - Binds, - }, - }; - - this.log.debug(`Starting ${this.imageFqn} with options: `, createOptions); - - return new Promise((resolve, reject) => { - const eventEmitter: EventEmitter = docker.run( - this.imageFqn, - [], - [], - createOptions, - {}, - (err: Error) => { - if (err) { - const errorMessage = `Failed to start container ${this.imageFqn}`; - const exception = new RuntimeError(errorMessage, err); - this.log.error(exception); - reject(exception); - } - }, - ); - - eventEmitter.once("start", async (container: Container) => { - const { id } = container; - this.log.debug(`Started ${this.imageFqn} successfully. ID=${id}`); - this._containerId = Optional.ofNonNull(id); - - if (this.emitContainerLogs) { - const fnTag = `[${this.imageFqn}]`; - await Containers.streamLogs({ - container: this.container.get(), - tag: fnTag, - log: this.log, - }); - } - - this.log.debug(`Registered container log stream callbacks OK`); - - try { - this.log.debug(`Starting to wait for healthcheck... `); - await Containers.waitForHealthCheck(this.containerId.get()); - this.log.debug(`Healthcheck passed OK`); - resolve(container); - } catch (ex) { - this.log.error(ex); - reject(ex); - } - }); - }); - } - - public async stop(): Promise { - return Containers.stop(this.container.get()); - } - - public async destroy(): Promise { - return this.container.get().remove(); - } - - public async checkHostSourceDirExists(): Promise { - const pathExists = await fs.pathExists(this.hostSourceDir.get()); - if (!pathExists) { - const errorMessage = `hostSourceDir ${this.hostSourceDir.get()} does not exist (or not accessible) on file-system. Cannot continue with Rust compilation`; - throw new RuntimeError(errorMessage); - } - } -} diff --git a/packages/cactus-test-tooling/src/test/typescript/integration/rustc-container/rustc-container-target-bundler.test.ts b/packages/cactus-test-tooling/src/test/typescript/integration/rustc-container/rustc-container-target-bundler.test.ts deleted file mode 100644 index fce6a52c6c..0000000000 --- a/packages/cactus-test-tooling/src/test/typescript/integration/rustc-container/rustc-container-target-bundler.test.ts +++ /dev/null @@ -1,132 +0,0 @@ -import path from "path"; -import test, { Test } from "tape-promise/tape"; -import temp from "temp"; -import esm from "esm"; -import fs from "fs-extra"; -import { LogLevelDesc } from "@hyperledger/cactus-common"; -import { - Containers, - RustcBuildCmd, - RustcContainer, -} from "../../../../main/typescript/public-api"; - -const logLevel: LogLevelDesc = "TRACE"; - -type HelloWorldExports = { - hello_world: () => string; - say_hello: (name: string) => string; -}; - -/** - * Skip this until we figure out why this new error (out of the blue) is happening: - * https://github.com/hyperledger/cactus/issues/2104 - */ -test.skip("compiles Rust code to bundler targeted .wasm", async (t: Test) => { - const tmpDirAffix = "cactus-test-tooling-rustc-container-test"; - temp.track(); - test.onFinish(async () => await temp.cleanup()); - const hostSourceDir = await temp.mkdir(tmpDirAffix); - - const srcDir = path.join(hostSourceDir, "./src/"); - await fs.mkdir(srcDir); - - const rustcContainer = new RustcContainer({ logLevel }); - t.ok(rustcContainer, "RustcContainer instance truthy OK"); - - test.onFinish(async () => { - await rustcContainer.stop(); - }); - - const dockerodeContainer = await rustcContainer.start(); - t.ok(dockerodeContainer, "dockerodeContainer truthy OK"); - - const containerPkDir = path.join(rustcContainer.cwd, "./pkg/"); - - const cargoTomlHostDir = path.join( - __dirname, - "../../../rust/fixtures/wasm-hello-world/", - ); - const putCargoTomlRes = await Containers.putFile({ - containerOrId: dockerodeContainer, - dstFileDir: rustcContainer.cwd, - dstFileName: "Cargo.toml", - srcFileDir: cargoTomlHostDir, - srcFileName: "Cargo.toml", - }); - t.ok(putCargoTomlRes, "putCargoTomlRes truthy OK"); - t.ok(putCargoTomlRes.statusCode, "putCargoTomlRes.statusCode truthy OK"); - t.equal(putCargoTomlRes.statusCode, 200, "putCargoTomlRes.statusCode 200 OK"); - - const containerSrcDir = path.join(rustcContainer.cwd, "./src/"); - await Containers.exec(dockerodeContainer, ["mkdir", containerSrcDir]); - - const libRsHostDir = path.join( - __dirname, - "../../../rust/fixtures/wasm-hello-world/src/", - ); - const putLibRsRes = await Containers.putFile({ - containerOrId: dockerodeContainer, - dstFileDir: containerSrcDir, - dstFileName: "lib.rs", - srcFileDir: libRsHostDir, - srcFileName: "lib.rs", - }); - t.ok(putLibRsRes, "putLibRsRes truthy OK"); - t.ok(putLibRsRes.statusCode, "putLibRsRes.statusCode truthy OK"); - t.equal(putLibRsRes.statusCode, 200, "putLibRsRes.statusCode 200 OK"); - - const wasmPackBuildOut = await Containers.exec( - dockerodeContainer, - RustcBuildCmd.WASM_PACK_BUILD_BUNDLER, - 300000, - "TRACE", - ); - t.ok(wasmPackBuildOut, "wasmPackBuildOut truthy OK"); - - // The list of files the wasm-pack bundler target produces - const expectedFiles = [ - ".gitignore", - "hello_world.d.ts", - "hello_world.js", - "hello_world_bg.js", - "hello_world_bg.wasm", - "hello_world_bg.wasm.d.ts", - "package.json", - ]; - - const filesOnFs = await Containers.ls(dockerodeContainer, containerPkDir); - t.ok(filesOnFs, "filesOnFs truthy OK"); - t.true(Array.isArray(filesOnFs), "Array.isArray(filesOnFs) OK"); - t.comment(`filesOnFs: ${JSON.stringify(filesOnFs)}`); - t.deepEqual(filesOnFs, expectedFiles, "deepEqual filesOnFs, fileNames OK"); - - const fileChecks = filesOnFs.map(async (fileName) => { - const containerFilePath = path.join(containerPkDir, fileName); - const hostFilePath = path.join(hostSourceDir, fileName); - const contentsBuffer = await Containers.pullBinaryFile( - dockerodeContainer, - containerFilePath, - ); - t.ok(contentsBuffer, `contents buffer truthy OK: ${containerFilePath}`); - t.true(contentsBuffer.length > 0, `size > 0 OK: ${containerFilePath}`); - await fs.writeFile(hostFilePath, contentsBuffer); - const { isFile, size } = await fs.stat(hostFilePath); - t.true(isFile, `isFile===true OK: ${hostFilePath}`); - t.true(size > 0, `size > 0 OK: ${hostFilePath}`); - }); - - await t.doesNotReject(Promise.all(fileChecks), "All WASM build files OK"); - - const wasmHostPath = path.join(hostSourceDir, "./hello_world.js"); - const esmRequire = esm(module, { wasm: true }); - const wasmModule = esmRequire(wasmHostPath) as HelloWorldExports; - const helloWorldOut = wasmModule.hello_world(); - t.ok(helloWorldOut, "helloWorldOut truthy OK"); - t.equal(helloWorldOut, "Hello World!", "helloWorldOut EQ Hello World! OK"); - - const greeting = wasmModule.say_hello("Peter"); - t.ok(greeting, "greeting truthy OK"); - t.equal(greeting, "Hello Peter!", "greeting EQ Hello Peter! OK"); - - t.end(); -}); diff --git a/packages/cactus-test-tooling/src/test/typescript/integration/rustc-container/rustc-container-target-nodejs.test.ts b/packages/cactus-test-tooling/src/test/typescript/integration/rustc-container/rustc-container-target-nodejs.test.ts deleted file mode 100644 index 67dafadf3e..0000000000 --- a/packages/cactus-test-tooling/src/test/typescript/integration/rustc-container/rustc-container-target-nodejs.test.ts +++ /dev/null @@ -1,136 +0,0 @@ -import path from "path"; -import "jest-extended"; -import temp from "temp"; -import fs from "fs-extra"; -import { LogLevelDesc } from "@hyperledger/cactus-common"; -import { - Containers, - RustcBuildCmd, - RustcContainer, -} from "../../../../main/typescript/public-api"; -const testCase = "compiles Rust code to NodeJS targeted .wasm"; -describe(testCase, () => { - type HelloWorldExports = { - hello_world: () => string; - say_hello: (name: string) => string; - }; - - const logLevel: LogLevelDesc = "TRACE"; - - let rustcContainer: RustcContainer; - - beforeAll(async () => { - rustcContainer = new RustcContainer({ logLevel }); - }); - - afterAll(async () => await rustcContainer.stop()); - afterAll(async () => await temp.cleanup()); - - test(testCase, async () => { - const tmpDirAffix = "cactus-test-tooling-rustc-container-test"; - temp.track(); - const hostSourceDir = await temp.mkdir(tmpDirAffix); - - const srcDir = path.join(hostSourceDir, "./src/"); - await fs.mkdir(srcDir); - - expect(rustcContainer).toBeTruthy(); - - const dockerodeContainer = await rustcContainer.start(); - expect(dockerodeContainer).toBeTruthy(); - - const containerPkDir = path.join(rustcContainer.cwd, "./pkg/"); - - const cargoTomlHostDir = path.join( - __dirname, - "../../../rust/fixtures/wasm-hello-world/", - ); - const putCargoTomlRes = await Containers.putFile({ - containerOrId: dockerodeContainer, - dstFileDir: rustcContainer.cwd, - dstFileName: "Cargo.toml", - srcFileDir: cargoTomlHostDir, - srcFileName: "Cargo.toml", - }); - expect(putCargoTomlRes); - expect(putCargoTomlRes.statusCode); - expect(putCargoTomlRes.statusCode).toEqual(200); - - const containerSrcDir = path.join(rustcContainer.cwd, "./src/"); - await Containers.exec(dockerodeContainer, ["mkdir", containerSrcDir]); - - const libRsHostDir = path.join( - __dirname, - "../../../rust/fixtures/wasm-hello-world/src/", - ); - const putLibRsRes = await Containers.putFile({ - containerOrId: dockerodeContainer, - dstFileDir: containerSrcDir, - dstFileName: "lib.rs", - srcFileDir: libRsHostDir, - srcFileName: "lib.rs", - }); - expect(putLibRsRes).toBeTruthy(); - expect(putLibRsRes.statusCode).toBeTruthy(); - expect(putLibRsRes.statusCode).toEqual(200); - - const wasmPackBuildOut = await Containers.exec( - dockerodeContainer, - RustcBuildCmd.WASM_PACK_BUILD_NODEJS, - ); - expect(wasmPackBuildOut).toBeTruthy(); - - // The list of files the wasm-pack NodeJS target produces - const expectedFiles = [ - ".gitignore", - "hello_world.d.ts", - "hello_world.js", - "hello_world_bg.wasm", - "hello_world_bg.wasm.d.ts", - "package.json", - ]; - - const filesOnFs = await Containers.ls(dockerodeContainer, containerPkDir); - expect(filesOnFs).toBeTruthy(); - expect(Array.isArray(filesOnFs)).toBe(true); - expect(filesOnFs).toEqual(expectedFiles); - - const fileChecks = filesOnFs.map(async (fileName) => { - const containerFilePath = path.join(containerPkDir, fileName); - const hostFilePath = path.join(hostSourceDir, fileName); - const contentsBuffer = await Containers.pullBinaryFile( - dockerodeContainer, - containerFilePath, - ); - await fs.writeFile(hostFilePath, contentsBuffer); - const { size } = await fs.stat(hostFilePath); - return { contentsBuffer, size }; - }); - - const fileChecksPromise = Promise.all(fileChecks); - expect(fileChecksPromise).toBeTruthy(); - expect(fileChecksPromise).toResolve(); - - const fileChecksResults = await fileChecksPromise; - expect(fileChecksResults).toBeTruthy(); - expect(fileChecksResults).toBeArrayOfSize(filesOnFs.length); - - fileChecksResults.forEach(({ contentsBuffer, size }) => { - expect(contentsBuffer).toBeTruthy(); - expect(contentsBuffer.length > 0).toBe(true); - // expect(isFile).toBe(true); - expect(size).toBeGreaterThan(0); - }); - - const wasmHostPath = path.join(hostSourceDir, "./hello_world.js"); - // eslint-disable-next-line @typescript-eslint/no-var-requires - const wasmModule = require(wasmHostPath) as HelloWorldExports; - const helloWorldOut = wasmModule.hello_world(); - expect(helloWorldOut).toBeTruthy(); - expect(helloWorldOut).toEqual("Hello World!"); - - const greeting = wasmModule.say_hello("Peter"); - expect(greeting).toBeTruthy(); - expect(greeting).toEqual("Hello Peter!"); - }); -}); diff --git a/tools/docker/rust-compiler/Dockerfile b/tools/docker/rust-compiler/Dockerfile deleted file mode 100644 index 7460e66e54..0000000000 --- a/tools/docker/rust-compiler/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM rust:1.72.0-slim-bullseye - -RUN apt update - -# wasm-pack dependencies+install -RUN apt install -y build-essential pkg-config libssl-dev -RUN cargo install --version=0.12.1 wasm-pack diff --git a/tools/docker/rust-compiler/README.md b/tools/docker/rust-compiler/README.md deleted file mode 100644 index c01a59ddf6..0000000000 --- a/tools/docker/rust-compiler/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# @hyperledger/cactus-rust-compiler - -A container image that can be used to compile Rust source code and then also -WASM pack it where necessary/applicable. - -## Table of Contents - -- [Usage](#usage) -- [Build](#build) - -## Usage - -## Build - -```sh -DOCKER_BUILDKIT=1 docker build -f ./tools/docker/rust-compiler/Dockerfile . --tag crc -```