Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
makefile refactor (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: awendt <anthony@defenseunicorns.com>
Co-authored-by: Jordan McClintock <jordan@defenseunicorns.com>
  • Loading branch information
3 people authored Sep 8, 2023
1 parent 6c35d41 commit 74e3607
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 52 deletions.
102 changes: 54 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
# The version of Zarf to use. To keep this repo as portable as possible the Zarf binary will be downloaded and added to
# the build folder.
# renovate: datasource=github-tags depName=defenseunicorns/zarf
ZARF_VERSION := v0.29.1

# The version of the build harness container to use
BUILD_HARNESS_REPO := ghcr.io/defenseunicorns/build-harness/build-harness
# renovate: datasource=docker depName=ghcr.io/defenseunicorns/build-harness/build-harness
BUILD_HARNESS_VERSION := 1.10.2
# renovate: datasource=docker depName=ghcr.io/defenseunicorns/packages/dubbd-k3d extractVersion=^(?<version>\d+\.\d+\.\d+)
DUBBD_K3D_VERSION := 0.6.2
DUBBD_K3D_VERSION := 0.8.1

# Figure out which Zarf binary we should use based on the operating system we are on
ZARF_BIN := zarf
UNAME_S := $(shell uname -s)
UNAME_P := $(shell uname -p)
ifneq ($(UNAME_S),Linux)
ifeq ($(UNAME_S),Darwin)
ZARF_BIN := $(addsuffix -mac,$(ZARF_BIN))
endif
ifeq ($(UNAME_P),i386)
ZARF_BIN := $(addsuffix -intel,$(ZARF_BIN))
endif
ifeq ($(UNAME_P),arm64)
ZARF_BIN := $(addsuffix -apple,$(ZARF_BIN))
endif
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),x86_64)
ARCH := amd64
else ifeq ($(UNAME_M),amd64)
ARCH := amd64
else ifeq ($(UNAME_M),arm64)
ARCH := arm64
else
$(error Unsupported architecture: $(UNAME_M))
endif

# Silent mode by default. Run `make VERBOSE=1` to turn off silent mode.
Expand Down Expand Up @@ -75,7 +74,7 @@ fix-cache-permissions: ## Fixes the permissions on the pre-commit cache
########################################################################

.PHONY: test
test: ## Run all automated tests. Requires access to an AWS account. Costs money. Requires env vars "REPO_URL", "GIT_BRANCH", "REGISTRY1_USERNAME", "REGISTRY1_PASSWORD", "GHCR_USERNAME", "GHCR_PASSWORD", "AWS_AVAILABILITY_ZONE" and other standard AWS env vars.
test: ## Run all automated tests. Requires access to an AWS account. Costs money. Requires env vars "REPO_URL", "GIT_BRANCH", "REGISTRY1_USERNAME", "REGISTRY1_PASSWORD", "GHCR_USERNAME", "GHCR_PASSWORD" and standard AWS env vars.
mkdir -p .cache/go
mkdir -p .cache/go-build
echo "Running automated tests. This will take several minutes. At times it does not log anything to the console. If you interrupt the test run you will need to log into AWS console and manually delete any orphaned infrastructure."
Expand Down Expand Up @@ -115,7 +114,7 @@ test-ssh: ## Run this if you set SKIP_TEARDOWN=1 and want to SSH into the still-
# Cluster Section
########################################################################

cluster/full: cluster/destroy cluster/create build/all deploy/all ## This will destroy any existing cluster, create a new one, then build and deploy all
cluster/reset: cluster/destroy cluster/create ## This will destroy any existing cluster and then create a new one

cluster/create: ## Create a k3d cluster with metallb installed
K3D_FIX_MOUNTS=1 k3d cluster create k3d-test-cluster --config utils/k3d/k3d-config.yaml
Expand All @@ -137,7 +136,7 @@ cluster/destroy: ## Destroy the k3d cluster
# Build Section
########################################################################

build/all: build build/zarf build/zarf-init.sha256 build/dubbd-pull-k3d.sha256 build/test-pkg-deps build/uds-capability-gitlab-runner ##
build/all: build build/zarf build/zarf-init build/dubbd-k3d build/test-pkg-deps build/uds-capability-gitlab-runner

build: ## Create build directory
mkdir -p build
Expand All @@ -146,51 +145,58 @@ build: ## Create build directory
clean: ## Clean up build files
rm -rf ./build

build/zarf: | build ## Download the Linux flavor of Zarf to the build dir
echo "Downloading zarf"
curl -sL https://github.com/defenseunicorns/zarf/releases/download/$(ZARF_VERSION)/zarf_$(ZARF_VERSION)_Linux_amd64 -o build/zarf
.PHONY: build/zarf
build/zarf: | build ## Download the Zarf to the build dir
if [ -f build/zarf ] && [ "$$(build/zarf version)" = "$(ZARF_VERSION)" ] ; then exit 0; fi && \
echo "Downloading zarf" && \
curl -sL https://github.com/defenseunicorns/zarf/releases/download/$(ZARF_VERSION)/zarf_$(ZARF_VERSION)_$(UNAME_S)_$(ARCH) -o build/zarf && \
chmod +x build/zarf

build/zarf-mac-intel: | build ## Download the Mac (Intel) flavor of Zarf to the build dir
echo "Downloading zarf-mac-intel"
curl -sL https://github.com/defenseunicorns/zarf/releases/download/$(ZARF_VERSION)/zarf_$(ZARF_VERSION)_Darwin_amd64 -o build/zarf-mac-intel
chmod +x build/zarf-mac-intel

build/zarf-init.sha256: | build ## Download the init package
echo "Downloading zarf-init-amd64-$(ZARF_VERSION).tar.zst"
.PHONY: build/zarf-init
build/zarf-init: | build ## Download the init package
if [ -f build/zarf-init-amd64-$(ZARF_VERSION).tar.zst ] ; then exit 0; fi && \
echo "Downloading zarf-init-amd64-$(ZARF_VERSION).tar.zst" && \
curl -sL https://github.com/defenseunicorns/zarf/releases/download/$(ZARF_VERSION)/zarf-init-amd64-$(ZARF_VERSION).tar.zst -o build/zarf-init-amd64-$(ZARF_VERSION).tar.zst
echo "Creating shasum of the init package"
shasum -a 256 build/zarf-init-amd64-$(ZARF_VERSION).tar.zst | awk '{print $$1}' > build/zarf-init.sha256

build/dubbd-pull-k3d.sha256: | build ## Download dubbd k3d oci package
./build/zarf package pull oci://ghcr.io/defenseunicorns/packages/dubbd-k3d:$(DUBBD_K3D_VERSION)-amd64 --oci-concurrency 9 --output-directory build
echo "Creating shasum of the dubbd-k3d package"
shasum -a 256 build/zarf-package-dubbd-k3d-amd64-$(DUBBD_K3D_VERSION).tar.zst | awk '{print $$1}' > build/dubbd-pull-k3d.sha256

.PHONY: build/dubbd-k3d
build/dubbd-k3d: | build/zarf ## Download dubbd k3d oci package
if [ -f build/zarf-package-dubbd-k3d-amd64-$(DUBBD_K3D_VERSION).tar.zst ] ; then exit 0; fi && \
cd build && ./zarf package pull oci://ghcr.io/defenseunicorns/packages/dubbd-k3d:$(DUBBD_K3D_VERSION)-amd64 --oci-concurrency 12

build/test-pkg-deps: | build ## Build package dependencies for testing
build/zarf package create utils/pkg-deps/namespaces/ --skip-sbom --confirm --output-directory build
build/zarf package create utils/pkg-deps/gitlab/ --skip-sbom --confirm --output-directory build
build/zarf package create utils/pkg-deps/rbac/ --skip-sbom --confirm --output-directory build
build/test-pkg-deps: | build/zarf ## Build package dependencies for testing
cd build && ./zarf package create ../utils/pkg-deps/namespaces/ --skip-sbom --confirm
cd build && ./zarf package create ../utils/pkg-deps/gitlab/ --skip-sbom --confirm
cd build && ./zarf package create ../utils/pkg-deps/rbac/ --skip-sbom --confirm

build/uds-capability-gitlab-runner: | build ## Build the gitlab runner capability
build/zarf package create . --skip-sbom --confirm --output-directory build
build/uds-capability-gitlab-runner: | build/zarf ## Build the gitlab-runner capability
cd build && ./zarf package create ../ --skip-sbom --confirm

########################################################################
# Deploy Section
########################################################################

deploy/all: deploy/init deploy/dubbd-k3d deploy/test-pkg-deps deploy/uds-capability-gitlab-runner ##

deploy/init: ## Deploy the zarf init package
./build/zarf init --confirm --components=git-server
deploy/init: | build/zarf ## Deploy the zarf init package
cd build && ./zarf init --confirm --components=git-server

deploy/dubbd-k3d: | build/zarf ## Deploy the k3d flavor of DUBBD
cd build && ./zarf package deploy zarf-package-dubbd-k3d-amd64-$(DUBBD_K3D_VERSION).tar.zst --confirm

deploy/test-pkg-deps: | build/zarf ## Deploy the package dependencies needed for testing the gitlab-runner capability
cd build && ./zarf package deploy zarf-package-gitlab-runner-namespaces-* --confirm
cd build && ./zarf package deploy zarf-package-gitlab-runner-gitlab* --confirm
cd build && ./zarf package deploy zarf-package-gitlab-runner-rbac* --confirm

deploy/dubbd-k3d: ## Deploy the k3d flavor of DUBBD
cd ./build && ./zarf package deploy zarf-package-dubbd-k3d-amd64-$(DUBBD_K3D_VERSION).tar.zst --confirm
deploy/uds-capability-gitlab-runner: | build/zarf ## Deploy the gitlab-runner capability
cd build && ./zarf package deploy zarf-package-gitlab-runner-amd*.tar.zst --confirm --set GITLAB_RUNNER_DEPENDS_ON="[]"

########################################################################
# Macro Section
########################################################################

deploy/test-pkg-deps: ## Deploy the package dependencies needed for testing the gitlab capability
cd ./build && ./zarf package deploy zarf-package-gitlab-runner-namespaces-* --confirm
cd ./build && ./zarf package deploy zarf-package-gitlab-runner-gitlab* --confirm
cd ./build && ./zarf package deploy zarf-package-gitlab-runner-rbac* --confirm
.PHONY: all
all: build/all cluster/reset deploy/all ## Build and deploy gitlab-runner locally

deploy/uds-capability-gitlab-runner: ## Deploy the gilab-runner capability
cd ./build && ./zarf package deploy zarf-package-gitlab-runner-amd*.tar.zst --confirm --set GITLAB_RUNNER_DEPENDS_ON="[]"
.PHONY: rebuild
rebuild: clean build/all
6 changes: 3 additions & 3 deletions test/e2e/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func SetupTestPlatform(t *testing.T, platform *types.TestPlatform) { //nolint:fu
output, err = platform.RunSSHCommandAsSudo(`cd ~/app && make build/zarf`)
require.NoError(t, err, output)

// Copy zarf-config.toml to the build folder
output, err = platform.RunSSHCommandAsSudo(`cd ~/app && cp test/e2e/zarf-config.toml build/zarf-config.toml`)
// Copy zarf-config.yaml to the build folder
output, err = platform.RunSSHCommandAsSudo(`cd ~/app && cp test/e2e/zarf-config.yaml build/zarf-config.yaml`)
require.NoError(t, err, output)

// Log into registry1.dso.mil
Expand All @@ -125,7 +125,7 @@ func SetupTestPlatform(t *testing.T, platform *types.TestPlatform) { //nolint:fu
require.NoError(t, err, output)

// Create cluster build and deploy
output, err = platform.RunSSHCommandAsSudo(`cd ~/app && make cluster/full`)
output, err = platform.RunSSHCommandAsSudo(`cd ~/app && make all`)
require.NoError(t, err, output)

})
Expand Down
1 change: 0 additions & 1 deletion test/e2e/zarf-config.toml

This file was deleted.

1 change: 1 addition & 0 deletions test/e2e/zarf-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
no_progress: true

0 comments on commit 74e3607

Please sign in to comment.