-
Notifications
You must be signed in to change notification settings - Fork 43
/
Makefile
73 lines (62 loc) · 2.84 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
.PHONY: bundle build push docker-run
IMAGE_NAME := quay.io/app-sre/qontract-server
IMAGE_TAG := $(shell git rev-parse --short=7 HEAD)
APP_INTERFACE_PATH ?= $(shell pwd)/../../service/app-interface
CONTAINER_ENGINE ?= $(shell which podman >/dev/null 2>&1 && echo podman || echo docker)
CONTAINER_SELINUX_FLAG ?= :z
SCHEMAS_PATH ?= $(shell pwd)/../qontract-schemas
SCHEMAS_DIR := $(SCHEMAS_PATH)/schemas
GRAPHQL_SCHEMA_DIR := $(SCHEMAS_PATH)/graphql-schemas
DATA_DIR_NAME ?= data
DATA_DIR := $(APP_INTERFACE_PATH)/$(DATA_DIR_NAME)
RESOURCES_DIR := $(APP_INTERFACE_PATH)/resources
BUNDLE_DIR := $(shell pwd)/bundle
BUNDLE_FILENAME := bundle.json
SERVER_CONTAINER_NAME ?= qontract-server
VALIDATOR_CONTAINER_NAME ?= qontract-validator
VALIDATOR_IMAGE_NAME ?= quay.io/app-sre/qontract-validator
VALIDATOR_IMAGE_TAG ?= latest
GIT_COMMIT := $(shell cd $(APP_INTERFACE_PATH) && git rev-parse HEAD)
GIT_COMMIT_TIMESTAMP := $(shell cd $(APP_INTERFACE_PATH) && git log -1 --format=%ct $(GIT_COMMIT))
ifneq (,$(wildcard $(CURDIR)/.docker))
DOCKER_CONF := $(CURDIR)/.docker
else
DOCKER_CONF := $(HOME)/.docker
endif
dev: docker-run-clean bundle docker-run
reload: bundle
curl -X POST http://localhost:4000/reload
bundle:
@$(CONTAINER_ENGINE) pull $(VALIDATOR_IMAGE_NAME):$(VALIDATOR_IMAGE_TAG)
mkdir -p $(BUNDLE_DIR)
@$(CONTAINER_ENGINE) run --rm --name $(VALIDATOR_CONTAINER_NAME) \
-v $(SCHEMAS_DIR):/schemas$(CONTAINER_SELINUX_FLAG) \
-v $(GRAPHQL_SCHEMA_DIR):/graphql$(CONTAINER_SELINUX_FLAG) \
-v $(DATA_DIR):/data$(CONTAINER_SELINUX_FLAG) \
-v $(RESOURCES_DIR):/resources$(CONTAINER_SELINUX_FLAG) \
$(VALIDATOR_IMAGE_NAME):$(VALIDATOR_IMAGE_TAG) \
qontract-bundler /schemas /graphql/schema.yml /data /resources $(GIT_COMMIT) $(GIT_COMMIT_TIMESTAMP) > $(BUNDLE_DIR)/$(BUNDLE_FILENAME)
@$(CONTAINER_ENGINE) run --rm --name $(VALIDATOR_CONTAINER_NAME) \
-v $(BUNDLE_DIR):/bundle$(CONTAINER_SELINUX_FLAG) \
$(VALIDATOR_IMAGE_NAME):$(VALIDATOR_IMAGE_TAG) \
qontract-validator --only-errors /bundle/$(BUNDLE_FILENAME)
run:
LOAD_METHOD=fs DATAFILES_FILE=$(BUNDLE_DIR)/$(BUNDLE_FILENAME) yarn run server
debug:
LOAD_METHOD=fs DATAFILES_FILE=$(BUNDLE_DIR)/$(BUNDLE_FILENAME) yarn run debug
docker-run:
@$(CONTAINER_ENGINE) run -it --rm --name $(SERVER_CONTAINER_NAME) \
-v $(BUNDLE_DIR):/bundle$(CONTAINER_SELINUX_FLAG) \
-p 4000:4000 \
-e LOAD_METHOD=fs \
-e DATAFILES_FILE=/bundle/$(BUNDLE_FILENAME) \
$(IMAGE_NAME):$(IMAGE_TAG)
docker-run-clean:
@$(CONTAINER_ENGINE) rm -f $(SERVER_CONTAINER_NAME) || true
@$(CONTAINER_ENGINE) rm -f $(VALIDATOR_CONTAINER_NAME) || true
build:
@$(CONTAINER_ENGINE) build --pull -t $(IMAGE_NAME):latest .
@$(CONTAINER_ENGINE) tag $(IMAGE_NAME):latest $(IMAGE_NAME):$(IMAGE_TAG)
push:
@$(CONTAINER_ENGINE) --config=$(DOCKER_CONF) push $(IMAGE_NAME):latest
@$(CONTAINER_ENGINE) --config=$(DOCKER_CONF) push $(IMAGE_NAME):$(IMAGE_TAG)