From e76836f1942e359a605c6125b95cc7260b0adc7f Mon Sep 17 00:00:00 2001 From: HenryNguyen5 <6404866+HenryNguyen5@users.noreply.github.com> Date: Thu, 7 Mar 2024 11:37:24 -0500 Subject: [PATCH] Introduce LOOP plugin support for devspace goreleaser builds --- .goreleaser.develop.yaml | 4 ++ .goreleaser.devspace.yaml | 5 ++ .../templates/chainlink-cm.yaml | 2 +- core/chainlink.goreleaser.Dockerfile | 12 ++++ tools/bin/goreleaser_utils | 65 ++++++++++++++++++- 5 files changed, 84 insertions(+), 4 deletions(-) diff --git a/.goreleaser.develop.yaml b/.goreleaser.develop.yaml index 60949eee72e..7fbd2aa667b 100644 --- a/.goreleaser.develop.yaml +++ b/.goreleaser.develop.yaml @@ -63,6 +63,7 @@ dockers: goarch: amd64 extra_files: - tmp/linux_amd64/libs + - tmp/linux_amd64/plugins - tools/bin/ldd_fix build_flag_templates: - "--platform=linux/amd64" @@ -86,6 +87,7 @@ dockers: goarch: arm64 extra_files: - tmp/linux_arm64/libs + - tmp/linux_arm64/plugins - tools/bin/ldd_fix build_flag_templates: - "--platform=linux/arm64" @@ -109,6 +111,7 @@ dockers: goarch: amd64 extra_files: - tmp/linux_amd64/libs + - tmp/linux_amd64/plugins - tools/bin/ldd_fix build_flag_templates: - "--platform=linux/amd64" @@ -133,6 +136,7 @@ dockers: goarch: arm64 extra_files: - tmp/linux_arm64/libs + - tmp/linux_arm64/plugins - tools/bin/ldd_fix build_flag_templates: - "--platform=linux/arm64" diff --git a/.goreleaser.devspace.yaml b/.goreleaser.devspace.yaml index 8cf10a1fc88..1c6b4768d98 100644 --- a/.goreleaser.devspace.yaml +++ b/.goreleaser.devspace.yaml @@ -43,12 +43,17 @@ dockers: goarch: amd64 extra_files: - tmp/linux_amd64/libs + - tmp/linux_amd64/plugins - tools/bin/ldd_fix build_flag_templates: - "--platform=linux/amd64" - "--pull" - "--build-arg=CHAINLINK_USER=chainlink" - "--build-arg=COMMIT_SHA={{ .FullCommit }}" + - "--build-arg=CL_MEDIAN_CMD=chainlink-feeds" + - "--build-arg=CL_MERCURY_CMD=chainlink-mercury" + - "--build-arg=CL_SOLANA_CMD=chainlink-solana" + - "--build-arg=CL_STARKNET_CMD=chainlink-starknet" - "--label=org.opencontainers.image.created={{ .Date }}" - "--label=org.opencontainers.image.description={{ .Env.IMAGE_LABEL_DESCRIPTION }}" - "--label=org.opencontainers.image.licenses={{ .Env.IMAGE_LABEL_LICENSES }}" diff --git a/charts/chainlink-cluster/templates/chainlink-cm.yaml b/charts/chainlink-cluster/templates/chainlink-cm.yaml index 25deb475af2..6f8b043e3d1 100644 --- a/charts/chainlink-cluster/templates/chainlink-cm.yaml +++ b/charts/chainlink-cluster/templates/chainlink-cm.yaml @@ -68,4 +68,4 @@ data: {{ else }} {{ end }} --- -{{- end }} \ No newline at end of file +{{- end }} diff --git a/core/chainlink.goreleaser.Dockerfile b/core/chainlink.goreleaser.Dockerfile index 7774c416f0e..7dab088116e 100644 --- a/core/chainlink.goreleaser.Dockerfile +++ b/core/chainlink.goreleaser.Dockerfile @@ -16,9 +16,21 @@ RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ && rm -rf /var/lib/apt/lists/* COPY ./chainlink /usr/local/bin/ + # Copy native libs if cgo is enabled COPY ./tmp/linux_${TARGETARCH}/libs /usr/local/bin/libs +# Copy plugins and enable them +COPY ./tmp/linux_${TARGETARCH}/plugins/* /usr/local/bin/ +# Allow individual plugins to be enabled by supplying their path +ARG CL_MEDIAN_CMD +ARG CL_MERCURY_CMD +ARG CL_SOLANA_CMD +ARG CL_STARKNET_CMD +ENV CL_MEDIAN_CMD=${CL_MEDIAN_CMD} \ + CL_MERCURY_CMD=${CL_MERCURY_CMD} \ + CL_SOLANA_CMD=${CL_SOLANA_CMD} \ + CL_STARKNET_CMD=${CL_STARKNET_CMD} # Temp fix to patch correctly link the libwasmvm.so COPY ./tools/bin/ldd_fix /usr/local/bin/ldd_fix RUN chmod +x /usr/local/bin/ldd_fix diff --git a/tools/bin/goreleaser_utils b/tools/bin/goreleaser_utils index 4eb8e1acd07..08f0e0a0026 100755 --- a/tools/bin/goreleaser_utils +++ b/tools/bin/goreleaser_utils @@ -1,4 +1,6 @@ #!/usr/bin/env bash +set -x + # get machine / kernel name _get_platform() { @@ -58,19 +60,76 @@ before_hook() { cp -f "$wasmvm_lib_path_darwin_amd64" "$lib_path/darwin_amd64/libs" mkdir -p "$lib_path/darwin_arm64/libs" cp -f "$wasmvm_lib_path_darwin_arm64" "$lib_path/darwin_arm64/libs" + + # MOVE PLUGINS HERE + gobin=$(go env GOPATH)/bin + + install_local_plugins "linux" "amd64" "$gobin"/linux_amd64 + install_remote_plugins "linux" "amd64" "$gobin"/linux_amd64 + mkdir -p "$lib_path/linux_amd64/plugins" + cp "$gobin"/linux_amd64/chainlink* "$lib_path/linux_amd64/plugins" + + install_local_plugins "linux" "arm64" "$gobin"/linux_arm64 + install_remote_plugins "linux" "arm64" "$gobin"/linux_arm64 + mkdir -p "$lib_path/linux_arm64/plugins" + cp "$gobin"/linux_arm64/chainlink* "$lib_path/linux_arm64/plugins" +} + +install_local_plugins() { + local -r goos=$1 + local -r goarch=$2 + local -r gobin=$3 + + GOBIN=$gobin GOARCH=$goarch GOOS=$goos make install-medianpoc + GOBIN=$gobin GOARCH=$goarch GOOS=$goos make install-install-ocr3-capability +} + +get_remote_plugin_paths() { + plugins=( + "github.com/smartcontractkit/chainlink-solana|/pkg/solana/cmd/chainlink-solana" + "github.com/smartcontractkit/chainlink-starknet/relayer|/pkg/chainlink/cmd/chainlink-starknet" + "github.com/smartcontractkit/chainlink-feeds|/cmd/chainlink-feeds" + "github.com/smartcontractkit/chainlink-data-streams|/mercury/cmd/chainlink-mercury" + ) + + for plugin in "${plugins[@]}"; do + plugin_dep_name=$(echo "$plugin" | cut -d"|" -f1) + plugin_main=$(echo "$plugin" | cut -d"|" -f2) + + full_plugin_path=$(go list -m -f "{{.Dir}}" "$plugin_dep_name")"$plugin_main" + echo "$full_plugin_path" + done +} + +install_remote_plugins() { + local -r goos=$1 + local -r goarch=$2 + local -r gobin=$(go env GOPATH)/bin + + for plugin in $(get_remote_plugin_paths); do + GOBIN=$gobin GOARCH=$goarch GOOS=$goos go install "$plugin" + done + } # binary build post hook # moves native libraries to binary libs directory build_post_hook() { local -r dist_path=$1 - local -r lib_path=$dist_path/libs + local -r lib_dest_path=$dist_path/libs local -r platform=$2 local -r arch=$3 + local -r plugin_src_path=./tmp/${platform}_${arch}/plugins + local -r plugin_dest_path=$dist_path/plugins + # COPY NATIVE LIBRARIES HERE local -r wasmvm_lib_path=$(_get_wasmvm_lib_path "$platform" "$arch") - mkdir -p "$lib_path" - cp "$wasmvm_lib_path" "$lib_path" + mkdir -p "$lib_dest_path" + cp "$wasmvm_lib_path" "$lib_dest_path" + + # COPY PLUGINS HERE + mkdir -p "$plugin_dest_path" + cp -r "$plugin_src_path/." "$plugin_dest_path" } "$@"