From fcd033307245635b15c557bfed6bcdd61e4b1465 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Tue, 12 Sep 2023 15:21:26 -0700 Subject: [PATCH] changes --- integration-tests/Makefile | 14 ++++- integration-tests/operator_ui/README.md | 26 +++++++++ integration-tests/operator_ui/TAG | 1 + integration-tests/operator_ui/check.sh | 37 +++++++++++++ integration-tests/operator_ui/install.sh | 67 ++++++++++++++++++++++++ integration-tests/scripts/buildTests | 2 +- integration-tests/test.Dockerfile | 2 - integration-tests/tools/bin/build_abigen | 42 +++++++++++++++ integration-tests/tools/bin/ldflags | 8 +++ 9 files changed, 195 insertions(+), 4 deletions(-) create mode 100644 integration-tests/operator_ui/README.md create mode 100644 integration-tests/operator_ui/TAG create mode 100755 integration-tests/operator_ui/check.sh create mode 100755 integration-tests/operator_ui/install.sh create mode 100755 integration-tests/tools/bin/build_abigen create mode 100755 integration-tests/tools/bin/ldflags diff --git a/integration-tests/Makefile b/integration-tests/Makefile index 110c119df7..088e6c935b 100644 --- a/integration-tests/Makefile +++ b/integration-tests/Makefile @@ -6,6 +6,14 @@ LINUX=LINUX OSX=OSX WINDOWS=WIN32 OSFLAG := + +.DEFAULT_GOAL := abigen + +COMMIT_SHA ?= $(shell git rev-parse HEAD) +VERSION = $(shell cat VERSION) +GO_LDFLAGS := $(shell tools/bin/ldflags) +GOFLAGS = -ldflags "$(GO_LDFLAGS)" + ifeq ($(OS),Windows_NT) OSFLAG = $(WINDOWS) else @@ -212,4 +220,8 @@ run_test_with_local_image: build_docker_image SELECTED_NETWORKS="SIMULATED,SIMULATED_1,SIMULATED_2" \ ARGS="$(args)" \ PRODUCT=$(product) \ - ./scripts/run_product_tests \ No newline at end of file + ./scripts/run_product_tests + +.PHONY: operator-ui +operator-ui: ## Fetch the frontend + ./operator_ui/install.sh \ No newline at end of file diff --git a/integration-tests/operator_ui/README.md b/integration-tests/operator_ui/README.md new file mode 100644 index 0000000000..07bda2cd1d --- /dev/null +++ b/integration-tests/operator_ui/README.md @@ -0,0 +1,26 @@ +# Operator UI + +NOTE: If you're looking for the source of operator UI, it has now been moved to https://github.com/smartcontractkit/operator-ui + +This directory instead now as a collection of scripts for maintaining the version of operator UI to pull in when developing and building the chainlink node. + +## About + +This package is responsible for rendering the UI of the chainlink node, which allows interactions with node jobs, jobs runs, configuration and any other related tasks. + +## Installation + +### Requirements + +The `install.sh` script handles installing the specified tag of operator UI within the [tag file](./TAG). When executed, it downloads then moves the static assets of operator UI into the `core/web/assets` path. Then, when the chainlink binary is built, these assets are included into the build that gets served. + +## Updates + +### Requirements + +- gh cli ^2.15.0 https://github.com/cli/cli/releases/tag/v2.15.0 +- jq ^1.6 https://stedolan.github.io/jq/ + +The `update.sh` script will check for the latest release from the `smartcontractkit/operator-ui` repository, if the latest release is newer than the current tag, it'll update the [tag file](./TAG) with the corresponding latest tag. Checking for updates is automatically [handled by CI](../.github/workflows/operator-ui.yml), where any new detected updates will be pushed to a branch and have a PR opened against `develop`. + +See https://docs.github.com/en/rest/releases/releases#get-the-latest-release for how a latest release is determined. diff --git a/integration-tests/operator_ui/TAG b/integration-tests/operator_ui/TAG new file mode 100644 index 0000000000..e75a8c12a5 --- /dev/null +++ b/integration-tests/operator_ui/TAG @@ -0,0 +1 @@ +v0.8.0-91e5ba4 diff --git a/integration-tests/operator_ui/check.sh b/integration-tests/operator_ui/check.sh new file mode 100755 index 0000000000..614afd4b07 --- /dev/null +++ b/integration-tests/operator_ui/check.sh @@ -0,0 +1,37 @@ +#!/bin/bash +set -e + +# Dependencies: +# gh cli ^2.15.0 https://github.com/cli/cli/releases/tag/v2.15.0 +# jq ^1.6 https://stedolan.github.io/jq/ + +repo=smartcontractkit/operator-ui +gitRoot=$(git rev-parse --show-toplevel) +cd "$gitRoot/operator_ui" + +tag_file=TAG +current_tag=$(cat $tag_file) +echo "Currently pinned tag for $repo is $current_tag" + +echo "Getting latest release for tag for $repo" +release=$(gh release view -R $repo --json 'tagName,body') +latest_tag=$(echo "$release" | jq -r '.tagName') +body=$(echo "$release" | jq -r '.body') + +if [ "$current_tag" = "$latest_tag" ]; then + echo "Tag $current_tag is up to date." + exit 0 +else + echo "Tag $current_tag is out of date, updating $tag_file file to latest version..." + echo "$latest_tag" >"$tag_file" + echo "Tag updated $current_tag -> $latest_tag" + if [ "$CI" ]; then + echo "current_tag=$current_tag" >> $GITHUB_OUTPUT + echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT + # See https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md#setting-the-pull-request-body-from-a-file + body="${body//'%'/'%25'}" + body="${body//$'\n'/'%0A'}" + body="${body//$'\r'/'%0D'}" + echo "body=$body" >> $GITHUB_OUTPUT + fi +fi diff --git a/integration-tests/operator_ui/install.sh b/integration-tests/operator_ui/install.sh new file mode 100755 index 0000000000..1342f6d1be --- /dev/null +++ b/integration-tests/operator_ui/install.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +set -e + +owner=smartcontractkit +repo=operator-ui +fullRepo=${owner}/${repo} + +ccipPath=$GOPATH/pkg/mod/github.com/smartcontractkit/ccip +ccipV2=$(ls -1 $ccipPath | grep v2 | tail -n 1) + +gitRoot=$(git rev-parse --show-toplevel || pwd) +cd "$gitRoot/operator_ui" +unpack_dir="$ccipPath/$ccipV2/core/web/assets" +tag=$(cat TAG) +# Remove the version prefix "v" +strippedTag="${tag:1}" +# Taken from https://github.com/kennyp/asdf-golang/blob/master/lib/helpers.sh +msg() { + echo -e "\033[32m$1\033[39m" >&2 +} + +err() { + echo -e "\033[31m$1\033[39m" >&2 +} + +fail() { + err "$1" + exit 1 +} + +msg "Getting release $tag for $fullRepo" +# https://docs.github.com/en/rest/releases/releases#get-a-release-by-tag-name +asset_name=${owner}-${repo}-${strippedTag}.tgz +download_url=https://github.com/${fullRepo}/releases/download/${tag}/${asset_name} + +# Inspired from https://github.com/kennyp/asdf-golang/blob/master/bin/download#L29 +msg "Download URL: ${download_url}" +# Check if we're able to download first +http_code=$(curl -LIs -w '%{http_code}' -o /dev/null "$download_url") +if [ "$http_code" -eq 404 ] || [ "$http_code" -eq 403 ]; then + fail "URL: ${download_url} returned status ${http_code}" +fi +# Then go ahead if we get a success code +msg "Downloading ${fullRepo}:${tag} asset: $asset_name..." +msg "" +curl -L -o "$asset_name" "$download_url" + +msg "Unpacking asset $asset_name" +tar -xvzf "$asset_name" + +msg "" +msg "Removing old contents of $unpack_dir" +rm -rf "$unpack_dir" + +if [ ! -d "$unpack_dir" ] +then +echo "$unpack_dir folder path not present, creating $ccipPath/$ccipV2/core/web" +chmod u+rwx $ccipPath/$ccipV2/core/web +mkdir -p $unpack_dir +fi + +msg "Copying contents of package/artifacts to $unpack_dir" +cp -rf package/artifacts/. "$unpack_dir" || true + +msg "Cleaning up" +rm -r package +rm "$asset_name" diff --git a/integration-tests/scripts/buildTests b/integration-tests/scripts/buildTests index 77c1738655..8159d05f48 100755 --- a/integration-tests/scripts/buildTests +++ b/integration-tests/scripts/buildTests @@ -9,8 +9,8 @@ set -ex SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) cd "$SCRIPT_DIR"/../../ || exit 1 -make operator-ui cd ./integration-tests +make operator-ui helm repo update diff --git a/integration-tests/test.Dockerfile b/integration-tests/test.Dockerfile index b367c9b3f5..fc6eefd650 100644 --- a/integration-tests/test.Dockerfile +++ b/integration-tests/test.Dockerfile @@ -5,8 +5,6 @@ FROM ${BASE_IMAGE}:${IMAGE_VERSION} ARG SUITES=chaos migration performance reorg smoke soak benchmark COPY . testdir/ -COPY ../operator_ui testdir/operator_ui -COPY ../tools/bin testdir/tools/bin WORKDIR /go/testdir RUN /go/testdir/integration-tests/scripts/buildTests "${SUITES}" ENTRYPOINT ["/go/testdir/integration-tests/scripts/entrypoint"] diff --git a/integration-tests/tools/bin/build_abigen b/integration-tests/tools/bin/build_abigen new file mode 100755 index 0000000000..f0087c7d80 --- /dev/null +++ b/integration-tests/tools/bin/build_abigen @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# Checks that the correct abigen is installed in this directory, and installs it +# if not. + +set -e + +# Version of abigen to install. Must be run within chainlink project +GETH_VERSION=$(go list -json -m github.com/ethereum/go-ethereum | jq -r .Version) +GETH_REPO_URL="https://github.com/ethereum/go-ethereum" + +function realpath { echo $(cd $(dirname $1); pwd)/$(basename $1); } +THIS_DIR="$(realpath "$(dirname $0)")" + +NATIVE_ABIGEN_VERSION=v"$( + "$THIS_DIR/abigen" --version 2> /dev/null | \ + grep -E -o '([0-9]+\.[0-9]+\.[0-9]+)' +)" || true + +if [ "$NATIVE_ABIGEN_VERSION" == "$GETH_VERSION" ]; then + echo "Correct abigen version already installed." + exit 0 +fi + +function cleanup() { + rm -rf "$TMPDIR" +} + +trap cleanup EXIT + +TMPDIR="$(mktemp -d)" + +pushd "$TMPDIR" + +git clone --depth=1 --single-branch --branch "$GETH_VERSION" "$GETH_REPO_URL" +cd go-ethereum/cmd/abigen +go build +rm -f "$THIS_DIR/abigen" # necessary on MacOS for code signing +cp ./abigen "$THIS_DIR" + +popd + diff --git a/integration-tests/tools/bin/ldflags b/integration-tests/tools/bin/ldflags new file mode 100755 index 0000000000..e7d72818b9 --- /dev/null +++ b/integration-tests/tools/bin/ldflags @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +cd "$(dirname "$0")" + +COMMIT_SHA=${COMMIT_SHA:-$(git rev-parse HEAD)} +VERSION=${VERSION:-$(cat "../../VERSION")} + +echo "-X github.com/smartcontractkit/chainlink/v2/core/static.Version=$VERSION -X github.com/smartcontractkit/chainlink/v2/core/static.Sha=$COMMIT_SHA"