-
Notifications
You must be signed in to change notification settings - Fork 538
/
Makefile-os
171 lines (137 loc) Β· 6.02 KB
/
Makefile-os
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
####################################################################################################
# Our makefile makes use of docker compose commands. Our config files rely on environment variables
# both for passing configuration to the containers as well as configuring the compose file itself.
# Variables referenced in docker-compose*.yml should be read from .env, exported and saved in .env
####################################################################################################
DOCKER_PROGRESS ?= auto
DOCKER_METADATA_FILE ?= buildx-bake-metadata.json
DOCKER_PUSH ?=
export DOCKER_COMMIT ?=
export DOCKER_BUILD ?=
export DOCKER_VERSION ?=
export DATA_BACKUP_SKIP ?=
override DOCKER_MYSQLD_VOLUME = addons-server_data_mysqld
INITIALIZE_ARGS ?=
INIT_CLEAN ?=
INIT_LOAD ?=
ifneq ($(INIT_CLEAN),)
INITIALIZE_ARGS += --clean
endif
ifneq ($(INIT_LOAD),)
INITIALIZE_ARGS += --load $(INIT_LOAD)
endif
DOCKER_BAKE_ARGS := \
--file docker-bake.hcl \
--file .env \
--progress $(DOCKER_PROGRESS) \
--metadata-file $(DOCKER_METADATA_FILE) \
ifeq ($(DOCKER_PUSH), true)
DOCKER_BAKE_ARGS += --push
endif
DOCKER_COMPOSE_ARGS := \
-d \
--wait \
--remove-orphans \
--no-build \
--quiet-pull \
--renew-anon-volumes
# Paths should be cleaned before mounting .:/data/olympia
# These are files which should be sourced from the container
# or should be fresh on every run of the project
CLEAN_PATHS := \
src/olympia.egg-info \
supervisord.pid \
version.json \
logs \
buildx-bake-metadata.json \
deps \
.PHONY: help_redirect
help_redirect:
@$(MAKE) help --no-print-directory
.PHONY: help_submake
help_submake:
@echo "Host only commands:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile-os | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo "\nAll other commands will be passed through to the docker 'web' container make:"
@make -f Makefile-docker help_submake
.PHONY: test_setup
test_setup:
npm exec jest -- ./tests/make --runInBand
.PHONY: setup
setup: ## create configuration files version.json and .env required to run this project
for path in $(CLEAN_PATHS); do rm -rf "$(PWD)/$$path" && echo "$$path removed"; done
./scripts/setup.py
.PHONY: push_locales
push_locales: ## extracts and merges translation strings
bash ./scripts/push_l10n_extraction.sh $(ARGS)
.PHONY: update_docker
update_docker: data_export up data_restore ## update all the docker images
.PHONY: shell
shell: ## connect to a running addons-server docker shell
docker compose exec --user olympia web bash
.PHONY: rootshell
rootshell: ## connect to a running addons-server docker shell with root user
docker compose exec --user root web bash
.PHONY: docker_compose_config
docker_compose_config: ## Show the docker compose configuration
@docker compose config web --format json
.PHONY: docker_build_web
docker_build_web: ## Build the docker images using buildx bake
docker buildx bake $(DOCKER_BAKE_ARGS) $(ARGS)
.PHONY: docker_pull_web
docker_pull_web: ## Pull the latest docker image using current tag
docker compose pull web --policy always
.PHONY: docker_pull_or_build ## Pull or build the docker image based on the image version
docker_pull_or_build:
# If the image is tagged with version "local" then we should build the image before running
# docker compose up. The image will be available to docker compose, skipping a pull attempt.
# This is useful for local development where the image is built and tagged with "local".
# Also for CI/CID pipelines on forks where we cannot pull the image and must build locally.
# If the image is tagged with a version other than "local" then we should skip the build
# and let docker compose pull the image instead. This is useful for CI/CD pipelines where
# the image is already built and pushed to a registry.
@IMAGE=$$(docker compose config web --format json | jq -r '.services.web.image'); \
echo "image: $$IMAGE"; \
if echo "$$IMAGE" | grep -q ":local"; then \
$(MAKE) docker_build_web; \
else \
$(MAKE) docker_pull_web; \
fi
.PHONY: docker_mysqld_volume_create
docker_mysqld_volume_create: ## Create the mysqld volume
docker volume create $(DOCKER_MYSQLD_VOLUME)
.PHONY: docker_mysqld_volume_remove
docker_mysqld_volume_remove: ## Remove the mysqld volume
docker volume rm $(DOCKER_MYSQLD_VOLUME)
.PHONY: docker_compose_down
docker_compose_down: ## Stop the docker containers
docker compose down --rmi local --remove-orphans --volumes
.PHONY: docker_clean_volumes
docker_clean_volumes: ## Remove dangling volumes, skipping the mysqld volume
docker volume prune \
--filter label=com.docker.compose.project=addons-server \
--all \
--force
.PHONY: docker_clean_images
docker_clean_images: ## Remove dangling images
docker image prune --filter "dangling=true" --force
.PHONY: docker_clean_build_cache
docker_clean_build_cache: ## Remove buildx build cache
docker buildx prune -af
.PHONY: clean_docker
clean_docker: docker_compose_down docker_mysqld_volume_remove docker_clean_images docker_clean_volumes docker_clean_build_cache ## Remove all docker resources taking space on the host machine
.PHONY: docker_compose_up
docker_compose_up: docker_mysqld_volume_create ## Start the docker containers
docker compose up $(DOCKER_COMPOSE_ARGS) $(ARGS)
.PHONY: up
up: setup docker_pull_or_build docker_compose_up docker_clean_images docker_clean_volumes ## Create and start docker compose
# Explicitly run initialize via the web container as make can get confused
# both routing the command to the web container and
# routing the command to the proper target.
docker compose exec --user olympia web make -f Makefile-docker initialize ARGS=$(shell echo "'$(INITIALIZE_ARGS)'")
.PHONY: down
down: docker_compose_down docker_clean_images docker_clean_volumes ## Stop the docker containers and clean up non-peristent dangling resources
%: ## This directs any other recipe (command) to the web container's make.
docker compose exec --user olympia web make $(MAKECMDGOALS) ARGS="$(shell echo $(ARGS))"
# You probably want to put new commands in Makefile-docker, unless they operate
# on multiple containers or are host-os specific.