Skip to content

Commit

Permalink
[TT-1042] Add nix shell support (#898)
Browse files Browse the repository at this point in the history
* Add nix shell support

* Fix CGO issue

* Update messed up readme

* Use nix in CI

* Debug complete, only show errors again in test outputs

* cleanup helm and go mod downloads in ci

* Bump flake lock to get updated versions

* Fix go build issues by putting in the newer apple sdk by default. Does not affect other platforms
  • Loading branch information
tateexon authored Apr 9, 2024
1 parent 3bc477e commit e62deff
Show file tree
Hide file tree
Showing 15 changed files with 277 additions and 40 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake .
43 changes: 37 additions & 6 deletions .github/workflows/k8s-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,38 @@ jobs:
TEST_SUITE: local-runner
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install Nix
uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Load Nix
run: nix develop -c sh -c "go mod download"
- name: Setup environment
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-run-tests-environment@5bee84d30d90295010bda68b0cd46be3a1eea917 # v2.3.9
with:
go_mod_path: go.mod
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
QA_AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
QA_KUBECONFIG: ${{ secrets.QA_KUBECONFIG }}
go_necessary: false
- name: Run Tests
env:
LOCAL_CHARTS: true
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@ce87f8986ca18336cc5015df75916c2ec0a7c4b3 # v2.1.2
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@5bee84d30d90295010bda68b0cd46be3a1eea917 # v2.3.9
with:
cl_repo: ${{ env.CHAINLINK_IMAGE }}
cl_image_tag: ${{ env.CHAINLINK_VERSION }}
test_command_to_run: make gotestloghelper_build && unset ENV_JOB_IMAGE && helm repo update && make k8s_test_e2e_ci
test_download_vendor_packages_command: go mod download
test_command_to_run: |
unset ENV_JOB_IMAGE
nix develop -c sh -c "make k8s_test_e2e_ci"
artifacts_location: ./e2e/logs
publish_check_name: E2E Test Results
token: ${{ secrets.GITHUB_TOKEN }}
go_mod_path: go.mod
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
QA_AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
QA_KUBECONFIG: ${{ secrets.QA_KUBECONFIG }}
run_setup: false
- name: Upload test log
uses: actions/upload-artifact@v3
if: failure()
Expand All @@ -101,20 +117,35 @@ jobs:
TEST_TRIGGERED_BY: chainlink-testing-framework-remote-runner-ci
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install Nix
uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Load Nix
run: nix develop -c sh -c "go mod download"
- name: Setup environment
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-run-tests-environment@5bee84d30d90295010bda68b0cd46be3a1eea917 # v2.3.9
with:
go_mod_path: go.mod
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
QA_AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
QA_KUBECONFIG: ${{ secrets.QA_KUBECONFIG }}
go_necessary: false
- name: Run Remote Runner Tests
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@ce87f8986ca18336cc5015df75916c2ec0a7c4b3 # v2.1.2
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/run-tests@5bee84d30d90295010bda68b0cd46be3a1eea917 # v2.3.9
with:
cl_repo: ${{ env.CHAINLINK_IMAGE }}
cl_image_tag: ${{ env.CHAINLINK_VERSION }}
test_command_to_run: make gotestloghelper_build && helm repo update && make k8s_test_e2e_ci_remote_runner
test_download_vendor_packages_command: go mod download
test_command_to_run: |
nix develop -c sh -c "make k8s_test_e2e_ci_remote_runner"
artifacts_location: ./k8s/logs
publish_check_name: E2E Remote Runner Test Results
token: ${{ secrets.GITHUB_TOKEN }}
go_mod_path: go.mod
QA_AWS_REGION: ${{ secrets.QA_AWS_REGION }}
QA_AWS_ROLE_TO_ASSUME: ${{ secrets.QA_AWS_ROLE_TO_ASSUME }}
QA_KUBECONFIG: ${{ secrets.QA_KUBECONFIG }}
run_setup: false
- name: Upload test log
uses: actions/upload-artifact@v2
if: failure()
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@ jobs:
steps:
- name: Checkout the Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install Go
uses: smartcontractkit/chainlink-github-actions/chainlink-testing-framework/setup-go@00c6214deb10a3f374c6d3430c32c5202015d463 # v2.2.12
with:
test_download_vendor_packages_command: go mod download
go_mod_path: ${{ matrix.project.path }}go.mod
cache_key_id: ctf-go
cache_restore_only: 'false'
- name: Install gotestloghelper
run: make gotestloghelper_build
- name: Install Nix
uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Load Nix
run: |
nix develop -c sh -c "cd ${{ matrix.project.path }} && \
go mod download"
- name: Run Tests
run: |
PATH=$PATH:$(go env GOPATH)/bin
export PATH
set -euo pipefail
# disabled, because we want to use a multiline output of go list command
# shellcheck disable=SC2046
cd ${{ matrix.project.path }}
go test -timeout 5m -json -cover -covermode=count -coverprofile=unit-test-coverage.out $(go list ./... | grep -v /k8s/e2e/ | grep -v /k8s/examples/ | grep -v /docker/test_env) 2>&1 | tee /tmp/gotest.log | /home/runner/work/chainlink-testing-framework/chainlink-testing-framework/gotestloghelper -ci
nix develop -c sh -c "cd ${{ matrix.project.path }} && \
make test_unit"
- name: Code Coverage
uses: codecov/codecov-action@v3
with:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ k3dvolume/
charts/**/*.tgz
__debug*
# saved private chain configuration
.private_chains/*
.private_chains/*

.direnv
30 changes: 30 additions & 0 deletions .helm-repositories.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: ''
generated: '0001-01-01T00:00:00Z'
repositories:
- caFile: ''
certFile: ''
insecure_skip_tls_verify: false
keyFile: ''
name: bitnami
pass_credentials_all: false
password: ''
url: https://charts.bitnami.com/bitnami
username: ''
- caFile: ''
certFile: ''
insecure_skip_tls_verify: false
keyFile: ''
name: chainlink-qa
pass_credentials_all: false
password: ''
url: https://raw.githubusercontent.com/smartcontractkit/qa-charts/gh-pages/
username: ''
- caFile: ''
certFile: ''
insecure_skip_tls_verify: false
keyFile: ''
name: grafana
pass_credentials_all: false
password: ''
url: https://grafana.github.io/helm-charts
username: ''
7 changes: 5 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ repos:
hooks:
- name: Prettier
id: prettier
- repo: https://github.com/golangci/golangci-lint
rev: v1.54.2 # Use the version of golangci-lint you want
- repo: local
hooks:
- id: golangci-lint
name: golangci-lint
entry: golangci-lint run
language: system
types: [go]
29 changes: 14 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BIN_DIR = bin
export GOPATH ?= $(shell go env GOPATH)
export GO111MODULE ?= on
CDK8S_CLI_VERSION=2.1.48
Expand Down Expand Up @@ -30,14 +29,10 @@ tidy:
cd ./tools/gotestloghelper && go mod tidy && cd -
cd ./k8s-test-runner && go mod tidy && cd -

go_mod: tidy
.PHONY: go_mod
go_mod:
go mod download

.PHONY: install_gotestfmt
install_gotestfmt:
go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
set -euo pipefail

install_tools:
ifeq ($(OSFLAG),$(WINDOWS))
echo "If you are running windows and know how to install what is needed, please contribute by adding it here!"
Expand Down Expand Up @@ -80,11 +75,11 @@ docker_prune:
compile_contracts:
python3 ./utils/compile_contracts.py

test_unit: install_gotestfmt
go test -json -cover -covermode=count -coverprofile=unit-test-coverage.out ./client ./gauntlet ./testreporters ./k8s/config ./utils/osutil 2 2>&1 | tee /tmp/gotest.log | gotestfmt
test_unit: go_mod
go test -timeout 5m -json -cover -covermode=count -coverprofile=unit-test-coverage.out $(shell go list ./... | grep -v /k8s/e2e/ | grep -v /k8s/examples/ | grep -v /docker/test_env) 2>&1 | tee /tmp/gotest.log | gotestloghelper -ci

test_docker: install_gotestfmt
go test -timeout 20m -json -failfast -parallel 3 -cover -covermode=atomic -coverprofile=unit-test-coverage.out ./docker/test_env 2>&1 | tee /tmp/gotest.log | gotestfmt
test_docker: go_mod
go test -timeout 20m -json -failfast -parallel 3 -cover -covermode=atomic -coverprofile=unit-test-coverage.out ./docker/test_env 2>&1 | tee /tmp/gotest.log | gotestloghelper -ci


#######################
Expand Down Expand Up @@ -132,11 +127,11 @@ k8s_test:
k8s_test_e2e:
go test ./k8s/e2e/local-runner -count 1 -test.parallel=12 -v $(args)

k8s_test_e2e_ci:
go test ./k8s/e2e/local-runner -count 1 -v -test.parallel=14 -test.timeout=1h -json 2>&1 | tee /tmp/gotest.log | ./gotestloghelper -ci -singlepackage
k8s_test_e2e_ci: go_mod
go test ./k8s/e2e/local-runner -count 1 -test.parallel=14 -test.timeout=1h -json 2>&1 | tee /tmp/gotest.log | gotestloghelper -ci -singlepackage

k8s_test_e2e_ci_remote_runner:
go test ./k8s/e2e/remote-runner -count 1 -v -test.parallel=20 -test.timeout=1h -json 2>&1 | tee /tmp/remoterunnergotest.log | ./gotestloghelper -ci -singlepackage
k8s_test_e2e_ci_remote_runner: go_mod
go test ./k8s/e2e/remote-runner -count 1 -test.parallel=20 -test.timeout=1h -json 2>&1 | tee /tmp/remoterunnergotest.log | gotestloghelper -ci -singlepackage

.PHONY: examples
examples:
Expand All @@ -157,3 +152,7 @@ chaosmesh: ## there is currently a bug on JS side to import all CRDs from one ya
.PHONY: tools_build
gotestloghelper_build:
cd ./tools/gotestloghelper && go build -o ../../gotestloghelper . && cd -

.PHONY: nix_shell
nix_shell:
nix develop
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ Then use
make install_deps
```

##### Optional Nix

We have setup a nix shell which will produce a reliable environment that will behave the same locally and in ci. To use it instead of the above you will need to [install nix](https://nixos.org/download/)

To start the nix shell run:

```shell
make nix_shell
```

If you install [direnv](https://github.com/direnv/direnv/blob/master/docs/installation.md) you wil be able to have your environment start the nix shell as soon as you cd into it once you have allowed the directory via:

```shell
direnv allow
```

### Running tests in k8s

To read how to run a test in k8s, read [here](./k8s/REMOTE_RUN.md)
Expand Down Expand Up @@ -161,13 +177,15 @@ cfg, err: = builder.
```

When using a custom image you can even further simplify the builder by calling only `WithCustomDockerImages` method. Based on the image name and version we will determine which execution layer client it is and whether it's `eth1` or `eth2` client:

```go
builder := NewEthereumNetworkBuilder()
cfg, err: = builder.
WithCustomDockerImages(map[ContainerType]string{
ContainerType_Geth: "ethereum/client-go:v1.13.10"}).
Build()
```

In the case above we would launch a `Geth` client with `eth2` network and `Prysm` consensus layer.

You can also configure epochs at which hardforks will happen. Currently only `Deneb` is supported. Epoch must be >= 1. Example:
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
description = "chainlink-testing-framework developement shell";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = inputs@{ self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; overlays = [ ]; };
# The current default sdk for macOS fails to compile go projects, so we use a newer one for now.
# This has no effect on other platforms.
callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage;
in rec {
devShell = callPackage ./shell.nix {
inherit pkgs;
scriptDir = toString ./.; # This converts the flake's root directory to a string
};
formatter = pkgs.nixpkgs-fmt;
});
}
1 change: 1 addition & 0 deletions nix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
experimental-features = nix-command flakes
Loading

0 comments on commit e62deff

Please sign in to comment.