forked from ukit-network/passport-security
/
Makefile
87 lines (68 loc) · 2.03 KB
/
Makefile
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
DOCKER = docker
DOCKER_ORG = docker.pkg.github.com/gmsllc
PROJECT_NAME = devenv
COMPOSE_FILE = docker/env/development/docker-compose.yaml
DOCKER_COMPOSE = docker-compose --file $(COMPOSE_FILE) --project-name $(PROJECT_NAME)
GIT = git
SERVICE = passport-security
ifdef GITHUB_REF
BRANCH = $(subst refs/heads/,,$(GITHUB_REF))
else
BRANCH = $(shell $(GIT) rev-parse --abbrev-ref HEAD)
endif
BRANCH_SLUG = $(subst /,_,$(BRANCH))
DOCKER_REPO = $(DOCKER_ORG)/$(SERVICE)
CONTAINER_NAME = $(SERVICE)
CONTAINER_ID = $(shell $(DOCKER) ps --quiet --filter name=^/$(CONTAINER_NAME)$/)
export COMPOSE_DOCKER_CLI_BUILD = 1
export DOCKER_BUILDKIT = 1
export DOCKER_IMAGE = $(shell echo $(DOCKER_REPO)/$(SERVICE)-$(BRANCH_SLUG)-DEV | tr A-Z a-z)
.PHONY: login
login:
@echo $(DOCKER_REGISTRY_PASS) | docker login $(DOCKER_ORG) --username $(DOCKER_REGISTRY_USER) --password-stdin
.PHONY: push
push:
$(DOCKER_COMPOSE) push
.PHONY: down
down:
$(DOCKER_COMPOSE) down --volumes $(if $(REMOVE_IMAGES),--rmi all)
.PHONY: build
build:
$(DOCKER_COMPOSE) build --pull $(SERVICE)
.PHONY: ensure-networks
ensure-networks:
@-$(DOCKER) network create $(PROJECT_NAME)_$(DOCKER_ORG)
.PHONY: run
run: down build ensure-networks
$(DOCKER_COMPOSE) run $(if $(RUN_DETACHED),--detach )--no-deps --rm --service-ports --use-aliases --name $(CONTAINER_NAME) $(SERVICE) $(COMMAND)
.PHONY: logs
logs:
docker logs --follow $(CONTAINER_NAME)
.PHONY: exec
exec:
$(DOCKER) exec --interactive --tty $(CONTAINER_NAME) $(COMMAND)
.PHONY: command
command: $(if $(CONTAINER_ID),exec,run)
.PHONY: up
up: down
up: RUN_DETACHED = true
up: run
.PHONY: lint
lint: COMMAND = npm run lint
lint: command
.PHONY: test
test: COMMAND = npm test
test: command
.PHONY: shell
shell: COMMAND = bash
shell: command
.PHONY: publish
publish: COMMAND = npm publish
publish: command
.PHONY: confirm-clean
confirm-clean:
@echo -n "Are you sure? (this will delete all docker resources for this project) [y/N] " && read ans && [ $${ans:-N} = y ]
.PHONY: clean
clean: confirm-clean
clean: REMOVE_IMAGES = true
clean: down