forked from elephant-track/elephant-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elephant.def
95 lines (80 loc) · 3.45 KB
/
elephant.def
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
Bootstrap: docker
From: pytorch/pytorch:1.10.0-cuda11.3-cudnn8-runtime
%files
./docker /docker
./script /opt/elephant/script
./app /app
./elephant-core /src/elephant-core
./environment.yml /src/environment.yml
%environment
export UWSGI_UID=$(id -u)
export UWSGI_GID=$(id -g)
export UWSGI_CHOWN_SOCKET=$(id -u):$(id -g)
export PYTHONPATH=/app
export MKL_THREADING_LAYER=GNU
export GRPC_POLL_STRATEGY=epoll1
%post
# Install requirements
set -x \
&& apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y \
nginx \
redis-server \
supervisor \
ca-certificates \
curl \
gnupg && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install Python modules
sed -i 's/.\/elephant-core/\/src\/elephant-core/g' /src/environment.yml \
&& conda install -c conda-forge -y mamba \
&& mamba env update -f /src/environment.yml \
&& mamba clean -qafy \
&& rm -rf /src/elephant-core \
&& rm /src/environment.yml
# Install and set up RabbbitMQ
chmod +x /docker/install-rabbitmq.sh && /docker/install-rabbitmq.sh
RABBITMQ_USER=user && RABBITMQ_PASSWORD=user
service rabbitmq-server start
rabbitmqctl add_user $RABBITMQ_USER $RABBITMQ_PASSWORD 2>/dev/null
rabbitmqctl set_user_tags $RABBITMQ_USER administrator
rabbitmqctl set_permissions -p / $RABBITMQ_USER ".*" ".*" ".*"
service rabbitmq-server stop
# Set up nginx
cp /docker/nginx.conf /etc/nginx/nginx.conf
groupadd nginx && useradd -g nginx nginx
sed -i 's/listen 80/listen 8080/g' /etc/nginx/nginx.conf
# forward request and error logs to docker log collector
ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
# Copy the base uWSGI ini file to enable default dynamic uwsgi process number
mkdir -p /etc/uwsgi
cp /docker/uwsgi.ini /etc/uwsgi/uwsgi.ini
# Custom Supervisord config
cp /docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
sed -i 's#/usr/bin/pidproxy /var/lib/rabbitmq/mnesia/rabbitmq.pid /bin/bash -c "/rabbitmq.sh"#rabbitmq-server#g' /etc/supervisor/conf.d/supervisord.conf
sed -i '/user=user/d' /etc/supervisor/conf.d/supervisord.conf
sed -i '/group=user/d' /etc/supervisor/conf.d/supervisord.conf
# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app
cp /docker/start.sh /start.sh
chmod +x /start.sh
# Clean up
rm -r /docker
%runscript
# Initialize files to bind
rm -r $HOME/.elephant_binds 2> /dev/null
mkdir -p $HOME/.elephant_binds/var/run
cp -a /var/log $HOME/.elephant_binds/var/
cp -a /var/lib $HOME/.elephant_binds/var/
%labels
Author Ko Sugawara <ko.sugawara@ens-lyon.fr>
%help
This is a container to run ELEPHANt server.
Usage:
singularity build --fakeroot elephant.sif elephant.def
singularity run --fakeroot elephant.sif
singularity instance start --nv --bind $HOME/.elephant_binds/var/lib:/var/lib,$HOME/.elephant_binds/var/log:/var/log,$HOME/.elephant_binds/var/run:/var/run,$ELEPHANT_WORKSPACE:/workspace elephant.sif elephant
singularity exec instance://elephant python /opt/elephant/script/dataset_generator.py --uint16 /workspace/datasets/elephant-demo/elephant-demo.h5 /workspace/datasets/elephant-demo
SINGULARITYENV_CUDA_VISIBLE_DEVICES=0 singularity exec instance://elephant /start.sh
singularity instance stop elephant