-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathelephant.def
108 lines (92 loc) · 3.9 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
96
97
98
99
100
101
102
103
104
105
106
107
108
Bootstrap: docker
From: pytorch/pytorch:2.3.1-cuda12.1-cudnn8-runtime
%files
./docker /docker
./script /opt/elephant/script
./app /app
./elephant-core /src/elephant-core
./requirements.txt /src/requirements.txt
%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
export PATH=/opt/conda/bin:$PATH
export RABBITMQ_USER=user
export RABBITMQ_PASSWORD=user
export RABBITMQ_MANAGEMENT_PORT=15672
export RABBITMQ_PID_FILE=/var/lib/rabbitmq/mnesia/rabbitmq.pid
export ElEPHANT_HTTP_PORT=8080
%post -c /bin/bash
# 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 \
gosu \
gettext-base && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# install pypi packages
python -m pip install -r /src/requirements.txt && rm /src/requirements.txt
python -m pip install /src/elephant-core && rm -r /src/elephant-core
# Install and set up RabbbitMQ
# Install Python modules
sed -i 's/sudo //g' /docker/install-rabbitmq.sh
chmod +x /docker/install-rabbitmq.sh && /docker/install-rabbitmq.sh
echo "rabbitmq-server \$@" > /rabbitmq.sh
chmod +x /rabbitmq.sh
cp /docker/rabbitmq-env.conf /etc/rabbitmq/rabbitmq-env.conf
export RABBITMQ_USER=user
export RABBITMQ_PASSWORD=user
export RABBITMQ_MANAGEMENT_PORT=15672
cp /docker/setup-rabbitmq.sh /setup-rabbitmq.sh
chmod +x /setup-rabbitmq.sh
/setup-rabbitmq.sh
# Set up nginx
cp /docker/nginx.conf.template /etc/nginx/nginx.conf.template
groupadd -r nginx && useradd -r -g nginx nginx
# 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
sed -i '/chown-socket = nginx:nginx/d' /etc/uwsgi/uwsgi.ini
# Custom Supervisord config
cp /docker/supervisord.conf /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/
mkdir -p $HOME/.elephant_binds/etc
cp -a /etc/nginx $HOME/.elephant_binds/etc/
cp -a /etc/rabbitmq $HOME/.elephant_binds/etc/
chown -R $(id -u):$(id -g) $HOME/.elephant_binds
%labels
Author Ko Sugawara <[email protected]>
%help
This is a container to run ELEPHANt server.
Usage:
apptainer build --fakeroot elephant.sif elephant.def
apptainer run --fakeroot --bind $HOME:/root elephant.sif
apptainer instance start --nv --bind $HOME,$HOME/.elephant_binds/var/lib:/var/lib,$HOME/.elephant_binds/var/log:/var/log,$HOME/.elephant_binds/var/run:/var/run,$HOME/.elephant_binds/etc/nginx:/etc/nginx,$HOME/.elephant_binds/etc/rabbitmq:/etc/rabbitmq,$ELEPHANT_WORKSPACE:/workspace elephant.sif elephant
apptainer 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 apptainer exec instance://elephant /start.sh
apptainer instance stop elephant