Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve build-ui Makefile target and fix dependencies #2573

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ Then install dependencies and run the tests:
git submodule update --init --recursive
make install-tools
make test
# if you wish to build platform binaries locally - the step below is needed.
make build-ui
```

### Running local build with the UI
Expand Down
40 changes: 33 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ md-to-godoc-gen:

.PHONY: clean
clean:
rm -rf cover.out .cover/ cover.html lint.log fmt.log
rm -rf cover.out .cover/ cover.html lint.log fmt.log \
cmd/query/app/ui/actual/gen_assets.go \
cmd/query/app/ui/placeholder/gen_assets.go
Copy link
Member

Choose a reason for hiding this comment

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

this file is checked in, I don't think clean should be removing it.


.PHONY: test
test: go-gen test-otel
Expand Down Expand Up @@ -222,29 +224,53 @@ docker-hotrod:
docker build -t $(DOCKER_NAMESPACE)/example-hotrod:${DOCKER_TAG} ./examples/hotrod --build-arg TARGETARCH=$(GOARCH)

.PHONY: run-all-in-one
run-all-in-one:
run-all-in-one: build-ui
go run -tags ui ./cmd/all-in-one --log-level debug

# Be explicit about exactly what assets we want, as asset files could be partially deleted
# after initial generation; which is the case in Travis CI builds (DOCKER + DEPLOY).
EXPECT_ASSETS := cmd/query/app/ui/actual/gen_assets.go \
cmd/query/app/ui/placeholder/gen_assets.go
FOUND_ASSETS := $(wildcard $(EXPECT_ASSETS))
.PHONY: build-ui
build-ui:
# The `jaeger-ui` submodule contains the source code for the UI assets (requires Node.js 6+).
albertteoh marked this conversation as resolved.
Show resolved Hide resolved
# The assets must be compiled first with `make build-ui`, which runs Node.js build and then
# packages the assets into a Go file that is `.gitignore`-ed.
#
# The packaged assets can be enabled by providing a build tag `ui`; for example:
# $ go run -tags ui ./cmd/all-in-one/main.go
Copy link
Member

Choose a reason for hiding this comment

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

I think CONTRIBUTING file is a better place for this documentation than a makefile, nobody would look here, especially when reading instructions in CONTRIBUTING

#
# To reduce `build-ui` execution times, no work will be done if the resulting UI assets exist.
# These expected assets are cmd/query/app/ui/(actual|placeholder)/gen_assets.go.
#
# To force a rebuild of UI assets, run `make clean` which deletes any files matching the
# above glob pattern.
@echo "Expect UI assets: $(EXPECT_ASSETS)"
@echo "Found UI assets: $(FOUND_ASSETS)"

ifeq ($(FOUND_ASSETS), $(EXPECT_ASSETS))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm open to suggestions of a better approach to checking if build-ui was previously run.

Copy link
Member

Choose a reason for hiding this comment

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

This is what Make was built for - we can to define the files as dependencies of a target. However, the trick is that the files themselves should also be dependency-tracked. I.e. something like this:

placeholder/gen_assets.go: placeholder/public/index.html
    esc ...

actual/gen_assets.go: jaeger-ui/packages/jaeger-ui/build/index.html
    esc ...

build-ui: placeholder/gen_assets.go actual/gen_assets.go
    # actually, nothing to do here

But, there are still two problems with this:

  • ideally, jaeger-ui/packages/jaeger-ui/build/index.html should also be dependent on the actual UI source. This gets pretty complicated to manage.
  • this set-up always requires a real UI build, a situation I would rather avoid. It should only be required when the binary is compiled with -tags ui.

Copy link
Contributor Author

@albertteoh albertteoh Oct 18, 2020

Choose a reason for hiding this comment

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

Ah yes, good suggestion re: make on file dependencies.

ideally, jaeger-ui/packages/jaeger-ui/build/index.html should also be dependent on the actual UI source. This gets pretty complicated to manage.

Could we solve this with the following make target spec? I suspect you are suggesting that there's more to consider that I haven't picked up on:

jaeger-ui/packages/jaeger-ui/build/index.html:
	cd jaeger-ui && yarn install --frozen-lockfile && cd packages/jaeger-ui && yarn build

this set-up always requires a real UI build, a situation I would rather avoid.

Forgive me for not understanding and my ignorance; what specifically about this set-up requires a real UI build? I thought yarn build would result in a real UI build?

It should only be required when the binary is compiled with -tags ui.

In this PR, I made sure the build-ui target is only executed for binaries compiled with -tags ui, or have I misunderstood something?

Copy link
Member

Choose a reason for hiding this comment

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

Could we solve this with the following make target spec?

The main idea of Make is to execute targets when dependencies change. When the target itself is a file AND has no dependencies, then once that file exists the command will never be run:

$ cat Makefile
x: file

file:
       echo n > file

$ make x
echo n > file

$ make x
make: Nothing to be done for `x'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could add the build dir to the clean target (which doesn't exist when initing the submodule, also note actual/gen_assets.go isn't checked in so it should be okay to remove). So we'd have the following:

.PHONY: clean
clean:
	rm -rf cover.out .cover/ cover.html lint.log fmt.log \
		cmd/query/app/ui/actual/gen_assets.go \
		jaeger-ui/packages/jaeger-ui/build

.PHONY: build-ui
build-ui: cmd/query/app/ui/actual/gen_assets.go cmd/query/app/ui/placeholder/gen_assets.go
        # Do nothing

jaeger-ui/packages/jaeger-ui/build/index.html:
	cd jaeger-ui && yarn install --frozen-lockfile && cd packages/jaeger-ui && yarn build

cmd/query/app/ui/actual/gen_assets.go: jaeger-ui/packages/jaeger-ui/build/index.html
	esc -pkg assets -o cmd/query/app/ui/actual/gen_assets.go -prefix jaeger-ui/packages/jaeger-ui/build jaeger-ui/packages/jaeger-ui/build

cmd/query/app/ui/placeholder/gen_assets.go: cmd/query/app/ui/placeholder/public/index.html
	esc -pkg assets -o cmd/query/app/ui/placeholder/gen_assets.go -prefix cmd/query/app/ui/placeholder/public cmd/query/app/ui/placeholder/public

From a fresh clone, I performed the following test:

$ git submodule update --init --recursive

$ make build-ui
cd jaeger-ui && yarn install --frozen-lockfile && cd packages/jaeger-ui && yarn build
esc -pkg assets -o cmd/query/app/ui/actual/gen_assets.go -prefix jaeger-ui/packages/jaeger-ui/build jaeger-ui/packages/jaeger-ui/build
esc -pkg assets -o cmd/query/app/ui/placeholder/gen_assets.go -prefix cmd/query/app/ui/placeholder/public cmd/query/app/ui/placeholder/public

$ make build-ui
# Do nothing

# Trigger a rebuild of UI assets
$ make clean
rm -rf cover.out .cover/ cover.html lint.log fmt.log \
		cmd/query/app/ui/actual/gen_assets.go \
		jaeger-ui/packages/jaeger-ui/build

$ make build-ui
cd jaeger-ui && yarn install --frozen-lockfile && cd packages/jaeger-ui && yarn build
esc -pkg assets -o cmd/query/app/ui/actual/gen_assets.go -prefix jaeger-ui/packages/jaeger-ui/build jaeger-ui/packages/jaeger-ui/build

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. I would change # Do nothing to # Do nothing. If you need to force a rebuild of UI assets, run make clean.

I don't think you need to include cmd/query/app/ui/actual/gen_assets.go in the clean target, because that file will be rebuilt any time index.html is changed (which is being deleted in clean).

@echo "Skipping building UI assets as all expected files were found."
else
cd jaeger-ui && yarn install --frozen-lockfile && cd packages/jaeger-ui && yarn build
esc -pkg assets -o cmd/query/app/ui/actual/gen_assets.go -prefix jaeger-ui/packages/jaeger-ui/build jaeger-ui/packages/jaeger-ui/build
esc -pkg assets -o cmd/query/app/ui/placeholder/gen_assets.go -prefix cmd/query/app/ui/placeholder/public cmd/query/app/ui/placeholder/public
endif

.PHONY: build-all-in-one-linux
build-all-in-one-linux: build-ui
build-all-in-one-linux:
GOOS=linux $(MAKE) build-all-in-one

.PHONY: build-all-in-one
build-all-in-one: elasticsearch-mappings
build-all-in-one: build-ui elasticsearch-mappings
$(GOBUILD) -tags ui -o ./cmd/all-in-one/all-in-one-$(GOOS)-$(GOARCH) $(BUILD_INFO) ./cmd/all-in-one/main.go

.PHONY: build-agent
build-agent:
$(GOBUILD) -o ./cmd/agent/agent-$(GOOS)-$(GOARCH) $(BUILD_INFO) ./cmd/agent/main.go

.PHONY: build-query
build-query:
build-query: build-ui
$(GOBUILD) -tags ui -o ./cmd/query/query-$(GOOS)-$(GOARCH) $(BUILD_INFO) ./cmd/query/main.go

.PHONY: build-collector
Expand All @@ -264,15 +290,15 @@ build-otel-ingester:
cd ${OTEL_COLLECTOR_DIR}/cmd/ingester && $(GOBUILD) -o ./opentelemetry-ingester-$(GOOS)-$(GOARCH) $(BUILD_INFO) main.go

.PHONY: build-otel-all-in-one
build-otel-all-in-one:
build-otel-all-in-one: build-ui
cd ${OTEL_COLLECTOR_DIR}/cmd/all-in-one && $(GOBUILD) -tags ui -o ./opentelemetry-all-in-one-$(GOOS)-$(GOARCH) $(BUILD_INFO) main.go

.PHONY: build-ingester
build-ingester:
$(GOBUILD) -o ./cmd/ingester/ingester-$(GOOS)-$(GOARCH) $(BUILD_INFO) ./cmd/ingester/main.go

.PHONY: docker
docker: build-ui build-binaries-linux docker-images-only
docker: build-binaries-linux docker-images-only

.PHONY: build-binaries-linux
build-binaries-linux:
Expand Down