generated from compliance-framework/policy-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
65 lines (54 loc) · 1.68 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Makefile for building and pushing OPA policies to a registry
# Variables
REGISTRY_URL := ghcr.io
NAMESPACE := chris-cmsoft
POLICY_NAME := local-ssh-policies
VERSION := latest
POLICY_DIR := ./ssh # Directory containing your .rego files
# Build and Push Commands
.PHONY: all build bundle push clean
# Default action
all: test check build push clean
# Check if OPA CLI is installed
OPA := $(shell command -v opa 2> /dev/null)
ifeq ($(OPA),)
$(error "opa CLI not found. Please install it: https://www.openpolicyagent.org/docs/latest/cli/")
endif
# Check if Docker CLI is installed
CONTAINER_CLI := ""
DOCKER := $(shell command -v docker 2> /dev/null)
PODMAN := $(shell command -v podman 2> /dev/null)
ifeq ($(DOCKER),)
PODMAN := := $(shell command -v podman 2> /dev/null)
ifeq ($(PODMAN),)
$(error "either docker or podman CLI is required.")
else
CONTAINER_CLI = PODMAN
endif
else
CONTAINER_CLI = DOCKER
endif
test:
@echo "Testing policies..."
@OPA test policies
# Build the policies
check:
@echo "Checking policies..."
@opa check policies
# Bundle the policies into a tarball for OCI registry
build: clean
@echo "Bundling policies..."
@mkdir -p dist/
@opa build -b policies -o dist/bundle.tar.gz
# Push the bundled policies to an OCI-compliant registry
push: build
@echo "Pushing bundle to registry..."
@# Log in to the registry if necessary
@$(CONTAINER_CLI) login $(REGISTRY_URL)
@# Push the bundle as an OCI artifact
@$(CONTAINER_CLI) cp dist/bundle.tar.gz $(REGISTRY_URL)/$(NAMESPACE)/$(POLICY_NAME):$(VERSION)
@echo "Bundle pushed successfully to $(REGISTRY_URL)/$(NAMESPACE)/$(POLICY_NAME):$(VERSION)"
# Clean up build artifacts
clean:
@echo "Cleaning up..."
@rm -f dist/bundle.tar.gz