Skip to content
Snippets Groups Projects
Commit e0d14a0b authored by Thomas Juerges's avatar Thomas Juerges
Browse files

Merge branch '2021-03-22T14.42.30-branched_from_master-Makefile_refactoring' into 'master'

Small refactoring of the Makefile

See merge request !21
parents b9e49e63 75c78bc7
No related branches found
No related tags found
1 merge request!21Small refactoring of the Makefile
...@@ -2,30 +2,33 @@ ...@@ -2,30 +2,33 @@
MAKEPATH := $(abspath $(lastword $(MAKEFILE_LIST))) MAKEPATH := $(abspath $(lastword $(MAKEFILE_LIST)))
BASEDIR := $(notdir $(patsubst %/,%,$(dir $(MAKEPATH)))) BASEDIR := $(notdir $(patsubst %/,%,$(dir $(MAKEPATH))))
DOCKER_COMPOSE_ENV_FILE := $(abspath .env)
COMPOSE_FILES := $(wildcard *.yml) COMPOSE_FILES := $(wildcard *.yml)
COMPOSE_FILE_ARGS := $(foreach yml,$(COMPOSE_FILES),-f $(yml)) COMPOSE_FILE_ARGS := --env-file $(DOCKER_COMPOSE_ENV_FILE) $(foreach yml,$(COMPOSE_FILES),-f $(yml))
ATTACH_COMPOSE_FILE_ARGS := $(foreach yml,$(filter-out tango.yml,$(COMPOSE_FILES)),-f $(yml)) ATTACH_COMPOSE_FILE_ARGS := $(foreach yml,$(filter-out tango.yml,$(COMPOSE_FILES)),-f $(yml))
# If the first make argument is "start" or "stop"... # If the first make argument is "start" or "stop"...
ifeq (start,$(firstword $(MAKECMDGOALS))) ifeq (start,$(firstword $(MAKECMDGOALS)))
SERVICE_TARGET = true SERVICE_TARGET = true
else ifeq (stop,$(firstword $(MAKECMDGOALS))) else ifeq (stop,$(firstword $(MAKECMDGOALS)))
SERVICE_TARGET = true SERVICE_TARGET = true
else ifeq (attach,$(firstword $(MAKECMDGOALS))) else ifeq (attach,$(firstword $(MAKECMDGOALS)))
SERVICE_TARGET = true SERVICE_TARGET = true
ifndef NETWORK_MODE ifndef NETWORK_MODE
$(error NETWORK_MODE must specify the network to attach to, e.g., make NETWORK_MODE=tangonet-powersupply ...) $(error NETWORK_MODE must specify the network to attach to, e.g., make NETWORK_MODE=tangonet-powersupply ...)
endif endif
ifndef TANGO_HOST
$(error TANGO_HOST must specify the Tango database device, e.g., make TANGO_HOST=powersupply-databaseds:10000 ...) ifndef TANGO_HOST
endif $(error TANGO_HOST must specify the Tango database device, e.g., make TANGO_HOST=powersupply-databaseds:10000 ...)
endif
endif endif
ifdef SERVICE_TARGET ifdef SERVICE_TARGET
# .. then use the rest as arguments for the make target # .. then use the rest as arguments for the make target
SERVICE := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) SERVICE := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets # ...and turn them into do-nothing targets
$(eval $(SERVICE):;@:) $(eval $(SERVICE):;@:)
endif endif
# #
...@@ -35,37 +38,41 @@ endif ...@@ -35,37 +38,41 @@ endif
# time. # time.
# #
ifneq ($(CI_JOB_ID),) ifneq ($(CI_JOB_ID),)
NETWORK_MODE := tangonet-$(CI_JOB_ID) NETWORK_MODE := tangonet-$(CI_JOB_ID)
CONTAINER_NAME_PREFIX := $(CI_JOB_ID)- CONTAINER_NAME_PREFIX := $(CI_JOB_ID)-
else else
CONTAINER_NAME_PREFIX := CONTAINER_NAME_PREFIX :=
$(info Network mode cannot be host for the archiver! It won't work unless you set the env var CI_JOB_ID=local) $(info Network mode cannot be host for the archiver! It won't work unless you set the env var CI_JOB_ID=local)
endif endif
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
$(error Sorry, Windows is not supported yet) $(error Sorry, Windows is not supported yet)
else else
UNAME_S := $(shell uname -s) UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
DISPLAY ?= :0.0 ifeq ($(UNAME_S),Linux)
NETWORK_MODE ?= host DISPLAY ?= :0.0
XAUTHORITY_MOUNT := /tmp/.X11-unix:/tmp/.X11-unix NETWORK_MODE ?= host
XAUTHORITY ?= /hosthome/.Xauthority XAUTHORITY_MOUNT := /tmp/.X11-unix:/tmp/.X11-unix
# /bin/sh (=dash) does not evaluate 'docker network' conditionals correctly XAUTHORITY ?= /hosthome/.Xauthority
SHELL := /bin/bash # /bin/sh (=dash) does not evaluate 'docker network' conditionals correctly
endif SHELL := /bin/bash
ifeq ($(UNAME_S),Darwin) else ifeq ($(UNAME_S),Darwin)
IF_INTERFACE := $(shell scutil --nwi | grep 'Network interfaces:' | cut -d' ' -f3) IF_INTERFACE := $(shell scutil --nwi | grep 'Network interfaces:' | cut -d' ' -f3)
IP_ADDRESS := $(shell scutil --nwi | grep 'address' | cut -d':' -f2 | tr -d ' ' | head -n1) IP_ADDRESS := $(shell scutil --nwi | grep 'address' | cut -d':' -f2 | tr -d ' ' | head -n1)
DISPLAY := $(IP_ADDRESS):0 DISPLAY := $(IP_ADDRESS):0
# Make sure that Darwin, especially from macOS Catalina on, # Make sure that Darwin, especially from macOS Catalina on,
# allows X access from our Docker containers. # allows X access from our Docker containers.
ADD_TO_XHOST := $(shell xhost +$(IP_ADDRESS)) ADD_TO_XHOST := $(shell xhost +$(IP_ADDRESS))
# network_mode = host doesn't work on MacOS, so fix to the internal network # network_mode = host doesn't work on MacOS, so fix to the internal network
NETWORK_MODE ?= tangonet ifeq ($(NETWORK_MODE),)
XAUTHORITY_MOUNT := $(HOME)/.Xauthority:/hosthome/.Xauthority:ro NETWORK_MODE := tangonet
XAUTHORITY := /hosthome/.Xauthority else
endif NETWORK_MODE := $(NETWORK_MODE)
endif
XAUTHORITY_MOUNT := $(HOME)/.Xauthority:/hosthome/.Xauthority:ro
XAUTHORITY := /hosthome/.Xauthority
endif
endif endif
# #
...@@ -73,16 +80,33 @@ endif ...@@ -73,16 +80,33 @@ endif
# machine rather than at the container. # machine rather than at the container.
# #
ifeq ($(NETWORK_MODE),host) ifeq ($(NETWORK_MODE),host)
TANGO_HOST := $(shell hostname):10000 TANGO_HOST := $(shell hostname):10000
MYSQL_HOST := $(shell hostname):3306 MYSQL_HOST := $(shell hostname):3306
else else
TANGO_HOST := $(CONTAINER_NAME_PREFIX)databaseds:10000 ifeq ($(TANGO_HOST),)
MYSQL_HOST := $(CONTAINER_NAME_PREFIX)tangodb:3306 TANGO_HOST := $(CONTAINER_NAME_PREFIX)databaseds:10000
else
TANGO_HOST := $(TANGO_HOST)
endif
ifeq ($(MYSQL_HOST),)
MYSQL_HOST := $(CONTAINER_NAME_PREFIX)tangodb:3306
else
MYSQL_HOST := $(MYSQL_HOST)
endif
endif endif
DOCKER_COMPOSE_ARGS := DISPLAY=$(DISPLAY) XAUTHORITY=$(XAUTHORITY) TANGO_HOST=$(TANGO_HOST) \ DOCKER_COMPOSE_ARGS := DISPLAY=$(DISPLAY) \
NETWORK_MODE=$(NETWORK_MODE) XAUTHORITY_MOUNT=$(XAUTHORITY_MOUNT) TANGO_SKA_CONTAINER_MOUNT=$(TANGO_SKA_CONTAINER_MOUNT) TANGO_LOFAR_CONTAINER_MOUNT=$(TANGO_LOFAR_CONTAINER_MOUNT) TANGO_LOFAR_CONTAINER_DIR=${TANGO_LOFAR_CONTAINER_DIR} MYSQL_HOST=$(MYSQL_HOST) \ XAUTHORITY=$(XAUTHORITY) \
CONTAINER_NAME_PREFIX=$(CONTAINER_NAME_PREFIX) COMPOSE_IGNORE_ORPHANS=true CONTAINER_EXECUTION_UID=$(shell id -u) TANGO_HOST=$(TANGO_HOST) \
NETWORK_MODE=$(NETWORK_MODE) \
XAUTHORITY_MOUNT=$(XAUTHORITY_MOUNT) \
TANGO_SKA_CONTAINER_MOUNT=$(TANGO_SKA_CONTAINER_MOUNT) \
TANGO_LOFAR_CONTAINER_MOUNT=$(TANGO_LOFAR_CONTAINER_MOUNT) \
TANGO_LOFAR_CONTAINER_DIR=${TANGO_LOFAR_CONTAINER_DIR} MYSQL_HOST=$(MYSQL_HOST) \
CONTAINER_NAME_PREFIX=$(CONTAINER_NAME_PREFIX) \
COMPOSE_IGNORE_ORPHANS=true \
CONTAINER_EXECUTION_UID=$(shell id -u)
.PHONY: up down minimal start stop status clean pull help .PHONY: up down minimal start stop status clean pull help
...@@ -132,4 +156,3 @@ clean: down ## clear all TANGO database entries ...@@ -132,4 +156,3 @@ clean: down ## clear all TANGO database entries
help: ## show this help. help: ## show this help.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment