docker.mk 1.21 KB
Newer Older
1
2
3
4
5
6
7
8
ifndef IMAGENAME
	ifdef CI_REGISTRY_IMAGE
		IMAGENAME=$(CI_REGISTRY_IMAGE)
	else
		IMAGENAME=$(NAME)
	endif
endif

9
IMAGEWTAG?=$(IMAGENAME):$(VERSION)
10
11
DOCKER_FLAGS?=$(-ti)
DOCKER_CMD?=
12

13
docker-login: ## Log in to the registry. It will only be used in the server, or when running a CI task locally (if CI_BUILD_TOKEN is set).
14
15
16
17
18
19
20
21
22
23
24
ifeq ($(CI_BUILD_TOKEN),)
	@echo "Not logging in to the docker registry" "$(CI_REGISTRY)"
else
	@docker login -u gitlab-ci-token -p $(CI_BUILD_TOKEN) $(CI_REGISTRY)
endif
ifeq ($(HUB_USER),)
	@echo "Not logging in to global the docker registry"
else
	@docker login -u $(HUB_USER) -p $(HUB_PASSWORD)
endif

25
docker-clean: ## Remove docker credentials
26
27
28
29
30
ifeq ($(HUB_USER),)
else
	@docker logout
endif

31
32
33
34
35
36
37
38
39
40
41
42
43
docker-run: ## Build a generic docker image
	docker run $(DOCKER_FLAGS) $(IMAGEWTAG) $(DOCKER_CMD)

docker-build: ## Build a generic docker image
	docker build . -t $(IMAGEWTAG)

docker-push: docker-login ## Push a generic docker image
	docker push $(IMAGEWTAG)

docker-latest-push: docker-login ## Push the latest image
	docker tag $(IMAGEWTAG) $(IMAGENAME)
	docker push $(IMAGENAME)

44
45
46
47
login:: docker-login

clean:: docker-clean

48
49
50
docker-info:
	@echo IMAGEWTAG=${IMAGEWTAG}

51
.PHONY:: docker-login docker-clean login clean