forked from meyerson/anbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
140 lines (117 loc) · 3.89 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Builds the dependencies packaged as a docker image. Assumes docker is
# installed. If not, go to: https://www.docker.com/products/overview
# #
# * * * environment * * * #
# #
DOCKER := $(shell command -v docker 2> /dev/null)
VERSION := $(shell git rev-parse HEAD | tr -d '\n'; git diff-index -w --quiet HEAD -- || echo "")
DOCKER_REGISTRY := registry.hub.docker.com
DOCKER_REPO := dmeyerson
DOCKER_NAME := anbox
WORKER_NAME := anbox_worker
DOCKER_BASE_HASH := $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(DOCKER_NAME):$(VERSION)
DOCKER_BASE_LATEST := $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(DOCKER_NAME):latest
DOCKER_WORK_HASH := $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(WORKER_NAME):$(VERSION)
DOCKER_WORK_LATEST := $(DOCKER_REGISTRY)/$(DOCKER_REPO)/$(WORKER_NAME):latest
ANDROID_IMAGED_DIR := /mnt/store/android_images
USER_NAME := scraper
AWS_PROFILE := default
# TODO: respect pre-existing env vars
.PHONY: deps
deps:
ifndef DOCKER
$(error 'docker' binary is not found; please install Docker, as the app is containerized for portability)
endif
.PHONY: envvars
envvars:
ifndef DOCKER_NAME
$(error 'DOCKER_NAME' environment variable is undefined)
endif
ifndef DOCKER_REGISTRY
$(error 'DOCKER_REGISTRY' environment variable is undefined)
endif
ifndef DOCKER_REPO
$(error 'DOCKER_REPO' environment variable is undefined)
endif
ifndef VERSION
$(error 'VERSION' environment variable is undefined)
endif
# #
# * * * help * * * #
# #
.PHONY: help
help:
@echo
@echo ' make build - build the docker image tagged with the latest commit hash and "latest"'
@echo ' make notebook - start jupyter notebook server'
@echo ' make docs - generate documentation in the container locally'
@echo ' make shell - open a shell in the container locally'
@echo ' make push_docker - push the built image with git commit hash tag and "latest" to docker repo'
@echo ' make stop - stop and remove the local running app container'
@echo ' make test - run python tests'
@echo
# #
# * * * targets * * * #
# #
# white space changes will trigger partial rebuilds
.PHONY: build_base
build_base: deps envvars
docker build \
-t $(DOCKER_BASE_HASH) \
-t $(DOCKER_BASE_LATEST) \
-f Dockerfile .
.PHONY: build_worker
build_worker: deps envvars build_base
docker build \
-t $(DOCKER_WORK_HASH) \
-t $(DOCKER_WORK_LATEST) \
-f Dockerfile_worker .
.PHONY: push_docker
push_docker:
until docker push $(DOCKER_WORK_LATEST); do docker login $(DOCKER_REGISTRY); done
until docker push $(DOCKER_BASE_LATEST); do docker login $(DOCKER_REGISTRY); done
.PHONY: prep_host
prep_host:
pacaur -Sy aur/anbox-modules-dkms-git
sudo modprobe ashmem_linux
sudo modprobe binder_linux
# TODO - grab android img as needed
.PHONY: run
run: deps envvars stop build_worker
docker run -it \
--net=host \
--env="DISPLAY" \
--volume=$(HOME)/.Xauthority:/root/.Xauthority:rw \
-v /mnt/store/android_images:/var/lib/anbox/ \
--privileged \
-v /tmp/.X11-unix:/tmp/.X11-unix \
$(DOCKER_WORK_LATEST) \
/bin/bash # really hacky :(
.PHONY: shell
shell: deps envvars stop build_worker
docker run -it \
--net=host \
--env="DISPLAY" \
--volume=$(HOME)/.Xauthority:/root/.Xauthority:rw \
-v /mnt/store/android_images:/var/lib/anbox/ \
--privileged \
-v /tmp/.X11-unix:/tmp/.X11-unix \
$(DOCKER_WORK_LATEST) \
/bin/bash
.PHONY: viz_confirm
viz_confirm: deps envvars stop
docker run -it \
--net=host \
--env="DISPLAY" \
--volume=$(HOME)/.Xauthority:/root/.Xauthority:rw \
--privileged \
-v /tmp/.X11-unix:/tmp/.X11-unix \
$(DOCKER_WORK_LATEST) \
xeyes
.PHONY: test
test: build stop
docker run -it $(DOCKER_TAG_HASH) pytest --disable-warnings -vv --pyargs src
.PHONY: stop
stop: deps envvars
docker stop $(DOCKER_NAME) 2> /dev/null || true
docker rm $(DOCKER_NAME) 2> /dev/null || true