-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
192 lines (177 loc) · 6.03 KB
/
Makefile
File metadata and controls
192 lines (177 loc) · 6.03 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# 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
# Load configuration from `.env` if it exists.
-include .env
# Allow environment variable overrides with defaults.
BUILD_IMAGE ?= unattended/petros:latest
RUNTIME_IMAGE ?= debian:trixie-slim
DOCKER_BUILD_ARGS ?=
DOCKER_RUN_ARGS ?= -e RUST_LOG=info
MAGISTER_NAME ?= magister
IMAGE_TAG ?= latest
ACT_PULL ?= true
.PHONY: init
init:
@echo "Initializing configuration files ..."
@if [ ! -f .env ]; then \
cp .env.example .env; \
echo "Created .env from .env.example - please review."; \
else \
echo ".env already exists."; \
fi
@if [ ! -f magister.toml ]; then \
cp magister.example.toml magister.toml; \
echo "Created magister.toml from magister.example.toml - please review."; \
else \
echo "magister.toml already exists."; \
fi
@echo "Initialization complete. Review configuration before running."
.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
cp ./target/release/magister ./out/magister
@echo "Build complete."
.PHONY: test
test:
@echo "Running tests ..."
cargo test --release
@echo "... tests completed."
.PHONY: docker
docker:
@echo "Building Magister image ..."
@echo " Build image: $(BUILD_IMAGE)"
@echo " Runtime image: $(RUNTIME_IMAGE)"
@echo " Output tag: $(MAGISTER_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.magister \
-t $(MAGISTER_NAME):$(IMAGE_TAG) \
.
@echo "Build complete: $(MAGISTER_NAME):$(IMAGE_TAG)"
.PHONY: ci
ci:
@echo "Building Docker images from pre-built binaries (CI mode) ..."
@if [ ! -f out/magister ]; 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: $(MAGISTER_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.magister \
-t $(MAGISTER_NAME):$(IMAGE_TAG) \
.
@echo "Build complete: $(MAGISTER_NAME):$(IMAGE_TAG)"
.PHONY: run
run:
$(MAKE) build
$(MAKE) ci
@if [ ! -f .env ]; then \
echo "ERROR: .env not found" >&2; \
echo "Run 'make init' to create configuration files." >&2; \
exit 1; \
fi
@if [ ! -f magister.toml ]; then \
echo "ERROR: magister.toml not found" >&2; \
echo "Run 'make init' to create configuration files." >&2; \
exit 1; \
fi
@echo "Starting Magister container ..."
docker run --rm -it \
--name $(MAGISTER_NAME) \
$(DOCKER_RUN_ARGS) \
--env-file .env \
-v $(CURDIR)/magister.toml:/home/magister/magister.toml:ro \
$(MAGISTER_NAME):$(IMAGE_TAG)
.PHONY: stop
stop:
@echo "Stopping Magister container..."
docker stop $(MAGISTER_NAME)
docker rm $(MAGISTER_NAME) || true
.PHONY: shell
shell:
@echo "Opening shell in Magister ..."
docker run --rm -it \
--entrypoint /bin/bash \
$(MAGISTER_NAME):$(IMAGE_TAG)
.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 " init Initialize config from examples."
@echo " clean Clean output directories."
@echo " build Build native binaries."
@echo " test Run all tests for the build."
@echo " docker Build Docker images (compiles inside container)."
@echo " ci Build Docker images from pre-built binaries."
@echo " run Run the built Docker images locally."
@echo " stop Stop the running Magister container."
@echo " shell Open a shell in the Magister container."
@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 " MAGISTER_NAME - Magister container 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"
.DEFAULT_GOAL := build