-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
146 lines (126 loc) · 4.46 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
141
142
143
## =============================================================
## Utilities to develop a full machine learning pipeline on EMAP
## =============================================================
##
UID := $(shell id -u)
GID := $(shell id -g)
# These two lines make local environment variables available to Make
include .env
export $(shell sed 's/=.*//' .env)
# Self-documenting help; any comment line starting ## will be printed
# https://swcarpentry.github.io/make-novice/08-self-doc/index.html
## help : call this help function
.PHONY: help
help : Makefile
@sed -n 's/^##//p' $<
## app-buildso : builds the app as a standalone (so) container for testing
.PHONY: app-buildso
app-buildso: dockerfile-app
cp dev/setup.R app/setup.R
cp dev/app.R app/app.R
cp -R dev/app app/app
docker build \
--file dockerfile-app \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg HTTP_PROXY \
--build-arg HTTPS_PROXY \
--build-arg USER_NAME=$(USER) \
--build-arg USER_ID=$(UID) \
--build-arg GROUP_ID=$(GID) \
. -t app-$(APP_NAME)
## app-runso : runs the app as a standalone (so) container for testing
## imports identical environment file etc.
.PHONY: app-runso
app-runso:
docker run \
--rm -ti \
--name appso-$(APP_NAME) \
--env-file=.env \
-u $(UID):$(GID) \
app-$(APP_NAME) \
/bin/bash
## app-build : builds the app
.PHONY: app-build
app-build:
# cp dev/app.R app/app.R
cp -R dev/app app/
docker-compose build \
--build-arg USER_NAME=$(USER) \
--build-arg USER_ID=$(UID) \
--build-arg GROUP_ID=$(GID)
## app-run1 : runs the app just once
.PHONY: app-run1
app-run1:
docker-compose run app Rscript app.R
## app-run : runs the app as per the frequency defined in docker-compose
## (a log will also run automatically; this can be cancelled by Ctrl-C)
.PHONY: app-run
app-run:
docker-compose up -d
docker-compose logs -f
## app-clean : cleans the app up
.PHONY: app-clean
app-clean:
docker-compose down
## dev-build : builds the dev containers (just Rstudio for now)
.PHONY: dev-build
dev-build: rstudio-build
## dev-up : sets up Rstudio (8790) and PGWeb (8791)
## e.g. go to http://172.16.149:155:8790 for RStudio
## You may need to edit the port numbers if others are using this set-up on the same machine
.PHONY: dev-up
dev-up: rstudio-run pgweb-run
## rstudio-build : builds the Rstudio container
.PHONY: rstudio-build
rstudio-build: dockerfile-rstudio
docker build \
--file dockerfile-rstudio \
--build-arg http_proxy \
--build-arg https_proxy \
--build-arg HTTP_PROXY \
--build-arg HTTPS_PROXY \
. -t r4-tidyv
## rstudio-run : runs the Rstudio container (the username is rstudio)
## (the password to Rstudio is set in this section of the Makefile)
.PHONY: rstudio-run
rstudio-run:
@docker run --rm \
-p 8790:8787 \
-e PASSWORD=notbot \
-e USERID=$(UID) \
-e ROOT=true \
-v $(PWD)/dev:/home/rstudio/dev \
-v $(PWD)/renv:/home/rstudio/renv \
-d \
--name rstudio-ofelia \
r4-tidyv
@echo "*** Rstudio should be available on port 8790"
## pgweb-run : Run pgweb and connect automaticaly to the UDS
.PHONY: pgweb-run
pgweb-run:
@docker run -p 8791:8081 -d --rm \
--name pgweb_uds \
-e DATABASE_URL=postgres://sharris9:$(UDS_PWD)@172.16.149.132:5432/uds?sslmode=disable \
sosedoff/pgweb
@echo "*** PGWeb should be available on port 8791"
# clean up dev stuff
## dev-clean : Stops and removes the RStudio and pgweb containers
.PHONY: dev-clean
dev-clean:
docker stop rstudio-ofelia
docker stop pgweb_uds
##
## =============================================================
##
# Useful generic code chunks
# Not part of the main makefile
# fix permissions on the GAE
.PHONY: fix-permissions
fix-permissions:
# Set the group for all files to be docker. All GAE users are in the docker group
chgrp -R docker .
# Grant read, write, and open folder permission for all exisiting files to the docker group, and make new folders created have the docker group
chmod -R g+rwXs .
# For all the directories in here, make all new files created by default have the right group privileges, irrespective of the user UMASK
setfacl -R –d –m g::rwX /.