Skip to content

Commit

Permalink
fix: goreleaser develop build for local and CI (#11847)
Browse files Browse the repository at this point in the history
* add updated goreleaser templates

* update zig 0.11.0

* update goreleaser develop

* add back ldflags and rename goreleaser config file

* update goreleaser build gha workflow and pin new versions

* add back pre/post hooks and updated goreleaser Dockerfile to include LOOP plugins

* comment out integration-tests

* add back goreleaser_wrapper

* fix path in goreleaser_utils

* add multi-line json output support

* save

* revert everthing and add go mod tidy

* revert zig and goreleaser config

* update

* zig 0.10.1

* update go.mod go version

* add -shared in goreleaser

* use zig 0.11.0 and update bash fail

* add to cc

* update name

* test

* test

* add LD_LIBRARY_PATH in dockerfile

* add _transform_path func

* fix post-hook cp

* remove post hooks

* use zig

* use older zig version

* try zig 0.12.0-dev

* add back posthook

* use zig 0.10.1 again

* update go.mod to 1.21.5

* try older zig version

* another older zig version

* add ldd_fix script with patchelf

* uncomment

* add comments and remove unnecessary

* update go.mod version

* update go.mod to 1.21.7 for core/scripts

* update all go.mod to 1.21.7 and remove artifact outputs
  • Loading branch information
momentmaker authored Feb 20, 2024
1 parent 3aa93b2 commit b588371
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 27 deletions.
15 changes: 10 additions & 5 deletions .github/actions/goreleaser-build-sign-publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ description: A composite action that allows building and publishing signed chain
inputs:
goreleaser-version:
description: The goreleaser version
default: 1.15.2
default: 1.23.0
required: false
goreleaser-key:
description: The goreleaser key
required: false
zig-version:
description: The zig version
default: 0.10.1
required: false
cosign-version:
description: The cosign version
default: v1.13.1
default: v2.2.2
required: false
macos-sdk-dir:
description: The macos sdk directory
default: MacOSX12.3.sdk
required: false
# publising inputs
# publishing inputs
enable-docker-publish:
description: Enable publishing of docker images / manifests
default: "true"
Expand Down Expand Up @@ -75,16 +78,18 @@ runs:
- name: Setup goreleaser
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
with:
distribution: goreleaser
distribution: goreleaser-pro
install-only: true
version: ${{ inputs.goreleaser-version }}
env:
GORELEASER_KEY: ${{ inputs.goreleaser-key }}
- name: Setup zig
uses: goto-bus-stop/setup-zig@7ab2955eb728f5440978d5824358023be3a2802d # v2.2.0
with:
version: ${{ inputs.zig-version }}
- name: Setup cosign
if: inputs.enable-cosign == 'true'
uses: sigstore/cosign-installer@11086d25041f77fe8fe7b9ea4e48e3b9192b8f19 # v3.1.2
uses: sigstore/cosign-installer@9614fae9e5c5eddabb09f90a270fcb487c9f7149 # v3.3.0
with:
cosign-release: ${{ inputs.cosign-version }}
- name: Login to docker registry
Expand Down
4 changes: 1 addition & 3 deletions .github/actions/goreleaser-build-sign-publish/action_utils
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
set -x
set -euo pipefail

ENABLE_COSIGN=${ENABLE_COSIGN:-false}
ENABLE_GORELEASER_SNAPSHOT=${ENABLE_GORELEASER_SNAPSHOT:-false}
Expand Down Expand Up @@ -70,9 +71,6 @@ goreleaser_release() {
rm -rf cosign.pub
rm -rf cosign.key
fi

echo "metadata=$(cat dist/metadata.json)" >> "$GITHUB_OUTPUT"
echo "artifacts=$(cat dist/artifacts.json)" >> "$GITHUB_OUTPUT"
}

"$@"
5 changes: 3 additions & 2 deletions .github/workflows/goreleaser-build-publish-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
enable-goreleaser-snapshot: "true"
goreleaser-exec: ./tools/bin/goreleaser_wrapper
goreleaser-config: .goreleaser.develop.yaml
# ISSUE: https://github.com/golang/go/issues/52690
zig-version: 0.11.0-dev.3380+7e0a02ee2 # TODO: update action to v0.11.x once released
goreleaser-key: ${{ secrets.GORELEASER_KEY }}
zig-version: 0.11.0
- name: Collect Metrics
if: always()
id: collect-gha-metrics
Expand All @@ -46,6 +46,7 @@ jobs:
hostname: ${{ secrets.GRAFANA_INTERNAL_HOST }}
this-job-name: push-chainlink-develop-goreleaser
continue-on-error: true

mercury-e2e-tests:
needs: [push-chainlink-develop-goreleaser]
runs-on:
Expand Down
12 changes: 5 additions & 7 deletions .goreleaser.develop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:

before:
hooks:
- go mod tidy
- ./tools/bin/goreleaser_utils before_hook

# See https://goreleaser.com/customization/build/
Expand Down Expand Up @@ -62,6 +63,7 @@ dockers:
goarch: amd64
extra_files:
- tmp/linux_amd64/libs
- tools/bin/ldd_fix
build_flag_templates:
- "--platform=linux/amd64"
- "--pull"
Expand All @@ -84,6 +86,7 @@ dockers:
goarch: arm64
extra_files:
- tmp/linux_arm64/libs
- tools/bin/ldd_fix
build_flag_templates:
- "--platform=linux/arm64"
- "--pull"
Expand All @@ -106,6 +109,7 @@ dockers:
goarch: amd64
extra_files:
- tmp/linux_amd64/libs
- tools/bin/ldd_fix
build_flag_templates:
- "--platform=linux/amd64"
- "--pull"
Expand All @@ -129,6 +133,7 @@ dockers:
goarch: arm64
extra_files:
- tmp/linux_arm64/libs
- tools/bin/ldd_fix
build_flag_templates:
- "--platform=linux/arm64"
- "--pull"
Expand Down Expand Up @@ -170,13 +175,6 @@ docker_signs:
- artifacts: all
stdin: "{{ .Env.COSIGN_PASSWORD }}"

archives:
- rlcp: true
files:
- src: tmp/{{ .Os }}_{{ .Arch }}/libs/*
dst: libs
strip_parent: true

checksum:
name_template: "checksums.txt"

Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
golang 1.21.5
golang 1.21.7
mockery 2.38.0
nodejs 16.16.0
postgres 13.3
helm 3.10.3
zig 0.10.1
zig 0.11.0
golangci-lint 1.55.2
protoc 25.1
3 changes: 2 additions & 1 deletion core/chainlink.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ RUN apt-get update && apt-get install -y ca-certificates gnupg lsb-release curl
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |tee /etc/apt/sources.list.d/pgdg.list \
&& apt-get update && apt-get install -y postgresql-client-15 \
&& apt-get clean all
&& apt-get clean all \
&& rm -rf /var/lib/apt/lists/*

COPY --from=buildgo /go/bin/chainlink /usr/local/bin/

Expand Down
13 changes: 10 additions & 3 deletions core/chainlink.goreleaser.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ FROM ubuntu:20.04
ARG CHAINLINK_USER=root
ARG TARGETARCH
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y ca-certificates gnupg lsb-release curl
RUN apt-get update && apt-get install -y ca-certificates gnupg lsb-release curl patchelf

# Install Postgres for CLI tools, needed specifically for DB backups
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |tee /etc/apt/sources.list.d/pgdg.list \
&& apt-get update && apt-get install -y postgresql-client-15 \
&& apt-get clean all
&& apt-get clean all \
&& rm -rf /var/lib/apt/lists/*

COPY . /usr/local/bin/
COPY ./chainlink /usr/local/bin/
# Copy native libs if cgo is enabled
COPY ./tmp/linux_${TARGETARCH}/libs /usr/local/bin/libs

# 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
RUN /usr/local/bin/ldd_fix
RUN apt-get remove -y patchelf

RUN if [ ${CHAINLINK_USER} != root ]; then \
useradd --uid 14933 --create-home ${CHAINLINK_USER}; \
fi
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/smartcontractkit/chainlink/core/scripts

go 1.21.3
go 1.21.7

// Make sure we're working with the latest chainlink libs
replace github.com/smartcontractkit/chainlink/v2 => ../../
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/smartcontractkit/chainlink/v2

go 1.21.3
go 1.21.7

require (
github.com/Depado/ginprom v1.8.0
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
golang 1.21.5
golang 1.21.7
k3d 5.4.6
kubectl 1.25.5
nodejs 18.13.0
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/smartcontractkit/chainlink/integration-tests

go 1.21.4
go 1.21.7

// Make sure we're working with the latest chainlink libs
replace github.com/smartcontractkit/chainlink/v2 => ../
Expand Down
27 changes: 27 additions & 0 deletions tools/bin/ldd_fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# This script is used as a temp fix the ldd linking of cosm lib for binary
# Currently there is an issue with the go linker not working with zig
# https://github.com/ziglang/zig/issues/18922

chainlink_path="/usr/local/bin/chainlink"
libs_path="/usr/local/bin/libs"

line=$(ldd ${chainlink_path} | grep "github.com/!cosm!wasm/wasmvm")

if [ -z "$line" ]; then
echo "Error: Path containing 'github.com/!cosm!wasm/wasmvm' not found in the ldd output."
exit 1
fi

path=$(echo "$line" | awk '{print $1}')

if [ -z "$path" ]; then
echo "Error: Failed to extract the path from the line."
exit 1
fi

trimmed_path=${path%.so*}.so
cosm_file=$(ls ${libs_path} | grep "\.so$" | head -n 1)

patchelf --remove-needed "${trimmed_path}" "$chainlink_path"
patchelf --add-needed "$cosm_file" "$chainlink_path"

1 comment on commit b588371

@tuwuzizaikai
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢提供代码。这是一大段配置文件和脚本,看起来是一个GitHub Actions工作流,用于构建、签名和发布Go项目。下面是对其中的修改和建议:

更新依赖版本:

将 "goreleaser" 的默认版本从 "1.15.2" 更新为 "1.23.0"。
将 "zig" 的默认版本从 "0.10.1" 更新为 "0.11.0"。
将 "cosign" 的默认版本从 "v1.13.1" 更新为 "v3.3.0"。
修复脚本:

在 .github/actions/goreleaser-build-sign-publish/action_utils 文件的开头,修复 ENABLE_COSIGN 和 ENABLE_GORELEASER_SNAPSHOT 变量的定义。可能是因为变量名没有加上 $ 符号。
删除不必要的 echo 语句,这些语句可能是误输入的。
更新工具版本:

更新 "Go" 版本至 "1.21.7"。
更新 "Zig" 版本至 "0.11.0"。
更新 "Node.js" 版本至 "18.13.0"。
更新 "PostgreSQL" 版本至 "13.3"。
修复链式删除:

在 .github/workflows/goreleaser-build-publish-develop.yml 文件中,更新 "Zig" 版本到 "0.11.0"。
删除 ".github/actions/goreleaser-build-sign-publish/action_utils" 文件中的一些无关的语句。
修复工具版本:

在 .工具版本 文件中,将 "Zig" 版本更新为 "0.11.0"。
修复 Dockerfile:

在 核心/chainlink.Dockerfile 和 核心/chainlink.goreleaser.Dockerfile 文件中,将 "PostgreSQL" 版本更新为 "15"。
删除不必要的 rm -rf 语句。
修复 go.mod 文件:

在 核心/脚本/go.mod 文件中,将 "Go" 版本更新为 "1.21.7"。
在 go.mod 文件中,将 "Go" 版本更新为 "1.21.7"。
修复集成测试版本:

在 集成测试/.工具版本 文件中,将 "Node.js" 版本更新为 "18.13.0"。
修复集成测试 go.mod 文件:

在 集成测试/go.mod 文件中,将 "Go" 版本更新为 "1.21.7"。
修复脚本:

在 工具/bin/ldd_fix 文件中,修复脚本错误,确保 chainlink_path 和 libs_path 的定义不包含空格。
请确保在应用这些更改之前备份代码,并根据您的需求进行适当的测试。希望这些建议对您有帮助!

Please sign in to comment.