112 строки
4.1 KiB
Plaintext
112 строки
4.1 KiB
Plaintext
UID := $(shell id -u)
|
|
GID := $(shell id -g)
|
|
export UID
|
|
export GID
|
|
|
|
export DOCKER_BUILDER=container
|
|
|
|
DOCKER_TAG := addons-server-test
|
|
DOCKER_PLATFORM := linux/amd64
|
|
DOCKER_PROGRESS := auto
|
|
export DOCKER_COMMIT := $(shell git rev-parse HEAD || echo "commit")
|
|
DOCKER_CACHE_DIR := docker-cache
|
|
|
|
export DOCKER_VERSION ?= local
|
|
export VERSION_BUILD_URL ?= build
|
|
|
|
.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: push_locales
|
|
push_locales: ## extracts and merges translation strings
|
|
bash ./scripts/push_l10n_extraction.sh $(ARGS)
|
|
|
|
.PHONY: update_docker
|
|
update_docker: ## update all the docker images
|
|
docker compose exec --user olympia worker make update_deps
|
|
docker compose exec --user olympia web make update
|
|
docker compose restart web
|
|
docker compose restart worker
|
|
|
|
.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: create_env_file
|
|
create_env_file:
|
|
echo "UID=${UID}\nGID=${GID}" > .env
|
|
|
|
.PHONY: create_docker_builder
|
|
create_docker_builder: ## Create a custom builder for buildkit to efficiently build local images
|
|
docker buildx use $(DOCKER_BUILDER) 2>/dev/null || docker buildx create \
|
|
--name $(DOCKER_BUILDER) \
|
|
--driver=docker-container
|
|
|
|
DOCKER_BUILD_ARGS := -t $(DOCKER_TAG) \
|
|
--load \
|
|
--platform $(DOCKER_PLATFORM) \
|
|
--progress=$(DOCKER_PROGRESS) \
|
|
--builder=$(DOCKER_BUILDER) \
|
|
--label git.commit=$(DOCKER_COMMIT) \
|
|
--cache-to=type=local,dest=$(DOCKER_CACHE_DIR)-new \
|
|
|
|
DOCKER_CACHE_INDEX = $(wildcard $(DOCKER_CACHE_DIR)/index.json)
|
|
|
|
ifneq ($(DOCKER_CACHE_INDEX),)
|
|
DOCKER_BUILD_ARGS += --cache-from=type=local,src=$(DOCKER_CACHE_DIR),mode=max
|
|
endif
|
|
|
|
.PHONY: version
|
|
version: ## create version.json file
|
|
./scripts/version.sh $(DOCKER_VERSION) $(DOCKER_COMMIT) $(VERSION_BUILD_URL)
|
|
|
|
.PHONY: build_docker_image
|
|
build_docker_image: create_docker_builder version ## Build the docker image
|
|
DOCKER_BUILDKIT=1 docker buildx build $(DOCKER_BUILD_ARGS) .
|
|
rm -rf $(DOCKER_CACHE_DIR)
|
|
mv $(DOCKER_CACHE_DIR)-new $(DOCKER_CACHE_DIR)
|
|
|
|
.PHONY: clean_docker
|
|
clean_docker: ## Clean up docker containers, images, caches, volumes and local cache directories. Use with caution. To restart the app run make initialize_docker after this commandUse with caution.
|
|
docker compose down --rmi all --volumes
|
|
docker rmi $(DOCKER_TAG) || true
|
|
rm -rf $(DOCKER_CACHE_DIR)
|
|
rm -rf ./deps/**
|
|
|
|
.PHONY: initialize_docker
|
|
initialize_docker: create_env_file build_docker_image
|
|
# Run a fresh container from the base image to install deps. Since /deps is
|
|
# shared via a volume in docker-compose.yml, this installs deps for both web
|
|
# and worker containers, and does so without requiring the containers to be up.
|
|
# We just create dummy empty package.json and package-lock.json in deps/ so
|
|
# that docker compose doesn't create dummy ones itself, as they would be owned
|
|
# by root. They don't matter: the ones at the root directory are mounted
|
|
# instead.
|
|
touch deps/package.json
|
|
touch deps/package-lock.json
|
|
# Note that this is running with --user ${UID}:${GID} because the user olympia
|
|
# would be uid 9500 regardless of host at this point (this is only fixed when
|
|
# the container is up, through the command defined in docker-compose.yml),
|
|
# which is wrong for local development.
|
|
docker compose run --rm --user ${UID}:${GID} web make update_deps
|
|
docker compose up -d
|
|
docker compose exec --user olympia web make initialize
|
|
|
|
%: ## This directs any other recipe (command) to the web container's make.
|
|
docker compose exec --user olympia web make $(MAKECMDGOALS) ARGS=$(ARGS)
|
|
|
|
# You probably want to put new commands in Makefile-docker, unless they operate
|
|
# on multiple containers or are host-os specific.
|