Skip to content

Commit

Permalink
Rework makefile to build ui-files in server
Browse files Browse the repository at this point in the history
To separate out the UI components from the cli tool we need to update
the makefile to generate the dist/ui files in the `gitops-server` rather
than `gitops` directories.

This additionally changes to using a pattern-rule target to generate the
go binaries so that the same command can be used shared.
  • Loading branch information
Sam Cook committed Feb 21, 2022
1 parent 55f9faf commit a82acbd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 37 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ jobs:
- run: make dependencies
- run: go mod download
- run: make lint
- run: make bin
- run: make gitops
- run: make gitops-server
- run: make test
# - run: make lib-test

Expand Down
11 changes: 6 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ If we have missed anything you think should be included, or if anything is not
clear, we also accept contributions to this contribution doc :smile:.


## Building the binary
To build the `gitops` binary locally you can run `make bin`. This will create a `gitops`
binary in the `bin/` directory.
## Building the binaries
To build the `gitops` binary locally you can run `make gitops`. This will create a `gitops`
binary in the `bin/` directory. Similarly running `make gitops-server` will create a
`gitops-server` binary in the same directory.


## Testing
Expand Down Expand Up @@ -60,7 +61,7 @@ The acceptance tests can be run using `make acceptance-tests`. They require the
environment variables as the integration tests, with the following in addition:

- `WEGO_BIN_PATH`- The path to the `gitops` binary the tests should use. To test a locally
built binary which is created from `make bin`, you want to set it to `WEGO_BIN_PATH=$PWD/bin/gitops`.
built binary which is created from `make gitops`, you want to set it to `WEGO_BIN_PATH=$PWD/bin/gitops`.
- `IS_TEST_ENV`- If this environment variable is set to anything, it indicates to the `gitops` binary
that it should deploy images using the `latest` tag, instead of the latest version.

Expand All @@ -72,7 +73,7 @@ Until [#1158](https://github.com/weaveworks/weave-gitops/issues/1158) is resolve
`docker build -f Dockerfile -t aclevernameww/wego-app:latest . && docker push aclevernameww/wego-app:latest`
2. Update the `manifests/wego-app/deployment.yaml.tpl` to use your registry. Example:
`image: aclevernameww/wego-app:{{.Version}})`
3. Rebuild the local gitops binary via `make bin`
3. Rebuild the local gitops binary via `make gitops`
4. Ensure `WEGO_BIN_PATH` is set to the local binary and `IS_TEST_ENV=true`

As a result, when the acceptance tests run `gitops install`, they should deploy your custom-built docker image with the desired code changes.
Expand Down
58 changes: 32 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: debug bin gitops install clean fmt vet dependencies lint ui ui-lint ui-test ui-dev unit-tests proto proto-deps api-dev ui-dev fakes crd
.PHONY: all test install clean fmt vet dependencies gitops gitops-server _docker docker-gitops docker-gitops-server lint ui ui-audit ui-lint ui-test unit-tests proto proto-deps fakes crd
VERSION=$(shell git describe --always --match "v*")
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
Expand All @@ -24,12 +24,11 @@ ifeq ($(BINARY_NAME),)
BINARY_NAME := gitops
endif

.PHONY: bin

##@ Default target
all: gitops ## Install dependencies and build Gitops binary

##@ Test
unit-tests: dependencies cmd/gitops/ui/run/dist/index.html ## Run unit tests
unit-tests: dependencies cmd/gitops-server/cmd/dist/index.html ## Run unit tests
# To avoid downloading dependencies every time use `SKIP_FETCH_TOOLS=1 unit-tests`
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) CGO_ENABLED=0 go test -v -tags unittest ./...

Expand All @@ -49,15 +48,12 @@ local-docker-image:
DOCKER_BUILDKIT=1 docker build -t localhost:5000/wego-app:latest . --build-arg FLUX_VERSION=$(FLUX_VERSION)
docker push localhost:5000/wego-app:latest

test: dependencies cmd/gitops/ui/run/dist/index.html
test: dependencies cmd/gitops-server/cmd/dist/index.html
go test -v ./core/...

fakes: ## Generate testing fakes
go generate ./...

##@ Build
gitops: dependencies ui bin ## Install dependencies and build gitops binary

install: bin ## Install binaries to GOPATH
cp bin/$(BINARY_NAME) ${GOPATH}/bin/

Expand All @@ -67,20 +63,34 @@ api-dev: ## Server and watch gitops-server, will reload automatically on change
cluster-dev: ## Start tilt to do development with wego-app running on the cluster
tilt up

debug: ## Compile binary with optimisations and inlining disabled
go build -ldflags $(LDFLAGS) -o bin/$(BINARY_NAME) -gcflags='all=-N -l' cmd/gitops/*.go

bin: ## Build gitops binary
go build -ldflags $(LDFLAGS) -o bin/$(BINARY_NAME) cmd/gitops/*.go
##@ Build
# In addition to the main file depend on all go files and any other files in
# the cmd directory (e.g. dist, on the assumption that there won't be many)
bin/%: cmd/%/main.go $(shell find . -name "*.go") $(shell find cmd -type f)
ifdef DEBUG
go build -ldflags $(LDFLAGS) -o $@ $(GO_BUILD_OPTS) $<
else
go build -ldflags $(LDFLAGS) -gcflags='all=-N -l' -o $@ $(GO_BUILD_OPTS) $<
endif

gitops: bin/gitops ## Build the Gitops CLI, accepts a 'DEBUG' flag
gitops-server: cmd/gitops-server/cmd/dist/index.html bin/gitops-server ## Build the Gitops UI server, accepts a 'DEBUG' flag

_docker:
DOCKER_BUILDKIT=1 docker build $(DOCKERARGS) -f $(DOCKERFILE) .

docker: ## Build wego-app docker image
DOCKER_BUILDKIT=1 docker build --build-arg FLUX_VERSION=$(FLUX_VERSION) --target=runtime -t ghcr.io/weaveworks/wego-app:latest .
docker-gitops: DOCKERFILE:=gitops.dockerfile
docker-gitops: _docker ## Build a Docker image of the gitops CLI

docker-gitops-server: DOCKERFILE:=gitops-server.dockerfile
docker-gitops-server: DOCKERARGS:=--build-arg FLUX_VERSION=$(FLUX_VERSION)
docker-gitops-server: _docker ## Build a Docker image of the Gitops UI Server

# Clean up images and binaries
clean: ## Clean up images and binaries
rm -f bin/gitops
rm -rf cmd/gitops/ui/run/dist
rm -f bin/*
rm -rf cmd/gitops-server/cmd/dist
rm -rf coverage
rm -rf node_modules
rm -f .deps
Expand All @@ -95,7 +105,7 @@ fmt: ## Run go fmt against code
vet: ## Run go vet against code
go vet ./...

lint: cmd/gitops/ui/run/dist/index.html ## Run linters against code
lint: cmd/gitops-server/cmd/dist/index.html ## Run linters against code
golangci-lint run --out-format=github-actions --timeout 600s --skip-files "tilt_modules"

.deps:
Expand Down Expand Up @@ -124,7 +134,7 @@ proto: ## Generate protobuf files
##@ UI

node_modules: ## Install node modules
npm ci
npm install-clean
npx npm-force-resolutions

ui-lint: ## Run linter against the UI
Expand All @@ -136,20 +146,16 @@ ui-test: ## Run UI tests
ui-audit: ## Run audit against the UI
npm audit --production

ui: node_modules cmd/gitops/ui/run/dist/main.js ## Build the UI
ui: node_modules cmd/gitops-server/cmd/dist/index.html ## Build the UI

ui-lib: node_modules dist/index.js dist/index.d.ts ## Build UI libraries
# Remove font files from the npm module.
@find dist -type f -iname \*.otf -delete
@find dist -type f -iname \*.woff -delete

cmd/gitops/ui/run/dist:
mkdir -p cmd/gitops/ui/run/dist

cmd/gitops/ui/run/dist/index.html: cmd/gitops/ui/run/dist
touch cmd/gitops/ui/run/dist/index.html

cmd/gitops/ui/run/dist/main.js:
cmd/gitops-server/cmd/dist/index.html: node_modules $(shell find ui -type f)
# use `mkdir -p` so this works in the ui docker stage
if [ ! -d "cmd/gitops-server/cmd/dist" ]; then mkdir -p cmd/gitops-server/cmd/dist; fi
npm run build

# Runs a test to raise errors if the integration between Gitops Core and EE is
Expand Down
8 changes: 4 additions & 4 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load('ext://restart_process', 'docker_build_with_restart')

local_resource(
'gitops-bin',
'GOOS=linux GOARCH=amd64 make bin',
'gitops-server',
'GOOS=linux GOARCH=amd64 make gitops-server',
deps=[
'./cmd',
'./pkg',
Expand All @@ -17,7 +17,7 @@ docker_build_with_restart(
'./bin',
],
dockerfile="dev.dockerfile",
entrypoint='/app/build/gitops ui run -l',
entrypoint='/app/build/gitops-server -l',
live_update=[
sync('./bin', '/app/build'),
],
Expand All @@ -27,4 +27,4 @@ k8s_yaml([
'tools/wego-app-dev.yaml',
])

k8s_resource('wego-app', port_forwards='9000', resource_deps=['gitops-bin'])
k8s_resource('wego-app', port_forwards='9000', resource_deps=['gitops-server'])
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Weave GitOps core",
"targets": {
"default": {
"distDir": "cmd/gitops/ui/run/dist",
"distDir": "cmd/gitops-server/cmd/dist",
"source": "ui/index.html",
"sourceMap": false
},
Expand Down

0 comments on commit a82acbd

Please sign in to comment.