Skip to content

Commit

Permalink
Fixup Makefile help and Speedup builds (#847)
Browse files Browse the repository at this point in the history
Adds more help information to our Makefile and doesn't rebuild the UI unless explicitly asked for.
  • Loading branch information
Racer159 authored Oct 7, 2022
1 parent 47abd24 commit 347fa0d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
uses: actions/cache@v3
with:
path: '~/Library/Caches/ms-playwright/'
key: ${{ runner.os }}-browsers
key: ${{ runner.os }}-browsers

- name: "Build CLI"
run: make build-cli-linux-amd ARCH=amd64
Expand Down
16 changes: 16 additions & 0 deletions .hooks/print-ui-diff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

# Get the diff for UI related files
git diff HEAD src/ui
git diff HEAD package.json
git diff HEAD package-lock.json
git diff HEAD .npmrc
git diff HEAD .eslint*
git diff HEAD ts*
git diff HEAD prettier*
git diff HEAD svelte*
git diff HEAD vite*
git diff HEAD playwright*

# Get the current commit, branch and other information
git show --oneline -s
81 changes: 42 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,95 +28,84 @@ help: ## Show a list of all targets
| sed -n 's/^\(.*\): \(.*\)##\(.*\)/\1:\3/p' \
| column -t -s ":"

remove-packages: ## remove all zarf packages recursively
find . -type f -name 'zarf-package-*' -delete

vm-init: ## usage -> make vm-init OS=ubuntu
vm-init: ## Make a vagrant VM (usage -> make vm-init OS=ubuntu)
vagrant destroy -f
vagrant up --no-color ${OS}
echo -e "\n\n\n\033[1;93m ✅ BUILD COMPLETE. To access this environment, run \"vagrant ssh ${OS}\"\n\n\n"

vm-destroy: ## Destroy the VM
vm-destroy: ## Destroy the vagrant VM
vagrant destroy -f

clean: ## Clean the build dir
clean: ## Clean the build directory
rm -rf build

destroy:
destroy: ## Run `zarf destroy` on the current cluster
$(ZARF_BIN) destroy --confirm --remove-components
rm -fr build

remove-packages: ## Remove all zarf packages recursively
find . -type f -name 'zarf-package-*' -delete

ensure-ui-build-dir:
mkdir -p build/ui
touch build/ui/index.html

build-ui:
npm ci
npm run build
build-ui: ## Build the Zarf UI
if test "$(shell ./.hooks/print-ui-diff.sh | shasum)" != "$(shell cat build/ui/git-info.txt | shasum)" ; then\
npm ci;\
npm run build;\
fi

build-cli-linux-amd: build-injector-registry-amd build-ui
build-cli-linux-amd: build-injector-registry-amd build-ui ## Build the Zarf CLI for Linux on AMD64
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="$(BUILD_ARGS)" -o build/zarf main.go

build-cli-linux-arm: build-injector-registry-arm build-ui
build-cli-linux-arm: build-injector-registry-arm build-ui ## Build the Zarf CLI for Linux on ARM
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(BUILD_ARGS)" -o build/zarf-arm main.go

build-cli-mac-intel: build-injector-registry-amd build-ui
build-cli-mac-intel: build-injector-registry-amd build-ui ## Build the Zarf CLI for macOS on AMD64
GOOS=darwin GOARCH=amd64 go build -ldflags="$(BUILD_ARGS)" -o build/zarf-mac-intel main.go

build-cli-mac-apple: build-injector-registry-arm build-ui
build-cli-mac-apple: build-injector-registry-arm build-ui ## Build the Zarf CLI for macOS on ARM
GOOS=darwin GOARCH=arm64 go build -ldflags="$(BUILD_ARGS)" -o build/zarf-mac-apple main.go

build-cli-linux: build-cli-linux-amd build-cli-linux-arm
build-cli-linux: build-cli-linux-amd build-cli-linux-arm ## Build the Zarf CLI for Linux on AMD64 and ARM

build-cli: build-cli-linux-amd build-cli-linux-arm build-cli-mac-intel build-cli-mac-apple ## Build the CLI
build-cli: build-cli-linux-amd build-cli-linux-arm build-cli-mac-intel build-cli-mac-apple ## Build the Zarf CLI

build-injector-registry-amd:
build-injector-registry-amd: ## Build the Zarf Injector Stage 2 for Linux on AMD64
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o build/zarf-registry-amd64 src/injector/stage2/registry.go

build-injector-registry-arm:
build-injector-registry-arm: ## Build the Zarf Injector Stage 2 for Linux on ARM
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o build/zarf-registry-arm64 src/injector/stage2/registry.go

docs-and-schema: ensure-ui-build-dir
docs-and-schema: ensure-ui-build-dir ## Generate the Zarf Documentation and Schema
go run main.go internal generate-cli-docs
.hooks/create-zarf-schema.sh

dev: ensure-ui-build-dir
dev: ensure-ui-build-dir ## Start a Dev Server for the UI
go mod download
npm ci
npm run dev

test-built-ui:
API_PORT=3333 API_TOKEN=insecure $(ZARF_BIN) dev ui

test-docs-and-schema:
$(MAKE) docs-and-schema
.hooks/check-zarf-docs-and-schema.sh

test-cves: ensure-ui-build-dir
go run main.go tools sbom packages . -o json | grype --fail-on low

cve-report: ensure-ui-build-dir
go run main.go tools sbom packages . -o json | grype -o template -t .hooks/grype.tmpl > build/zarf-known-cves.csv

# Inject and deploy a new dev version of zarf agent for testing (should have an existing zarf agent deployemt)
# @todo: find a clean way to dynamically support Kind or k3d:
# when using kind: kind load docker-image $(tag)
# when using k3d: k3d image import $(tag)
dev-agent-image:
dev-agent-image: ## Create a new agent image and inject it into a currently inited cluster
$(eval tag := defenseunicorns/dev-zarf-agent:$(shell date +%s))
$(eval arch := $(shell uname -m))
CGO_ENABLED=0 GOOS=linux go build -o build/zarf-linux-$(arch) main.go
DOCKER_BUILDKIT=1 docker build --tag $(tag) --build-arg TARGETARCH=$(arch) . && \
k3d image import $(tag) && \
kubectl -n zarf set image deployment/agent-hook server=$(tag)

init-package: ## Create the zarf init package, macos "brew install coreutils" first
init-package: ## Create the zarf init package (must `brew install coreutils` on macOS first)
@test -s $(ZARF_BIN) || $(MAKE) build-cli
$(ZARF_BIN) package create -o build -a $(ARCH) --set AGENT_IMAGE=$(AGENT_IMAGE) --confirm .

ci-release: init-package ## Create the init package
ci-release: init-package

build-examples:
build-examples: ## Build all of the example packages
@test -s $(ZARF_BIN) || $(MAKE) build-cli

@test -s ./build/zarf-package-dos-games-$(ARCH).tar.zst || $(ZARF_BIN) package create examples/game -o build -a $(ARCH) --confirm
Expand Down Expand Up @@ -144,13 +133,27 @@ build-examples:
## Run e2e tests. Will automatically build any required dependencies that aren't present.
## Requires an existing cluster for the env var APPLIANCE_MODE=true
.PHONY: test-e2e
test-e2e: build-examples
test-e2e: build-examples ## Run all of the core Zarf CLI E2E tests
@test -s ./build/zarf-init-$(ARCH).tar.zst || $(ZARF_BIN) package create -o build -a $(ARCH) --set AGENT_IMAGE=$(AGENT_IMAGE) --confirm .
@test -s ./build/zarf-init-$(ARCH).tar.zst || $(MAKE) init-package
cd src/test/e2e && go test -failfast -v -timeout 30m

test-external:
.PHONY: test-external
test-external: ## Run the Zarf CLI E2E tests for an external registry and cluster
@test -s $(ZARF_BIN) || $(MAKE) build-cli
@test -s ./build/zarf-init-$(ARCH).tar.zst || $(MAKE) init-package
@test -s ./build/zarf-package-flux-test-$(ARCH).tar.zst || $(ZARF_BIN) package create examples/flux-test -o build -a $(ARCH) --confirm
cd src/test/external-test && go test -failfast -v -timeout 30m

test-built-ui: ## Run the Zarf UI E2E tests (requires `make build-ui` first)
API_PORT=3333 API_TOKEN=insecure $(ZARF_BIN) dev ui

test-docs-and-schema:
$(MAKE) docs-and-schema
.hooks/check-zarf-docs-and-schema.sh

test-cves: ensure-ui-build-dir
go run main.go tools sbom packages . -o json | grype --fail-on low

cve-report: ensure-ui-build-dir
go run main.go tools sbom packages . -o json | grype -o template -t .hooks/grype.tmpl > build/zarf-known-cves.csv
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "API_DEV_PORT=5173 API_PORT=3333 API_TOKEN=insecure concurrently --names \"ui,api\" -c \"gray.bold,yellow\" \"vite dev\" \"nodemon -e go -x 'go run main.go dev ui -l=trace || exit 1'\"",
"build": "vite build",
"build": "vite build && ./.hooks/print-ui-diff.sh > build/ui/git-info.txt ",
"test": "playwright test -x --reporter github,html",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
Expand Down

0 comments on commit 347fa0d

Please sign in to comment.