-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
211 lines (174 loc) · 8.88 KB
/
Makefile
File metadata and controls
211 lines (174 loc) · 8.88 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# Makefile for building and pushing coder-ddev Docker image and templates
# Configuration
IMAGE_NAME := ddev/coder-ddev
VERSION := $(shell cat VERSION 2>/dev/null || echo "1.0.0-beta1")
DOCKERFILE_DIR := image
DOCKERFILE := $(DOCKERFILE_DIR)/Dockerfile
# Template directories (name == directory name == Coder template name)
TEMPLATES := user-defined-web drupal-core drupal-contrib freeform
# Host path to the drupal-core seed cache (bind-mounted read-only into workspaces).
# This path is specific to the server where the template is deployed.
# Override with: make push-template-drupal-core DRUPAL_CACHE_PATH=/other/path/drupal-core-seed
DRUPAL_CACHE_PATH ?= $(HOME)/cache/drupal-core-seed ##v Host path to drupal-core seed cache; override per-server
# Whether to activate the pushed template version immediately.
# Set to false to push for testing before promoting:
# make push-template-drupal-core ACTIVATE=false
# coder templates versions list drupal-core # grab the new version name
# coder create --template drupal-core --template-version <version> test-ws --yes
# coder templates versions promote drupal-core <version>
ACTIVATE ?= true ##v Set to false to push a template version without activating it (test before promoting)
# Full image tag
IMAGE_TAG := $(IMAGE_NAME):$(VERSION)
IMAGE_LATEST := $(IMAGE_NAME):latest
# Per-template extra variables passed to `coder templates push`
TEMPLATE_VARS_user-defined-web := --variable workspace_image_registry=index.docker.io/$(IMAGE_NAME)
TEMPLATE_VARS_drupal-core := --variable workspace_image_registry=index.docker.io/$(IMAGE_NAME) \
--variable cache_path=$(DRUPAL_CACHE_PATH)
TEMPLATE_VARS_drupal-contrib := --variable workspace_image_registry=index.docker.io/$(IMAGE_NAME)
TEMPLATE_VARS_freeform := --variable workspace_image_registry=index.docker.io/$(IMAGE_NAME)
# Per-template display metadata set via `coder templates edit` after push
# (coder templates push only supports --name, not --description)
TEMPLATE_EDIT_user-defined-web := --display-name "[DEPRECATED] DDEV Web Workspace" \
--description "Deprecated: use the freeform template instead. Existing workspaces continue to work." \
--deprecated "Deprecated: use the freeform template instead. Existing workspaces continue to work."
TEMPLATE_EDIT_drupal-core := --display-name "Drupal Core Development" \
--description "Drupal core dev environment: full DDEV stack, core clone, Umami demo site. Ready in about a minute."
TEMPLATE_EDIT_drupal-contrib := --display-name "Drupal Contrib Development" \
--description "Drupal contrib module/theme dev: clone any drupal.org project, optional issue branch checkout. Ready in 5-10 minutes."
TEMPLATE_EDIT_freeform := --display-name "DDEV Freeform (Traefik)" --default-ttl 24h
# Shared recipe for pushing any template (call with template name as argument)
define push_template
@echo "Syncing VERSION to $(1)..."
cp VERSION $(1)/VERSION
@echo "Pushing Coder template $(1)..."
coder templates push --directory $(1) $(1) --yes --activate=$(ACTIVATE) $(TEMPLATE_VARS_$(1))
@echo "Setting template metadata for $(1)..."
coder templates edit $(1) --yes $(TEMPLATE_EDIT_$(1))
@echo "Template $(1) push complete"
endef
# Default target
.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help message
@echo "Usage: make [target] [VAR=value ...]"
@echo ""
@echo "Targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-42s %s\n", $$1, $$2}'
@echo ""
@echo "Variables (override on command line, e.g. make push-template-drupal-core ACTIVATE=false):"
@grep -E '^[A-Z_]+ \?=.*##v .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = " \\?=.*##v "}; {printf " %-42s %s\n", $$1, $$2}'
.PHONY: build
build: ## Build Docker image with cache
@echo "Building $(IMAGE_TAG)..."
docker build -t $(IMAGE_TAG) -t $(IMAGE_LATEST) $(DOCKERFILE_DIR)
@echo "Build complete: $(IMAGE_TAG)"
.PHONY: build-no-cache
build-no-cache: ## Build Docker image without cache
@echo "Building $(IMAGE_TAG) without cache..."
docker build --no-cache -t $(IMAGE_TAG) -t $(IMAGE_LATEST) $(DOCKERFILE_DIR)
@echo "Build complete: $(IMAGE_TAG)"
.PHONY: push
push: ## Push Docker image to registry
@echo "Pushing $(IMAGE_TAG)..."
docker push $(IMAGE_TAG)
@echo "Pushing $(IMAGE_LATEST)..."
docker push $(IMAGE_LATEST)
@echo "Push complete"
.PHONY: build-and-push
build-and-push: build push ## Build and push Docker image with cache
.PHONY: build-and-push-no-cache
build-and-push-no-cache: build-no-cache push ## Build and push Docker image without cache
.PHONY: login
login: ## Login to Docker registry
@echo "Logging in to Docker Hub..."
docker login
.PHONY: test
test: ## Test the built image by running it
@echo "Testing $(IMAGE_TAG)..."
docker run --rm $(IMAGE_TAG) ddev --version
docker run --rm $(IMAGE_TAG) docker --version
docker run --rm $(IMAGE_TAG) node --version
@echo "Test complete"
.PHONY: validate
validate: ## Validate all Terraform templates (requires terraform in PATH)
@for t in $(TEMPLATES); do \
echo "--- Validating $$t ---"; \
(cd $$t && terraform init -backend=false -input=false -no-color && terraform validate -no-color) || exit 1; \
done
@echo "All templates valid."
.PHONY: fmt-check
fmt-check: ## Check Terraform formatting across all templates
terraform fmt -check -recursive
.PHONY: test-templates
test-templates: ## Run Terraform mock unit tests for all templates (requires terraform in PATH)
@for t in $(TEMPLATES); do \
echo "--- Testing $$t ---"; \
(cd $$t && terraform test) || exit 1; \
done
@echo "All template tests passed."
.PHONY: push-staging
push-staging: ## Push all templates to staging-coder.ddev.com inactive (ACTIVATE=false); requires CODER_URL set to staging
$(MAKE) push-all-templates ACTIVATE=false
.PHONY: archive-inactive-versions
archive-inactive-versions: ## Archive all inactive template versions (requires coder CLI pointed at target instance)
@for t in $(TEMPLATES); do \
echo "--- Archiving inactive versions for $$t ---"; \
versions=$$(coder templates versions list $$t --output json 2>/dev/null | jq -r '.[] | select(.active == false) | .TemplateVersion.name'); \
if [ -z "$$versions" ]; then \
echo " No inactive versions."; \
else \
for v in $$versions; do \
coder templates versions archive $$t --yes $$v 2>/dev/null \
&& echo " Archived $$v" \
|| echo " Skipped $$v (in use by a workspace)"; \
done; \
fi; \
done
.PHONY: clean
clean: ## Remove local image
@echo "Removing local images..."
docker rmi $(IMAGE_TAG) $(IMAGE_LATEST) 2>/dev/null || true
@echo "Clean complete"
.PHONY: info
info: ## Show image and template information
@echo "Version: $(VERSION)"
@echo "Image Name: $(IMAGE_NAME)"
@echo "Image Tag: $(IMAGE_TAG)"
@echo "Latest Tag: $(IMAGE_LATEST)"
@echo "Dockerfile: $(DOCKERFILE)"
@echo "Templates: $(TEMPLATES)"
# --- Template push targets ---
.PHONY: push-template-user-defined-web
push-template-user-defined-web: ## Push user-defined-web template to Coder
$(call push_template,user-defined-web)
.PHONY: push-template-drupal-core
push-template-drupal-core: ## Push drupal-core template to Coder
$(call push_template,drupal-core)
.PHONY: push-template-drupal-contrib
push-template-drupal-contrib: ## Push drupal-contrib template to Coder
$(call push_template,drupal-contrib)
.PHONY: push-template-freeform
push-template-freeform: ## Push freeform template to Coder
$(call push_template,freeform)
.PHONY: push-all-templates
push-all-templates: push-template-user-defined-web push-template-drupal-core push-template-drupal-contrib push-template-freeform ## Push all templates to Coder (no image build)
@echo "All templates pushed!"
# --- Deploy targets ---
.PHONY: deploy-user-defined-web
deploy-user-defined-web: build-and-push push-template-user-defined-web ## Build image, push image, and push user-defined-web template
@echo "Deployment of user-defined-web complete!"
.PHONY: deploy-user-defined-web-no-cache
deploy-user-defined-web-no-cache: build-and-push-no-cache push-template-user-defined-web ## Build image (no cache), push, and push user-defined-web template
@echo "Deployment of user-defined-web complete!"
.PHONY: deploy-drupal-core
deploy-drupal-core: push-template-drupal-core ## Deploy drupal-core template (uses existing image)
@echo "Deployment of drupal-core complete!"
.PHONY: deploy-drupal-contrib
deploy-drupal-contrib: push-template-drupal-contrib ## Deploy drupal-contrib template (uses existing image)
@echo "Deployment of drupal-contrib complete!"
.PHONY: deploy-freeform
deploy-freeform: push-template-freeform ## Deploy freeform template (uses existing image)
@echo "Deployment of freeform complete!"
.PHONY: deploy-all
deploy-all: build-and-push push-all-templates ## Build image, push image, and push all templates
@echo "All templates deployed!"