diff --git a/.github/actions/run-interop-ping-test/action.yml b/.github/actions/run-interop-ping-test/action.yml index ed99658e4..544afa9d1 100644 --- a/.github/actions/run-interop-ping-test/action.yml +++ b/.github/actions/run-interop-ping-test/action.yml @@ -34,6 +34,12 @@ runs: echo "AWS_REGION=${{ inputs.aws-region }}" >> $GITHUB_ENV shell: bash + - name: If we have a secret for s3, we should push to the cache. + if: inputs.s3-access-key-id != '' && inputs.s3-secret-access-key != '' + run: | + echo "PUSH_CACHE=true" >> $GITHUB_ENV + shell: bash + - name: Configure AWS credentials for S3 build cache if: inputs.s3-access-key-id != '' && inputs.s3-secret-access-key != '' uses: aws-actions/configure-aws-credentials@v1 @@ -65,12 +71,12 @@ runs: - name: Build images working-directory: ${{ steps.find-workdir.outputs.WORK_DIR }} - run: make + run: make -j 2 shell: bash - name: Run the test working-directory: ${{ steps.find-workdir.outputs.WORK_DIR }} - run: WORKER_COUNT=2 npm run test -- --extra-version=${{ inputs.extra-versions }} --name-filter=${{ inputs.test-filter }} + run: WORKER_COUNT=4 npm run test -- --extra-version=${{ inputs.extra-versions }} --name-filter=${{ inputs.test-filter }} shell: bash - name: Print the results diff --git a/multidim-interop/Makefile b/multidim-interop/Makefile index 3e2b6d085..c0327cd08 100644 --- a/multidim-interop/Makefile +++ b/multidim-interop/Makefile @@ -13,5 +13,4 @@ $(RUST_SUBDIRS): $(NIM_SUBDIRS): $(MAKE) -C $@ - .PHONY: $(GO_SUBDIRS) $(JS_SUBDIRS) $(RUST_SUBDIRS) $(NIM_SUBDIRS) all diff --git a/multidim-interop/dockerBuildWrapper.sh b/multidim-interop/dockerBuildWrapper.sh deleted file mode 100755 index 087a4e8c9..000000000 --- a/multidim-interop/dockerBuildWrapper.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env /bin/bash - -CACHING_OPTIONS="" -# If in CI and we have a defined cache bucket, use caching -if [[ -n "${CI}" ]] && [[ -n "${AWS_BUCKET}" ]]; then - CACHING_OPTIONS="\ - --cache-to type=s3,mode=max,bucket=$AWS_BUCKET,region=$AWS_REGION,prefix=buildCache,name=$IMAGE_NAME \ - --cache-from type=s3,mode=max,bucket=$AWS_BUCKET,region=$AWS_REGION,prefix=buildCache,name=$IMAGE_NAME" -fi - -docker buildx build \ - --load \ - -t $IMAGE_NAME $CACHING_OPTIONS "$@" diff --git a/multidim-interop/go/v0.22/Dockerfile b/multidim-interop/go/v0.22/Dockerfile index 7f4da95bb..1da43fff4 100644 --- a/multidim-interop/go/v0.22/Dockerfile +++ b/multidim-interop/go/v0.22/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -FROM golang:1.19-alpine +FROM golang:1.19-alpine AS builder WORKDIR /app @@ -12,4 +12,7 @@ COPY *.go ./ RUN go build -o /testplan +FROM alpine:3.17 +COPY --from=builder /testplan /testplan + ENTRYPOINT [ "/testplan"] \ No newline at end of file diff --git a/multidim-interop/go/v0.22/Makefile b/multidim-interop/go/v0.22/Makefile index 9f0d96c70..7f2e637e0 100644 --- a/multidim-interop/go/v0.22/Makefile +++ b/multidim-interop/go/v0.22/Makefile @@ -1,11 +1,26 @@ -image_name := go-v0.22 +SHELL := /usr/bin/env bash +imageName := go-v0.22 +cacheKey=${shell find . -type f | sort | grep -v image.json | tr "\n" " " | xargs ../../helpers/hashFiles.sh} +shouldUseCache := ${shell IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/shouldUseCache.sh} + +all: image.json + +ifneq (${shouldUseCache},) +# We have a cached image, let's use it +image.json: + CACHE_KEY=${cacheKey} IMAGE_NAME=${imageName} ../../helpers/tryLoadCache.sh + docker image inspect ${imageName} -f "{{.Id}}" | \ + xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ +else image.json: Dockerfile main.go go.mod go.sum - IMAGE_NAME=${image_name} ../../dockerBuildWrapper.sh . - docker image inspect ${image_name} -f "{{.Id}}" | \ + docker build -t ${imageName} . + docker image inspect ${imageName} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ + IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/maybePushCache.sh +endif .PHONY: clean clean: - rm image.json \ No newline at end of file + rm image.json diff --git a/multidim-interop/go/v0.23/Dockerfile b/multidim-interop/go/v0.23/Dockerfile index 7f4da95bb..62f43b0c6 100644 --- a/multidim-interop/go/v0.23/Dockerfile +++ b/multidim-interop/go/v0.23/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -FROM golang:1.19-alpine +FROM golang:1.19-alpine AS builder WORKDIR /app @@ -12,4 +12,7 @@ COPY *.go ./ RUN go build -o /testplan -ENTRYPOINT [ "/testplan"] \ No newline at end of file +FROM alpine:3.17 +COPY --from=builder /testplan /testplan + +ENTRYPOINT [ "/testplan"] diff --git a/multidim-interop/go/v0.23/Makefile b/multidim-interop/go/v0.23/Makefile index fce12d5e7..792ab5900 100644 --- a/multidim-interop/go/v0.23/Makefile +++ b/multidim-interop/go/v0.23/Makefile @@ -1,11 +1,27 @@ -image_name := go-v0.23 +SHELL := /usr/bin/env bash +imageName := go-v0.23 +cacheKey=${shell find . -type f | sort | grep -v image.json | tr "\n" " " | xargs ../../helpers/hashFiles.sh} +shouldUseCache := ${shell IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/shouldUseCache.sh} + +all: image.json + +ifneq (${shouldUseCache},) +# We have a cached image, let's use it +image.json: + CACHE_KEY=${cacheKey} IMAGE_NAME=${imageName} ../../helpers/tryLoadCache.sh + docker image inspect ${imageName} -f "{{.Id}}" | \ + xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ +else image.json: Dockerfile main.go go.mod go.sum - IMAGE_NAME=${image_name} ../../dockerBuildWrapper.sh . - docker image inspect ${image_name} -f "{{.Id}}" | \ + docker build -t ${imageName} . + docker image inspect ${imageName} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ + # If we're in CI, save the cache + IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/maybePushCache.sh +endif .PHONY: clean clean: - rm image.json \ No newline at end of file + rm image.json diff --git a/multidim-interop/go/v0.24/Dockerfile b/multidim-interop/go/v0.24/Dockerfile index 7f4da95bb..1da43fff4 100644 --- a/multidim-interop/go/v0.24/Dockerfile +++ b/multidim-interop/go/v0.24/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -FROM golang:1.19-alpine +FROM golang:1.19-alpine AS builder WORKDIR /app @@ -12,4 +12,7 @@ COPY *.go ./ RUN go build -o /testplan +FROM alpine:3.17 +COPY --from=builder /testplan /testplan + ENTRYPOINT [ "/testplan"] \ No newline at end of file diff --git a/multidim-interop/go/v0.24/Makefile b/multidim-interop/go/v0.24/Makefile index f9b3736e3..e2a9052d2 100644 --- a/multidim-interop/go/v0.24/Makefile +++ b/multidim-interop/go/v0.24/Makefile @@ -1,11 +1,27 @@ -image_name := go-v0.24 +SHELL := /usr/bin/env bash +imageName := go-v0.24 +cacheKey=${shell find . -type f | sort | grep -v image.json | tr "\n" " " | xargs ../../helpers/hashFiles.sh} +shouldUseCache := ${shell IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/shouldUseCache.sh} + +all: image.json + +ifneq (${shouldUseCache},) +# We have a cached image, let's use it +image.json: + CACHE_KEY=${cacheKey} IMAGE_NAME=${imageName} ../../helpers/tryLoadCache.sh + docker image inspect ${imageName} -f "{{.Id}}" | \ + xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ +else image.json: Dockerfile main.go go.mod go.sum - IMAGE_NAME=${image_name} ../../dockerBuildWrapper.sh . - docker image inspect ${image_name} -f "{{.Id}}" | \ + docker build -t ${imageName} . + docker image inspect ${imageName} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ + # If we're in CI, save the cache + IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/maybePushCache.sh +endif .PHONY: clean clean: - rm image.json \ No newline at end of file + rm image.json diff --git a/multidim-interop/go/v0.25/Makefile b/multidim-interop/go/v0.25/Makefile index 6eb6526d1..b3c3c1760 100644 --- a/multidim-interop/go/v0.25/Makefile +++ b/multidim-interop/go/v0.25/Makefile @@ -1,12 +1,25 @@ -image_name := go-v0.25 +SHELL := /usr/bin/env bash +imageName := go-v0.25 commitSha := 5741b6c9bbcc1185bdf94d816dca966b37ce61ff +cacheKey := ${commitSha} +shouldUseCache := ${shell IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/shouldUseCache.sh} all: image.json +ifneq (${shouldUseCache},) +# We have a cached image, let's use it +image.json: + CACHE_KEY=${cacheKey} IMAGE_NAME=${imageName} ../../helpers/tryLoadCache.sh + docker image inspect ${imageName} -f "{{.Id}}" | \ + xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ +else image.json: go-libp2p-${commitSha} - cd go-libp2p-${commitSha} && IMAGE_NAME=${image_name} ../../../dockerBuildWrapper.sh -f test-plans/PingDockerfile . - docker image inspect ${image_name} -f "{{.Id}}" | \ + cd go-libp2p-${commitSha} && docker build -t ${imageName} -f test-plans/PingDockerfile . + # If we're in CI, save the cache + IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/maybePushCache.sh + docker image inspect ${imageName} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ +endif go-libp2p-${commitSha}: go-libp2p-${commitSha}.zip unzip -o go-libp2p-${commitSha}.zip @@ -17,4 +30,4 @@ go-libp2p-${commitSha}.zip: clean: rm image.json rm go-libp2p-*.zip - rm -rf go-libp2p-* \ No newline at end of file + rm -rf go-libp2p-* diff --git a/multidim-interop/go/v0.26/Makefile b/multidim-interop/go/v0.26/Makefile index c14ed9357..6f5de5ea9 100644 --- a/multidim-interop/go/v0.26/Makefile +++ b/multidim-interop/go/v0.26/Makefile @@ -1,12 +1,26 @@ -image_name := go-v0.26 +SHELL := /usr/bin/env bash +imageName := go-v0.26 commitSha := 59a14cf3194d5d057c45cb1dbc7b1af3a116bc7a +cacheKey := ${commitSha} +shouldUseCache := ${shell IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/shouldUseCache.sh} all: image.json +ifneq (${shouldUseCache},) +# We have a cached image, let's use it +image.json: + echo "Using cached image ${shouldUseCache} f" + CACHE_KEY=${cacheKey} IMAGE_NAME=${imageName} ../../helpers/tryLoadCache.sh + docker image inspect ${imageName} -f "{{.Id}}" | \ + xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ +else image.json: go-libp2p-${commitSha} - cd go-libp2p-${commitSha} && IMAGE_NAME=${image_name} ../../../dockerBuildWrapper.sh -f test-plans/PingDockerfile . - docker image inspect ${image_name} -f "{{.Id}}" | \ + cd go-libp2p-${commitSha} && docker build -t ${imageName} -f test-plans/PingDockerfile . + # If we're in CI, save the cache + IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/maybePushCache.sh + docker image inspect ${imageName} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ +endif go-libp2p-${commitSha}: go-libp2p-${commitSha}.zip unzip -o go-libp2p-${commitSha}.zip @@ -17,4 +31,4 @@ go-libp2p-${commitSha}.zip: clean: rm image.json rm go-libp2p-*.zip - rm -rf go-libp2p-* \ No newline at end of file + rm -rf go-libp2p-* diff --git a/multidim-interop/helpers/buildCacheKey.sh b/multidim-interop/helpers/buildCacheKey.sh new file mode 100755 index 000000000..8cdee9bf7 --- /dev/null +++ b/multidim-interop/helpers/buildCacheKey.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env /bin/bash +set -eou pipefail +set -x + +# Assert that IMAGE_NAME is not empty +if [ -z "$IMAGE_NAME" ]; then + echo "IMAGE_NAME is not set" + exit 1 +fi + +ARCH=$(docker info -f "{{.Architecture}}") +BUILD_CACHE_KEY="$IMAGE_NAME-$CACHE_KEY-$ARCH" +echo $BUILD_CACHE_KEY diff --git a/multidim-interop/helpers/hashFiles.sh b/multidim-interop/helpers/hashFiles.sh new file mode 100755 index 000000000..c7533f09c --- /dev/null +++ b/multidim-interop/helpers/hashFiles.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env /bin/bash +set -eou pipefail + +# sort all the files passed in by name, then hash them +echo "$@" | xargs -n1 | sort | xargs sha256sum | sha256sum | sed 's/.$//' | xargs diff --git a/multidim-interop/helpers/maybePushCache.sh b/multidim-interop/helpers/maybePushCache.sh new file mode 100755 index 000000000..3596cc504 --- /dev/null +++ b/multidim-interop/helpers/maybePushCache.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env /bin/bash +set -eou pipefail +set -x + +if [[ -n "${PUSH_CACHE:-}" ]]; then + script_dir=$(dirname "$0") + BUILD_CACHE_KEY=$($script_dir/buildCacheKey.sh) + AWS_BUCKET=${AWS_BUCKET:-libp2p-by-tf-aws-bootstrap} + + docker image save $IMAGE_NAME | gzip | aws s3 cp - s3://$AWS_BUCKET/imageCache/$BUILD_CACHE_KEY.tar.gz +fi + diff --git a/multidim-interop/helpers/shouldUseCache.sh b/multidim-interop/helpers/shouldUseCache.sh new file mode 100755 index 000000000..a4b28c2f0 --- /dev/null +++ b/multidim-interop/helpers/shouldUseCache.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env /bin/bash +set -eou pipefail +set -x + +# shouldUseCache.sh - Returns exit code 0 if we don't have the image locally and we have a cache hit. + +AWS_BUCKET=${AWS_BUCKET:-libp2p-by-tf-aws-bootstrap} + +script_dir=$(dirname "$0") +BUILD_CACHE_KEY=$($script_dir/buildCacheKey.sh) + +# If we already have this image name in docker, lets not use the cache, since a +# small change will probaby be faster than refetch the cache +if docker image inspect $IMAGE_NAME -f "{{.Id}}" &> /dev/null; then + exit 1; +fi + +curl --fail --head https://s3.amazonaws.com/$AWS_BUCKET/imageCache/$BUILD_CACHE_KEY.tar.gz &> /dev/null +# We need to echo something so that Make sees this as a target +echo $BUILD_CACHE_KEY diff --git a/multidim-interop/helpers/tryLoadCache.sh b/multidim-interop/helpers/tryLoadCache.sh new file mode 100755 index 000000000..c6ea4ea43 --- /dev/null +++ b/multidim-interop/helpers/tryLoadCache.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env /bin/bash +set -eou pipefail +set -x + +script_dir=$(dirname "$0") +BUILD_CACHE_KEY=$($script_dir/buildCacheKey.sh) +AWS_BUCKET=${AWS_BUCKET:-libp2p-by-tf-aws-bootstrap} + + +curl https://s3.amazonaws.com/$AWS_BUCKET/imageCache/$BUILD_CACHE_KEY.tar.gz \ + | docker image load && \ + exit 0 \ + || exit 1 diff --git a/multidim-interop/js/.gitignore b/multidim-interop/js/.gitignore new file mode 100644 index 000000000..d3d02c1fc --- /dev/null +++ b/multidim-interop/js/.gitignore @@ -0,0 +1 @@ +*-image.json diff --git a/multidim-interop/js/v0.41/ChromiumDockerfile b/multidim-interop/js/v0.41/ChromiumDockerfile index de8c51bd0..c522c85db 100644 --- a/multidim-interop/js/v0.41/ChromiumDockerfile +++ b/multidim-interop/js/v0.41/ChromiumDockerfile @@ -1,22 +1,6 @@ # syntax=docker/dockerfile:1 -FROM mcr.microsoft.com/playwright +ARG BASE_IMAGE +FROM $BASE_IMAGE -WORKDIR /app - - -COPY package*.json . - -RUN npm ci - -# Install browsers -RUN ./node_modules/.bin/playwright install - -COPY tsconfig.json . -COPY .aegir.js . -COPY test ./test -COPY src ./src - -RUN npm run build - -ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "browser" ] \ No newline at end of file +ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "browser" ] diff --git a/multidim-interop/js/v0.41/Dockerfile b/multidim-interop/js/v0.41/Dockerfile index cadf6681d..4c8d3a507 100644 --- a/multidim-interop/js/v0.41/Dockerfile +++ b/multidim-interop/js/v0.41/Dockerfile @@ -1,12 +1,16 @@ # syntax=docker/dockerfile:1 -FROM node:18 +# Using playwright so that we have the same base across NodeJS + Browser tests +FROM mcr.microsoft.com/playwright WORKDIR /app -COPY package*.json . +COPY package*.json ./ RUN npm ci +# Install browsers, Needed for the browser tests, but we do it here so we have the same base +RUN ./node_modules/.bin/playwright install + COPY tsconfig.json . COPY .aegir.js . COPY test ./test @@ -14,4 +18,4 @@ COPY src ./src RUN npm run build -ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "node" ] \ No newline at end of file +ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "node" ] diff --git a/multidim-interop/js/v0.41/Makefile b/multidim-interop/js/v0.41/Makefile index a186017fc..cfb871e4a 100644 --- a/multidim-interop/js/v0.41/Makefile +++ b/multidim-interop/js/v0.41/Makefile @@ -1,19 +1,18 @@ -image_name := js-v0.21 +imageName := js-v0.41 TEST_SOURCES := $(wildcard test/*.ts) -all: chromium-image.json node-image.json +all: node-${imageName}-image.json chromium-${imageName}-image.json -chromium-image.json: ChromiumDockerfile $(TEST_SOURCES) package.json package-lock.json .aegir.js - IMAGE_NAME=chromium-${image_name} ../../dockerBuildWrapper.sh -f ChromiumDockerfile . - docker image inspect chromium-${image_name} -f "{{.Id}}" | \ - xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ -node-image.json: Dockerfile $(TEST_SOURCES) package.json package-lock.json .aegir.js - IMAGE_NAME=node-${image_name} ../../dockerBuildWrapper.sh -f Dockerfile . - docker image inspect node-${image_name} -f "{{.Id}}" | \ +node-${imageName}-image.json: Dockerfile $(TEST_SOURCES) package.json package-lock.json .aegir.js build.ts + PATH=$$PATH:../../node_modules/.bin ts-node-esm --skipProject -O '{"module":"es2022"}' ./build.ts node-${imageName} + +chromium-${imageName}-image.json: ChromiumDockerfile $(TEST_SOURCES) node-${imageName}-image.json + docker build -t chromium-${imageName} -f ChromiumDockerfile --build-arg="BASE_IMAGE=node-${imageName}" . + docker image inspect chromium-${imageName} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ .PHONY: clean clean: - rm *image.json \ No newline at end of file + rm *image.json diff --git a/multidim-interop/js/v0.41/build.ts b/multidim-interop/js/v0.41/build.ts new file mode 100755 index 000000000..e83ef70b1 --- /dev/null +++ b/multidim-interop/js/v0.41/build.ts @@ -0,0 +1,37 @@ +import { execSync } from 'child_process'; +import * as fs from 'fs'; + +const cacheKey = execSync('find . -type f | sort | grep -v image.json | grep -v ./dist/ | tr "\n" " " | xargs ../../helpers/hashFiles.sh').toString().trim(); + +function shouldUseCache(imageName: string): boolean { + try { + execSync(`IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/shouldUseCache.sh`, { stdio: 'inherit' }); + return true; + } catch (e) { + return false; + } +} + +function buildImage(imageName: string, dockerfile: string) { + if (shouldUseCache(imageName)) { + console.log('Using cache'); + execSync(`CACHE_KEY=${cacheKey} IMAGE_NAME=${imageName} ../../helpers/tryLoadCache.sh`, { stdio: 'inherit' }); + } else { + execSync(`docker build -t ${imageName} -f ${dockerfile} .`, { stdio: 'inherit' }); + execSync(`IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/maybePushCache.sh`, { stdio: 'inherit' }); + } + + const imageHash = execSync(`docker image inspect ${imageName} -f "{{.Id}}"`).toString().trim(); + fs.writeFileSync(`${imageName}-image.json`, JSON.stringify({ imageID: imageHash })); +} + +function main(imageName: string, dockerfile: string = 'Dockerfile') { + buildImage(imageName, dockerfile); +} + +const args = process.argv.slice(2); +const imageName = args[0]; +const dockerfile = args[1]; +main(imageName, dockerfile); + +export {} diff --git a/multidim-interop/js/v0.42/ChromiumDockerfile b/multidim-interop/js/v0.42/ChromiumDockerfile index de8c51bd0..c522c85db 100644 --- a/multidim-interop/js/v0.42/ChromiumDockerfile +++ b/multidim-interop/js/v0.42/ChromiumDockerfile @@ -1,22 +1,6 @@ # syntax=docker/dockerfile:1 -FROM mcr.microsoft.com/playwright +ARG BASE_IMAGE +FROM $BASE_IMAGE -WORKDIR /app - - -COPY package*.json . - -RUN npm ci - -# Install browsers -RUN ./node_modules/.bin/playwright install - -COPY tsconfig.json . -COPY .aegir.js . -COPY test ./test -COPY src ./src - -RUN npm run build - -ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "browser" ] \ No newline at end of file +ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "browser" ] diff --git a/multidim-interop/js/v0.42/Dockerfile b/multidim-interop/js/v0.42/Dockerfile index cadf6681d..4c8d3a507 100644 --- a/multidim-interop/js/v0.42/Dockerfile +++ b/multidim-interop/js/v0.42/Dockerfile @@ -1,12 +1,16 @@ # syntax=docker/dockerfile:1 -FROM node:18 +# Using playwright so that we have the same base across NodeJS + Browser tests +FROM mcr.microsoft.com/playwright WORKDIR /app -COPY package*.json . +COPY package*.json ./ RUN npm ci +# Install browsers, Needed for the browser tests, but we do it here so we have the same base +RUN ./node_modules/.bin/playwright install + COPY tsconfig.json . COPY .aegir.js . COPY test ./test @@ -14,4 +18,4 @@ COPY src ./src RUN npm run build -ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "node" ] \ No newline at end of file +ENTRYPOINT [ "npm", "test", "--", "--build", "false", "--types", "false", "-t", "node" ] diff --git a/multidim-interop/js/v0.42/Makefile b/multidim-interop/js/v0.42/Makefile index 3234688fd..e2a1b9fc6 100644 --- a/multidim-interop/js/v0.42/Makefile +++ b/multidim-interop/js/v0.42/Makefile @@ -1,19 +1,18 @@ -image_name := js-v0.42 +imageName := js-v0.42 TEST_SOURCES := $(wildcard test/*.ts) -all: chromium-image.json node-image.json +all: node-${imageName}-image.json chromium-${imageName}-image.json -chromium-image.json: ChromiumDockerfile $(TEST_SOURCES) package.json package-lock.json .aegir.js - IMAGE_NAME=chromium-${image_name} ../../dockerBuildWrapper.sh -f ChromiumDockerfile . - docker image inspect chromium-${image_name} -f "{{.Id}}" | \ - xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ -node-image.json: Dockerfile $(TEST_SOURCES) package.json package-lock.json .aegir.js - IMAGE_NAME=node-${image_name} ../../dockerBuildWrapper.sh -f Dockerfile . - docker image inspect node-${image_name} -f "{{.Id}}" | \ +node-${imageName}-image.json: Dockerfile $(TEST_SOURCES) package.json package-lock.json .aegir.js build.ts + PATH=$$PATH:../../node_modules/.bin ts-node-esm --skipProject -O '{"module":"es2022"}' ./build.ts node-${imageName} + +chromium-${imageName}-image.json: ChromiumDockerfile $(TEST_SOURCES) node-${imageName}-image.json + docker build -t chromium-${imageName} -f ChromiumDockerfile --build-arg="BASE_IMAGE=node-${imageName}" . + docker image inspect chromium-${imageName} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ .PHONY: clean clean: - rm *image.json \ No newline at end of file + rm *image.json diff --git a/multidim-interop/js/v0.42/build.ts b/multidim-interop/js/v0.42/build.ts new file mode 100755 index 000000000..e83ef70b1 --- /dev/null +++ b/multidim-interop/js/v0.42/build.ts @@ -0,0 +1,37 @@ +import { execSync } from 'child_process'; +import * as fs from 'fs'; + +const cacheKey = execSync('find . -type f | sort | grep -v image.json | grep -v ./dist/ | tr "\n" " " | xargs ../../helpers/hashFiles.sh').toString().trim(); + +function shouldUseCache(imageName: string): boolean { + try { + execSync(`IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/shouldUseCache.sh`, { stdio: 'inherit' }); + return true; + } catch (e) { + return false; + } +} + +function buildImage(imageName: string, dockerfile: string) { + if (shouldUseCache(imageName)) { + console.log('Using cache'); + execSync(`CACHE_KEY=${cacheKey} IMAGE_NAME=${imageName} ../../helpers/tryLoadCache.sh`, { stdio: 'inherit' }); + } else { + execSync(`docker build -t ${imageName} -f ${dockerfile} .`, { stdio: 'inherit' }); + execSync(`IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/maybePushCache.sh`, { stdio: 'inherit' }); + } + + const imageHash = execSync(`docker image inspect ${imageName} -f "{{.Id}}"`).toString().trim(); + fs.writeFileSync(`${imageName}-image.json`, JSON.stringify({ imageID: imageHash })); +} + +function main(imageName: string, dockerfile: string = 'Dockerfile') { + buildImage(imageName, dockerfile); +} + +const args = process.argv.slice(2); +const imageName = args[0]; +const dockerfile = args[1]; +main(imageName, dockerfile); + +export {} diff --git a/multidim-interop/js/v0.42/package.json b/multidim-interop/js/v0.42/package.json index 936c7f8c2..bc873976f 100644 --- a/multidim-interop/js/v0.42/package.json +++ b/multidim-interop/js/v0.42/package.json @@ -37,4 +37,4 @@ "standard": "^17.0.0", "typescript": "^4.9.4" } -} \ No newline at end of file +} diff --git a/multidim-interop/nim/v1.0/Makefile b/multidim-interop/nim/v1.0/Makefile index 8a7891fa6..b86efcfa4 100644 --- a/multidim-interop/nim/v1.0/Makefile +++ b/multidim-interop/nim/v1.0/Makefile @@ -1,12 +1,27 @@ -image_name := nim-v1.0 +SHELL := /usr/bin/env bash +imageName := nim-v1.0 commitSha := 408dcf12bdf44dcd6f9021a6c795c472679d6d02 +cacheKey := ${commitSha} +shouldUseCache := ${shell IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/shouldUseCache.sh} all: image.json +ifneq (${shouldUseCache},) +# We have a cached image, let's use it +image.json: + echo "Using cached image ${shouldUseCache} f" + CACHE_KEY=${cacheKey} IMAGE_NAME=${imageName} ../../helpers/tryLoadCache.sh + docker image inspect ${imageName} -f "{{.Id}}" | \ + xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ +else image.json: main.nim nim-libp2p Dockerfile - IMAGE_NAME=${image_name} ../../dockerBuildWrapper.sh . - docker image inspect ${image_name} -f "{{.Id}}" | \ + docker build -t ${imageName} . + docker image inspect ${imageName} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ + # If we're in CI, save the cache + IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/maybePushCache.sh +endif + main.nim: ../mainv1.nim cp ../mainv1.nim main.nim diff --git a/multidim-interop/rust/v0.48/Makefile b/multidim-interop/rust/v0.48/Makefile index a461d1f60..f765c731b 100644 --- a/multidim-interop/rust/v0.48/Makefile +++ b/multidim-interop/rust/v0.48/Makefile @@ -1,12 +1,26 @@ -image_name := rust-v0.48 +SHELL := /usr/bin/env bash +imageName := rust-v0.48 commitSha := 7b3047d6d05d599f11f05938d4257e70de66ac12 +cacheKey := ${commitSha} +shouldUseCache := ${shell IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/shouldUseCache.sh} all: image.json +ifneq (${shouldUseCache},) +# We have a cached image, let's use it +image.json: + echo "Using cached image ${shouldUseCache} f" + CACHE_KEY=${cacheKey} IMAGE_NAME=${imageName} ../../helpers/tryLoadCache.sh + docker image inspect ${imageName} -f "{{.Id}}" | \ + xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ +else image.json: rust-libp2p-${commitSha} - cd rust-libp2p-${commitSha} && IMAGE_NAME=${image_name} ../../../dockerBuildWrapper.sh -f interop-tests/Dockerfile . - docker image inspect ${image_name} -f "{{.Id}}" | \ + cd rust-libp2p-${commitSha} && docker buildx build --load -f interop-tests/Dockerfile -t ${imageName} . + docker image inspect ${imageName} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ + # If we're in CI, save the cache + IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/maybePushCache.sh +endif rust-libp2p-${commitSha}: rust-libp2p-${commitSha}.zip unzip -o rust-libp2p-${commitSha}.zip diff --git a/multidim-interop/rust/v0.49/Makefile b/multidim-interop/rust/v0.49/Makefile index 9029e172b..69af99f4a 100644 --- a/multidim-interop/rust/v0.49/Makefile +++ b/multidim-interop/rust/v0.49/Makefile @@ -1,12 +1,26 @@ -image_name := rust-v0.49 +SHELL := /usr/bin/env bash +imageName := rust-v0.49 commitSha := 582c84043050eb0dd6e52d1bd0527175181d41cb +cacheKey := ${commitSha} +shouldUseCache := ${shell IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/shouldUseCache.sh} all: image.json +ifneq (${shouldUseCache},) +# We have a cached image, let's use it +image.json: + echo "Using cached image ${shouldUseCache} f" + CACHE_KEY=${cacheKey} IMAGE_NAME=${imageName} ../../helpers/tryLoadCache.sh + docker image inspect ${imageName} -f "{{.Id}}" | \ + xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ +else image.json: rust-libp2p-${commitSha} - cd rust-libp2p-${commitSha} && IMAGE_NAME=${image_name} ../../../dockerBuildWrapper.sh -f interop-tests/Dockerfile . - docker image inspect ${image_name} -f "{{.Id}}" | \ + cd rust-libp2p-${commitSha} && docker buildx build --load -f interop-tests/Dockerfile -t ${imageName} . + docker image inspect ${imageName} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ + # If we're in CI, save the cache + IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/maybePushCache.sh +endif rust-libp2p-${commitSha}: rust-libp2p-${commitSha}.zip unzip -o rust-libp2p-${commitSha}.zip diff --git a/multidim-interop/rust/v0.50/Makefile b/multidim-interop/rust/v0.50/Makefile index 2cc4892f7..5a15ed297 100644 --- a/multidim-interop/rust/v0.50/Makefile +++ b/multidim-interop/rust/v0.50/Makefile @@ -1,12 +1,27 @@ -image_name := rust-v0.50 +SHELL := /usr/bin/env bash +imageName := rust-v0.50 commitSha := beb66b5832384d9b813fcbf1f0fa01e6a64a9c5f +cacheKey := ${commitSha} +shouldUseCache := ${shell IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/shouldUseCache.sh} all: image.json +ifneq (${shouldUseCache},) +# We have a cached image, let's use it +image.json: + echo "Using cached image ${shouldUseCache} f" + CACHE_KEY=${cacheKey} IMAGE_NAME=${imageName} ../../helpers/tryLoadCache.sh + docker image inspect ${imageName} -f "{{.Id}}" | \ + xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ +else image.json: rust-libp2p-${commitSha} - cd rust-libp2p-${commitSha} && IMAGE_NAME=${image_name} ../../../dockerBuildWrapper.sh -f interop-tests/Dockerfile . - docker image inspect ${image_name} -f "{{.Id}}" | \ + cd rust-libp2p-${commitSha} && docker buildx build --load -f interop-tests/Dockerfile -t ${imageName} . + docker image inspect ${imageName} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ + # If we're in CI, save the cache + IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/maybePushCache.sh +endif + rust-libp2p-${commitSha}: rust-libp2p-${commitSha}.zip unzip -o rust-libp2p-${commitSha}.zip diff --git a/multidim-interop/rust/v0.51/Makefile b/multidim-interop/rust/v0.51/Makefile index 652370c79..b80058078 100644 --- a/multidim-interop/rust/v0.51/Makefile +++ b/multidim-interop/rust/v0.51/Makefile @@ -1,12 +1,27 @@ -image_name := rust-v0.51 +SHELL := /usr/bin/env bash +imageName := rust-v0.51 commitSha := 1a9cf4f7760724032b729c43165716c7ecd842ad +cacheKey := ${commitSha} +shouldUseCache := ${shell IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/shouldUseCache.sh} all: image.json +ifneq (${shouldUseCache},) +# We have a cached image, let's use it +image.json: + echo "Using cached image ${shouldUseCache} f" + CACHE_KEY=${cacheKey} IMAGE_NAME=${imageName} ../../helpers/tryLoadCache.sh + docker image inspect ${imageName} -f "{{.Id}}" | \ + xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ +else image.json: rust-libp2p-${commitSha} - cd rust-libp2p-${commitSha} && IMAGE_NAME=${image_name} ../../../dockerBuildWrapper.sh -f interop-tests/Dockerfile . - docker image inspect ${image_name} -f "{{.Id}}" | \ + cd rust-libp2p-${commitSha} && docker buildx build --load -f interop-tests/Dockerfile -t ${imageName} . + docker image inspect ${imageName} -f "{{.Id}}" | \ xargs -I {} echo "{\"imageID\": \"{}\"}" > $@ + # If we're in CI, save the cache + IMAGE_NAME=${imageName} CACHE_KEY=${cacheKey} ../../helpers/maybePushCache.sh +endif + rust-libp2p-${commitSha}: rust-libp2p-${commitSha}.zip unzip -o rust-libp2p-${commitSha}.zip diff --git a/multidim-interop/src/compose-runner.ts b/multidim-interop/src/compose-runner.ts index 2ad9982d0..79b33515a 100644 --- a/multidim-interop/src/compose-runner.ts +++ b/multidim-interop/src/compose-runner.ts @@ -8,6 +8,7 @@ import { ComposeSpecification, PropertiesServices } from "../compose-spec/compos import { stringify } from 'yaml'; const exec = util.promisify(execStd); +const timeoutSecs = 3 * 60 export type RunOpts = { up: { @@ -31,8 +32,10 @@ export async function run(namespace: string, compose: ComposeSpecification, opts } await fs.mkdir(dir, { recursive: true }) - // Create compose.yaml file - await fs.writeFile(path.join(dir, "compose.yaml"), stringify(compose)) + // Create compose.yaml file. + // Some docker compose environments don't like the name field to have special characters + const sanitizedComposeName = compose?.name.replace(/[^a-zA-Z0-9_-]/g, "_") + await fs.writeFile(path.join(dir, "compose.yaml"), stringify({...compose, name: sanitizedComposeName})) const upFlags: Array = [] if (opts.up.exitCodeFrom) { @@ -43,14 +46,11 @@ export async function run(namespace: string, compose: ComposeSpecification, opts } try { - const timeoutSecs = 3 * 60 - let timeoutId - const { stdout, stderr } = - (await Promise.race([ - exec(`docker compose -f ${path.join(dir, "compose.yaml")} up ${upFlags.join(" ")}`), - // Timeout - uses any type because this will only reject the promise. - new Promise((resolve, reject) => { timeoutId = setTimeout(() => reject("Timeout"), 1000 * timeoutSecs) }) - ])) + const timeoutId = setTimeout(() => controller.abort(), 1000 * timeoutSecs) + + const controller = new AbortController(); + const { signal } = controller; + const { stdout, stderr } = await exec(`docker compose -f ${path.join(dir, "compose.yaml")} up ${upFlags.join(" ")}`, { signal }) clearTimeout(timeoutId) const testResults = stdout.match(/.*dialer.*({.*)/) if (testResults === null || testResults.length < 2) { @@ -69,4 +69,4 @@ export async function run(namespace: string, compose: ComposeSpecification, opts } await fs.rm(dir, { recursive: true, force: true }) } -} \ No newline at end of file +} diff --git a/multidim-interop/src/generator.ts b/multidim-interop/src/generator.ts index 1d3986920..90b363cda 100644 --- a/multidim-interop/src/generator.ts +++ b/multidim-interop/src/generator.ts @@ -172,4 +172,4 @@ function buildSpec(containerImages: { [key: string]: string }, { name, dialerID, function normalizeTransport(transport: string | { name: string, onlyDial: boolean }): { name: string, onlyDial: boolean } { return typeof transport === "string" ? { name: transport, onlyDial: false } : transport -} \ No newline at end of file +} diff --git a/multidim-interop/versions.ts b/multidim-interop/versions.ts index 1f1c4bae1..f516996b2 100644 --- a/multidim-interop/versions.ts +++ b/multidim-interop/versions.ts @@ -6,11 +6,11 @@ import rustv048 from "./rust/v0.48/image.json" import rustv049 from "./rust/v0.49/image.json" import rustv050 from "./rust/v0.50/image.json" import rustv051 from "./rust/v0.51/image.json" -import jsV041 from "./js/v0.41/node-image.json" -import jsV042 from "./js/v0.42/node-image.json" +import jsV041 from "./js/v0.41/node-js-v0.41-image.json" +import jsV042 from "./js/v0.42/node-js-v0.42-image.json" import nimv10 from "./nim/v1.0/image.json" -import chromiumJsV041 from "./js/v0.41/chromium-image.json" -import chromiumJsV042 from "./js/v0.42/chromium-image.json" +import chromiumJsV041 from "./js/v0.41/chromium-js-v0.41-image.json" +import chromiumJsV042 from "./js/v0.42/chromium-js-v0.42-image.json" export type Version = { id: string,