addons-server/Makefile-os

89 строки
3.2 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
DOCKER_COMMIT := $(shell git rev-parse HEAD)
DOCKER_CACHE_DIR := docker-cache
.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: 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
.PHONY: build_docker_image
build_docker_image: create_docker_builder ## Build the docker image
DOCKER_BUILDKIT=1 docker buildx build \
-t $(DOCKER_TAG) \
--load \
--platform $(DOCKER_PLATFORM) \
--progress=$(DOCKER_PROGRESS) \
--cache-to=type=local,dest=$(DOCKER_CACHE_DIR)-new \
--cache-from=type=local,src=$(DOCKER_CACHE_DIR),mode=max \
--builder=$(DOCKER_BUILDER) \
--label git.commit=$(DOCKER_COMMIT) \
.
rm -rf $(DOCKER_CACHE_DIR)
mv $(DOCKER_CACHE_DIR)-new $(DOCKER_CACHE_DIR)
.PHONY: initialize_docker
initialize_docker: create_env_file
# 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.