Skip to content

Commit

Permalink
core: move main.go to root; simplify make build/install (#8954)
Browse files Browse the repository at this point in the history
Co-authored-by: Tate <tate.exon@smartcontract.com>
  • Loading branch information
jmank88 and tateexon authored Apr 17, 2023
1 parent 762a01a commit 44f8e36
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ jobs:
- name: Download Go vendor packages
run: go mod download
- name: Build binary
run: go build -o chainlink.test ./core
run: go build -o chainlink.test .
- name: Setup DB
run: ./chainlink.test local db preparetest
- name: Increase Race Timeout
Expand Down
2 changes: 0 additions & 2 deletions .goreleaser.develop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ builds:
- linux
goarch:
- arm64
main: ./core
hooks:
post: ./tools/bin/goreleaser_utils build_post_hook {{ dir .Path }} {{ .Os }} {{ .Arch }}
env:
Expand All @@ -42,7 +41,6 @@ builds:
- linux
goarch:
- amd64
main: ./core
hooks:
post: ./tools/bin/goreleaser_utils build_post_hook {{ dir .Path }} {{ .Os }} {{ .Arch }}
env:
Expand Down
4 changes: 0 additions & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ builds:
- linux
goarch:
- arm64
main: ./core
hooks:
post: ./tools/bin/goreleaser_utils build_post_hook {{ dir .Path }} {{ .Os }} {{ .Arch }}
env:
Expand All @@ -42,7 +41,6 @@ builds:
- linux
goarch:
- amd64
main: ./core
hooks:
post: ./tools/bin/goreleaser_utils build_post_hook {{ dir .Path }} {{ .Os }} {{ .Arch }}
env:
Expand All @@ -62,7 +60,6 @@ builds:
- darwin
goarch:
- arm64
main: ./core
hooks:
post: ./tools/bin/goreleaser_utils build_post_hook {{ dir .Path }} {{ .Os }} {{ .Arch }}
env:
Expand All @@ -82,7 +79,6 @@ builds:
- darwin
goarch:
- amd64
main: ./core
hooks:
post: ./tools/bin/goreleaser_utils build_post_hook {{ dir .Path }} {{ .Os }} {{ .Arch }}
env:
Expand Down
26 changes: 8 additions & 18 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
.DEFAULT_GOAL := chainlink

GOPATH ?= $(HOME)/go
COMMIT_SHA ?= $(shell git rev-parse HEAD)
VERSION = $(shell cat VERSION)
GOBIN ?= $(GOPATH)/bin
GO_LDFLAGS := $(shell tools/bin/ldflags)
GOFLAGS = -ldflags "$(GO_LDFLAGS)"

Expand Down Expand Up @@ -37,26 +35,18 @@ gomodtidy: ## Run go mod tidy on all modules.
cd ./integration-tests && go mod tidy

.PHONY: install-chainlink
install-chainlink: chainlink ## Install the chainlink binary.
mkdir -p $(GOBIN)
rm -f $(GOBIN)/chainlink
cp $< $(GOBIN)/chainlink
install-chainlink: operator-ui ## Install the chainlink binary.
go install $(GOFLAGS) .

chainlink: operator-ui ## Build the chainlink binary.
go build $(GOFLAGS) -o $@ ./core/
go build $(GOFLAGS) .

.PHONY: docker ## Build the chainlink docker image
docker:
docker buildx build \
--build-arg COMMIT_SHA=$(COMMIT_SHA) \
-f core/chainlink.Dockerfile .

.PHONY: chainlink-build
chainlink-build: operator-ui ## Build & install the chainlink binary.
go build $(GOFLAGS) -o chainlink ./core/
rm -f $(GOBIN)/chainlink
cp chainlink $(GOBIN)/chainlink

.PHONY: operator-ui
operator-ui: ## Fetch the frontend
./operator_ui/install.sh
Expand Down Expand Up @@ -91,17 +81,17 @@ generate: abigen codecgen mockery ## Execute all go:generate commands.

.PHONY: testdb
testdb: ## Prepares the test database.
go run ./core/main.go local db preparetest
go run . local db preparetest

.PHONY: testdb
testdb-user-only: ## Prepares the test database with user only.
go run ./core/main.go local db preparetest --user-only
go run . local db preparetest --user-only

# Format for CI
.PHONY: presubmit
presubmit: ## Format go files and imports.
goimports -w ./core
gofmt -w ./core
goimports -w .
gofmt -w .
go mod tidy

.PHONY: mockery
Expand All @@ -128,7 +118,7 @@ test_need_operator_assets: ## Add blank file in web assets if operator ui has no

.PHONY: config-docs
config-docs: ## Generate core node configuration documentation
go run ./core/config/v2/docs/cmd/generate/main.go -o ./docs/
go run ./core/config/v2/docs/cmd/generate -o ./docs/

.PHONY: golangci-lint
golangci-lint: ## Run golangci-lint for all issues.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Note: Other environment variables should not be set for all tests to pass
6. Drop/Create test database and run migrations:

```
go run ./core/main.go local db preparetest
make testdb
```

If you do end up modifying the migrations for the database, you will need to rerun
Expand Down
2 changes: 1 addition & 1 deletion config_docs_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chainlink
package main

import (
_ "embed"
Expand Down
6 changes: 2 additions & 4 deletions core/chainlink.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ RUN go mod download
# Env vars needed for chainlink build
ARG COMMIT_SHA

COPY common common
COPY core core
COPY operator_ui operator_ui
COPY . .

# Build the golang binary
RUN make chainlink-build
RUN make install-chainlink

# Final image: ubuntu with chainlink binary
FROM ubuntu:20.04
Expand Down
4 changes: 2 additions & 2 deletions core/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package core

import (
"fmt"
Expand All @@ -25,7 +25,7 @@ func init() {
}
}

func main() {
func Main() {
recovery.ReportPanics(func() {
run(newProductionClient(), os.Args...)
})
Expand Down
2 changes: 1 addition & 1 deletion core/main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//go:build !windows
// +build !windows

package main
package core

import (
"io"
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"github.com/smartcontractkit/chainlink/v2/core"
)

func main() {
core.Main()
}
4 changes: 2 additions & 2 deletions tools/bin/cldev
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ case "$1" in
node | core | n)
key='0x9CA9d2D5E04012C9Ed24C0e513C9bfAa4A2dD77f'
echo "** Running node"
go run -ldflags "$LDFLAGS" ./core/main.go -- node start -d -p tools/secrets/password.txt -a tools/secrets/apicredentials
go run -ldflags "$LDFLAGS" . -- node start -d -p tools/secrets/password.txt -a tools/secrets/apicredentials
;;
*)
go run ./core/main.go -- $@
go run . -- $@
;;
esac
2 changes: 1 addition & 1 deletion tools/bin/lint
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -euo pipefail

cd "$(dirname "$0")"/../../core
cd "$(dirname "$0")"/../..

golangci-lint --tests=false run
2 changes: 1 addition & 1 deletion tools/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ This is nothing new, just a demonstration that you should be able to run all the
$ make install

# run go tests
$ go run ./core/main.go local db preparetest
$ make testdb
$ go test ./...

# run evm tests
Expand Down

0 comments on commit 44f8e36

Please sign in to comment.