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

Clean makefile #1532

Merged
merged 4 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ jobs:
go-version: 1.17.x
- name: checkout
uses: actions/checkout@v2
- name: Install UI Deps
run: npm ci
- name: Build UI Assets
run: make cmd/gitops/ui/run/dist/main.js
run: make ui
- name: Set up kubebuilder
uses: fluxcd/pkg/actions/kubebuilder@main
- name: Set up flux dir but let dependencies install flux
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: 1.17.x
- run: npm ci
- run: make cmd/gitops/ui/run/dist/main.js
- run: make ui
- run: make ui-lint
- run: make ui-test
- run: make ui-audit
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: 1.17.X
- name: Fake Install flux
run: mkdir -p pkg/flux/bin && touch pkg/flux/bin/flux
- name: Fake dist for the ui cmd
run: mkdir -p cmd/gitops/ui/run/dist && touch cmd/gitops/ui/run/dist/index.js
- name: Run FOSSA scan and upload build data
uses: fossa-contrib/fossa-action@v1
with:
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ jobs:
run: make node_modules
- name: Check Git State
run: git diff --no-ext-diff --exit-code
- name: Fake Install flux
run: mkdir -p pkg/flux/bin && touch pkg/flux/bin/flux
- name: Build UI Assets
run: make cmd/gitops/ui/run/dist/index.html
- name: Check Format
run: make check-format
- name: Run linters
Expand Down Expand Up @@ -95,12 +91,10 @@ jobs:
with:
github-ssh-private-key: ${{ secrets.WEAVE_GITOPS_TEST_WEAVEWORKS_WEAVE_GITOPS_BOT_SSH_KEY }}
gitlab-ssh-private-key: ${{ secrets.GITLAB_KEY }}
- name: Install UI Deps
run: npm ci
- name: Build UI
run: make ui
- name: UI Deps Audit
run: make ui-audit
- name: Build UI Assets
run: make cmd/gitops/ui/run/dist/main.js
- name: Set up kubebuilder
uses: fluxcd/pkg/actions/kubebuilder@main
- name: Set up flux dir but let dependencies install flux
Expand Down
55 changes: 24 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
.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)
.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 which git > /dev/null && git describe --always --match "v*")
GOOS=$(shell which go > /dev/null && go env GOOS)
GOARCH=$(shell which go > /dev/null && go env GOARCH)

BUILD_TIME=$(shell date +'%Y-%m-%d_%T')
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
BRANCH=$(shell which git > /dev/null && git rev-parse --abbrev-ref HEAD)
GIT_COMMIT=$(shell git log -n1 --pretty='%h')
CURRENT_DIR=$(shell pwd)
FORMAT_LIST=$(shell gofmt -l .)
FLUX_VERSION=$(shell $(CURRENT_DIR)/tools/bin/stoml $(CURRENT_DIR)/tools/dependencies.toml flux.version)
FORMAT_LIST=$(shell which gofmt > /dev/null && gofmt -l .)
FLUX_VERSION=$(shell [ -f '$(CURRENT_DIR)/tools/bin/stoml' ] && $(CURRENT_DIR)/tools/bin/stoml $(CURRENT_DIR)/tools/dependencies.toml flux.version)
LDFLAGS = "-X github.com/weaveworks/weave-gitops/cmd/gitops/version.BuildTime=$(BUILD_TIME) -X github.com/weaveworks/weave-gitops/cmd/gitops/version.Branch=$(BRANCH) -X github.com/weaveworks/weave-gitops/cmd/gitops/version.GitCommit=$(GIT_COMMIT) -X github.com/weaveworks/weave-gitops/pkg/version.FluxVersion=$(FLUX_VERSION) -X github.com/weaveworks/weave-gitops/cmd/gitops/version.Version=$(VERSION)"

KUBEBUILDER_ASSETS ?= "$(CURRENT_DIR)/tools/bin/envtest"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
ifeq (,$(shell which go > /dev/null && go env GOBIN))
GOBIN=$(shell which go > /dev/null && go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
GOBIN=$(shell which go > /dev/null && go env GOBIN)
endif

ifeq ($(BINARY_NAME),)
BINARY_NAME := gitops
endif

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

##@ Test
unit-tests: dependencies ## Run unit tests
Expand Down Expand Up @@ -95,15 +95,8 @@ 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/*
rm -rf cmd/gitops-server/cmd/dist
rm -rf coverage
rm -rf node_modules
rm -f .deps
rm -rf dist
# There is an important (tracked) file in pkg/flux/bin so don't just nuke the whole folder
# -x: remove gitignored files too, -d: remove directories too
git clean -x -d --force pkg/flux/bin/
# Clean up everything. This includes files git has been told to ignore (-x) and directories (-d)
git clean -x -d --force

fmt: ## Run go fmt against code
go fmt ./...
Expand Down Expand Up @@ -144,6 +137,11 @@ proto: ## Generate protobuf files
# oapi-codegen -config oapi-codegen.config.yaml api/applications/applications.swagger.json

##@ UI
# Build the UI for embedding
ui: cmd/gitops-server/cmd/dist/index.html ## Build the UI

cmd/gitops-server/cmd/dist/index.html: node_modules $(shell find ui -type f)
npm run build

node_modules: ## Install node modules
npm install-clean
Expand All @@ -158,17 +156,17 @@ ui-test: ## Run UI tests
ui-audit: ## Run audit against the UI
npm audit --production

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

# Build the UI as an NPM package (hosted on github)
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-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
dist/index.js: ui/index.ts
npm run build:lib && cp package.json dist

dist/index.d.ts: ui/index.ts
npm run typedefs

# Runs a test to raise errors if the integration between Gitops Core and EE is
# in danger of breaking due to package API changes.
Expand All @@ -179,11 +177,6 @@ lib-test: dependencies ## Run the library integration test
-v $(CURRENT_DIR):/go/src/github.com/weaveworks/weave-gitops \
gitops-library-test

dist/index.js: ui/index.ts
npm run build:lib && cp package.json dist

dist/index.d.ts: ui/index.ts
npm run typedefs

# Test coverage

Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,33 @@ To set up a development environment for the CLI
6. Start the in-cluster API replacement job (powered by [http://tilt.dev](tilt.dev)) with `make cluster-dev`
7. make or make unit-tests to ensure everything built correctly.

### Requirements/tools
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉👍🧁 for extra documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Danke


This is a list of the tools you may need to install:

* [go](https://go.dev) -- Primary compiler for the CLI.
* [npm](https://www.npmjs.com/) -- Package manager for UI components.
* [ginkgo](https://onsi.github.io/ginkgo/) -- A go testing framework.
* [docker](https://www.docker.com/) -- Used for generating containers & testing kubernetes set-ups.
* [golangci-lint](https://github.com/golangci/golangci-lint/) -- A go linter.
* [buf](https://buf.build/) -- To generate the protobufs used by the API.
* [reflex](https://github.com/cespare/reflex) -- A file watcher.
* [kind](https://kind.sigs.k8s.io/) -- Run kubernetes clusters in docker for testing.
* [lcov](https://github.com/linux-test-project/lcov) -- Used for code coverage.

Some other tools are installed automatically by the makefile for you:

* [go-acc](https://github.com/ory/go-acc) -- Calculates code coverage for go.
* [gcov2lcov](https://github.com/jandelgado/gcov2lcov) -- Converts output from go-acc to a format lcov understands.
* [controller-gen](https://sigs.k8s.io/controller-tools/cmd/controller-gen) -- Helps generate kubernetes controller code.

And some tools that are installed by the `tools/download-deps.sh` script:

* [flux](https://fluxcd.io/) -- Continuous delivery system for kubernetes that weave-gitops enriches.
* [envtest](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/envtest) -- Run a kubernetes control plane locally for testing.
* [tilt](https://tilt.dev/) -- Automatically build and deploy to a local cluster.


### Cluster Dev Tips

- You may need to turn off your `kustomize-controller` to prevent it from reconciling your "GitOps RunTime" and over-writing the `wego-app` deployment.
Expand Down