-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
167 lines (147 loc) · 6.46 KB
/
Makefile
File metadata and controls
167 lines (147 loc) · 6.46 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
# makefile for building torero docker image
#
# Copyright 2025 torerodev
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
.PHONY: build push push-all build-all clean test help
# load version defaults from .env file
include .env
export
# github container registry path
GHCR_REGISTRY ?= ghcr.io/torerodev
# default versions if not specified (fallback if .env is missing)
# override with 'make build TORERO_VERSION=x.x.x'
TORERO_VERSION ?= 1.5.0
# default python version
PYTHON_VERSION ?= 3.13.0
# default opentofu version
OPENTOFU_VERSION ?= 1.9.1
# default tag as latest
TAG_AS_LATEST ?= true
# force rebuild (no-cache)
FORCE_REBUILD ?= false
# target platform(s) for multi-arch builds
PLATFORMS ?= linux/amd64,linux/arm64
# build single platform for local testing
LOCAL_PLATFORM ?= linux/$(shell uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
# all available torero versions for build-all
TORERO_VERSIONS ?= 1.5.0
help:
@echo "available targets:"
@echo " build - build torero image for local platform"
@echo " build-multi - build torero image for multiple platforms"
@echo " build-all - build all torero versions"
@echo " push - push specific torero version to GHCR"
@echo " push-all - push all torero versions to GHCR"
@echo " test - run basic tests on the built image"
@echo " clean - remove all torero images"
@echo ""
@echo "variables:"
@echo " GHCR_REGISTRY - github container registry path (default: ghcr.io/torerodev)"
@echo " TORERO_VERSION - torero version to build (default: 1.5.0)"
@echo " PYTHON_VERSION - python version to install (default: 3.13.0)"
@echo " TORERO_VERSIONS - space-separated list of torero versions for build-all (default: 1.3.1)"
@echo " FORCE_REBUILD - set to 'true' to force rebuild (default: false)"
@echo " TAG_AS_LATEST - set to 'true' to tag latest version (default: true)"
@echo " PLATFORMS - comma-separated list of target platforms (default: linux/amd64,linux/arm64)"
@echo " LOCAL_PLATFORM - platform for local builds (default: auto-detected)"
@echo ""
@echo "examples:"
@echo " make build"
@echo " make build TORERO_VERSION=1.5.0 PYTHON_VERSION=3.13.0"
@echo " make build-multi PLATFORMS=linux/amd64,linux/arm64"
@echo " make build-all TORERO_VERSIONS=\"1.4.0 1.5.0\""
@echo " make push"
@echo " make push-all"
build:
@echo "building image for local platform: $(GHCR_REGISTRY)/torero:$(TORERO_VERSION)"
@if [ "$(FORCE_REBUILD)" = "true" ]; then \
docker build -f Containerfile -t $(GHCR_REGISTRY)/torero:$(TORERO_VERSION) \
--platform $(LOCAL_PLATFORM) \
--build-arg TORERO_VERSION=$(TORERO_VERSION) \
--build-arg PYTHON_VERSION=$(PYTHON_VERSION) \
--no-cache .; \
else \
docker build -f Containerfile -t $(GHCR_REGISTRY)/torero:$(TORERO_VERSION) \
--platform $(LOCAL_PLATFORM) \
--build-arg TORERO_VERSION=$(TORERO_VERSION) \
--build-arg PYTHON_VERSION=$(PYTHON_VERSION) .; \
fi
@if [ "$(TAG_AS_LATEST)" = "true" ] && \
[ "$(TORERO_VERSION)" = "$(shell echo $(TORERO_VERSIONS) | tr ' ' '\n' | sort -V | tail -n1)" ]; then \
echo "tagging $(TORERO_VERSION) as latest"; \
docker tag $(GHCR_REGISTRY)/torero:$(TORERO_VERSION) $(GHCR_REGISTRY)/torero:latest; \
fi
# build multi-arch images with buildx
# optionally set PUSH=false to build without pushing (for testing)
PUSH ?= true
build-multi:
@echo "building multi-arch image: $(GHCR_REGISTRY)/torero:$(TORERO_VERSION) for platforms: $(PLATFORMS)"
@docker buildx inspect multiarch-builder > /dev/null 2>&1 || docker buildx create --name multiarch-builder --use
@if [ "$(FORCE_REBUILD)" = "true" ]; then \
docker buildx build -f Containerfile \
--platform $(PLATFORMS) \
--tag $(GHCR_REGISTRY)/torero:$(TORERO_VERSION) \
--build-arg TORERO_VERSION=$(TORERO_VERSION) \
--build-arg PYTHON_VERSION=$(PYTHON_VERSION) \
--no-cache \
$(if $(filter true,$(PUSH)),--push,) .; \
else \
docker buildx build -f Containerfile \
--platform $(PLATFORMS) \
--tag $(GHCR_REGISTRY)/torero:$(TORERO_VERSION) \
--build-arg TORERO_VERSION=$(TORERO_VERSION) \
--build-arg PYTHON_VERSION=$(PYTHON_VERSION) \
$(if $(filter true,$(PUSH)),--push,) .; \
fi
@if [ "$(TAG_AS_LATEST)" = "true" ] && \
[ "$(TORERO_VERSION)" = "$(shell echo $(TORERO_VERSIONS) | tr ' ' '\n' | sort -V | tail -n1)" ]; then \
echo "also tagging $(TORERO_VERSION) as latest"; \
docker buildx build -f Containerfile \
--platform $(PLATFORMS) \
--tag $(GHCR_REGISTRY)/torero:latest \
--build-arg TORERO_VERSION=$(TORERO_VERSION) \
--build-arg PYTHON_VERSION=$(PYTHON_VERSION) \
$(if $(filter true,$(PUSH)),--push,) .; \
fi
# build all torero versions
build-all:
@for torero_version in $(TORERO_VERSIONS); do \
$(MAKE) build TORERO_VERSION=$$torero_version PYTHON_VERSION=$(PYTHON_VERSION); \
done
# push specific version to GHCR
push:
@echo "pushing $(GHCR_REGISTRY)/torero:$(TORERO_VERSION) to GHCR..."
docker push $(GHCR_REGISTRY)/torero:$(TORERO_VERSION)
@if [ "$(TAG_AS_LATEST)" = "true" ] && \
[ "$(TORERO_VERSION)" = "$(shell echo $(TORERO_VERSIONS) | tr ' ' '\n' | sort -V | tail -n1)" ]; then \
echo "pushing latest tag"; \
docker push $(GHCR_REGISTRY)/torero:latest; \
fi
# push all versions to GHCR
push-all:
@for torero_version in $(TORERO_VERSIONS); do \
$(MAKE) push TORERO_VERSION=$$torero_version; \
done
# run basic tests on the built image
test:
@echo "testing $(GHCR_REGISTRY)/torero:$(TORERO_VERSION)..."
@docker run --rm $(GHCR_REGISTRY)/torero:$(TORERO_VERSION) torero version
@echo "testing python installation..."
@docker run --rm $(GHCR_REGISTRY)/torero:$(TORERO_VERSION) python3 --version
@echo "testing opentofu installation..."
@docker run --rm -e INSTALL_OPENTOFU=true -e OPENTOFU_VERSION=$(OPENTOFU_VERSION) $(GHCR_REGISTRY)/torero:$(TORERO_VERSION) bash -c "tofu version" || echo "opentofu test failed (expected on first run)"
# clean up all torero images
clean:
@echo "removing all torero images..."
-docker rmi $(shell docker images $(GHCR_REGISTRY)/torero -q) -f 2>/dev/null || true