-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
169 lines (154 loc) · 5.16 KB
/
Makefile
File metadata and controls
169 lines (154 loc) · 5.16 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Configuration is loaded from `.env.maintainer` and can be overridden by
# environment variables.
#
# Usage:
# make build # Build using `.env.maintainer`.
# BUILD_IMAGE=... make build # Override specific variables.
# Load configuration from `.env.maintainer` if it exists.
-include .env.maintainer
# Allow environment variable overrides with defaults.
BUILD_IMAGE ?= unattended/petros:latest
RUNTIME_IMAGE ?= debian:trixie-slim
DOCKER_BUILD_ARGS ?=
DOCKER_RUN_ARGS ?=
DOVE_NAME ?= dove
IMAGE_TAG ?= latest
ACT_PULL ?= false
.PHONY: clean
clean:
@bash -c 'echo -e "\033[33mWARNING: This will delete build artifacts.\033[0m"; \
read -p "Are you sure you want to continue? [y/N]: " confirm; \
if [[ "$$confirm" != "y" && "$$confirm" != "Y" ]]; then \
echo "Operation cancelled."; \
exit 1; \
fi'
rm -rf out/
rm -rf target/
rm -f result result-*
.PHONY: build
build:
@echo "Building native artifacts ..."
mkdir -p out
cargo build --release --bin dove
cp ./target/release/dove ./out/dove
@echo "Build complete."
.PHONY: test
test:
@echo "Running tests ..."
cargo build && cargo test && cd testbench && bash test.sh && cd ../
@echo "... tests completed."
.PHONY: docker-d
docker-d:
@echo "Building Dove image ..."
@echo " Build image: $(BUILD_IMAGE)"
@echo " Runtime image: $(RUNTIME_IMAGE)"
@echo " Output tag: $(DOVE_NAME):$(IMAGE_TAG)"
@mkdir -p out
docker build \
$(DOCKER_BUILD_ARGS) \
--build-arg BUILD_IMAGE=$(BUILD_IMAGE) \
--build-arg RUNTIME_IMAGE=$(RUNTIME_IMAGE) \
-f Dockerfile.dove \
-t $(DOVE_NAME):$(IMAGE_TAG) \
.
@echo "Build complete: $(DOVE_NAME):$(IMAGE_TAG)"
.PHONY: docker
docker:
$(MAKE) docker-d
.PHONY: ci
ci:
@echo "Building images from pre-built binaries (CI mode) ..."
@if [ ! -f out/dove ]; then \
echo "ERROR: Pre-built binaries not found in ./out/" >&2; \
echo "Run 'make build' first to create the binaries." >&2; \
exit 1; \
fi
@echo " Build image: $(BUILD_IMAGE)"
@echo " Runtime image: $(RUNTIME_IMAGE)"
@echo " Output tag: $(DOVE_NAME):$(IMAGE_TAG)"
docker build \
$(DOCKER_BUILD_ARGS) \
--build-arg BUILD_TYPE=prebuilt \
--build-arg BUILD_IMAGE=$(BUILD_IMAGE) \
--build-arg RUNTIME_IMAGE=$(RUNTIME_IMAGE) \
-f Dockerfile.dove \
-t $(DOVE_NAME):$(IMAGE_TAG) \
.
@echo "Build complete: $(DOVE_NAME):$(IMAGE_TAG)"
.PHONY: run-d
run-d:
@echo "Starting Dove container ..."
docker run --rm -it \
--name $(DOVE_NAME) \
$(DOCKER_RUN_ARGS) \
$(DOVE_NAME):$(IMAGE_TAG)
.PHONY: stop-d
stop-d:
@echo "Stopping Dove container..."
docker stop $(DOVE_NAME)
docker rm $(DOVE_NAME) || true
.PHONY: shell-d
shell-d:
@echo "Opening shell in Dove ..."
docker run --rm -it \
--entrypoint /bin/bash \
$(DOVE_NAME):$(IMAGE_TAG)
.PHONY: run
run:
$(MAKE) build
$(MAKE) ci
$(MAKE) run-d
.PHONY: act
act:
@echo "Running GitHub Actions workflow locally with act ..."
@if [ ! -d ".act-secrets" ]; then \
echo "WARNING: .act-secrets/ directory not found" >&2; \
echo "See docs/WORKFLOW_TESTING.md for setup instructions" >&2; \
fi
@echo "Cleaning previous act artifacts to prevent cross-repo contamination ..."
@rm -rf /tmp/act-artifacts/*
@echo "Setting up temporary secrets mount ..."
@sudo mkdir -p /opt/github-runner
@sudo rm -rf /opt/github-runner/secrets
@sudo ln -s $(CURDIR)/.act-secrets /opt/github-runner/secrets
@trap "sudo rm -f /opt/github-runner/secrets" EXIT; \
DOCKER_HOST="" act push -W .github/workflows/release.yml \
--container-options "-v /opt/github-runner/secrets:/opt/github-runner/secrets:ro" \
--artifact-server-path=/tmp/act-artifacts \
--pull=$(ACT_PULL) \
$(if $(DOCKER_BUILD_ARGS),--env DOCKER_BUILD_ARGS="$(DOCKER_BUILD_ARGS)")
.PHONY: help
help:
@echo "Build System"
@echo ""
@echo "Targets:"
@echo " clean Clean output directories."
@echo " build Build native binaries."
@echo " test Run all tests for the build."
@echo " docker-c Build just the Dove image."
@echo " docker Build Docker images (compiles inside container)."
@echo " ci Build Docker images from pre-built binaries."
@echo " run-c Run the built Dove image locally."
@echo " run Run the built Docker images locally."
@echo " stop-c Stop the running Dove container."
@echo " shell-c Open a shell in the Dove image."
@echo " act Test GitHub Actions release workflow locally."
@echo " help Show this help message."
@echo ""
@echo "Configuration:"
@echo " Variables are loaded from .env.maintainer."
@echo " Override with environment variables:"
@echo " BUILD_IMAGE - Builder image."
@echo " RUNTIME_IMAGE - Runtime base image."
@echo " DOVE_NAME - Dove image name."
@echo " IMAGE_TAG - Docker image tag."
@echo " DOCKER_BUILD_ARGS - Additional Docker build flags."
@echo " DOCKER_RUN_ARGS - Additional Docker run flags."
@echo ""
@echo "Examples:"
@echo " make build"
@echo " BUILD_IMAGE=unattended/petros:latest make build"
@echo " IMAGE_TAG=v1.0.0 make build"
@echo " DOCKER_BUILD_ARGS='--network host' make build"
@echo " DOCKER_RUN_ARGS='--network host' make run-d"
.DEFAULT_GOAL := build