-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdocker
More file actions
108 lines (90 loc) · 2.86 KB
/
Copy pathdocker
File metadata and controls
108 lines (90 loc) · 2.86 KB
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
##################################################################
# Docker shortcuts for make
#
# Usage examples:
#
# make -f docker build # builds a slendr Docker image
# make -f docker bash # creates an interactive shell
# make -f docker R # creates an interactive R session
# make -f docker rstudio # creates an RStudio Server instance
#
VERSION := dev
# check the OS type to assign appropriate Docker image tag
ifeq ($(shell uname -s), Darwin)
PLATFORM ?= arm64
else
PLATFORM ?= amd64
endif
IMAGE := bodkan/slendr-$(VERSION):$(PLATFORM)
CONTAINER := slendr
# if present, extract GitHub access token
TOKEN := $(shell if [ -f ~/.GITHUB_PAT ]; then more ~/.GITHUB_PAT; else echo ""; fi)
.PHONY: rstudio bash r build push pull local-webapp remote-webapp
bash:
docker run --rm -ti -v $(shell pwd):/project -w /project --name $(CONTAINER) $(IMAGE) bash
r:
docker run --rm -ti -v $(shell pwd):/project -w /project --name $(CONTAINER) $(IMAGE) R
attach:
container_id=`docker ps | awk -v name=slendr '$$2 ~ name {print $$1}'`; \
docker exec -it $$container_id /bin/bash
rstudio:
ifndef PORT
$(error PORT variable must be set explicitly)
endif
docker run --rm -ti -p $(PORT):8787 -e RUNROOTLESS=true -e DISABLE_AUTH=true -v $(shell pwd):/project --name $(CONTAINER) $(IMAGE)
jupyter:
ifndef PORT
$(error PORT variable must be set explicitly)
endif
docker run --rm -p $(PORT):$(PORT) -v $(shell pwd):/project --name $(CONTAINER) $(IMAGE) jupyter-lab --allow-root --ip=0.0.0.0 --port=$(PORT) --LabApp.token='' --no-browser
build:
docker build --build-arg GITHUB_PAT=$(TOKEN) --build-arg VERSION=$(VERSION) -t $(IMAGE) .
build-clean:
@echo $(IMAGE)
docker build --no-cache --build-arg GITHUB_PAT=$(TOKEN) -t $(IMAGE) .
push:
docker push $(IMAGE)
pull:
docker pull $(IMAGE)
stop:
docker stop $(CONTAINER) || true
local-webapp:
ifndef PORT
$(error PORT variable must be set explicitly)
endif
chromium --app=http://localhost:$(PORT) &
remote-webapp:
ifndef SERVER
$(error SERVER variable must be set to start a web app)
endif
ifndef PORT
$(error PORT variable must be set explicitly)
endif
@if [[ "$(SERVER)" != "localhost" ]]; then \
PID=$$(lsof -ti:$(PORT)); \
if [[ -n "$$PID" ]]; then \
kill -9 $$PID; \
fi; \
autossh -M 0 -f -N -L localhost:$(PORT):localhost:$(PORT) $(SERVER) || { \
echo "SSH connection failed. Exiting."; \
exit 1; \
}; \
fi; \
chromium --app=http://localhost:$(PORT) &
port-forward:
ifndef SERVER
$(error SERVER variable must be set to start a web app)
endif
ifndef PORT
$(error PORT variable must be set explicitly)
endif
@if [[ "$(SERVER)" != "localhost" ]]; then \
PID=$$(lsof -ti:$(PORT)); \
if [[ -n "$$PID" ]]; then \
kill -9 $$PID; \
fi; \
autossh -M 0 -f -N -L localhost:$(PORT):localhost:$(PORT) $(SERVER) || { \
echo "SSH connection failed. Exiting."; \
exit 1; \
}; \
fi