summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Shetye2024-03-20 14:35:54 +0530
committerSunil Shetye2024-03-20 14:39:29 +0530
commita8ceadd4660cb9ba477ed4b6f5a8399befd9b6ee (patch)
tree4d654b724c6e3667ea5371ca54fcc672eb193cc2
parent90aba8f2d5a3b69b2558b37fbf77234db64c963a (diff)
downloadCommon-Interface-Project-a8ceadd4660cb9ba477ed4b6f5a8399befd9b6ee.tar.gz
Common-Interface-Project-a8ceadd4660cb9ba477ed4b6f5a8399befd9b6ee.tar.bz2
Common-Interface-Project-a8ceadd4660cb9ba477ed4b6f5a8399befd9b6ee.zip
add files for docker
-rw-r--r--blocks/.dockerignore26
-rw-r--r--blocks/Dockerfile175
-rw-r--r--blocks/Makefile2
-rw-r--r--blocks/eda-frontend/.dockerignore1
-rwxr-xr-xblocks/install.sh48
-rwxr-xr-xblocks/run.sh13
6 files changed, 263 insertions, 2 deletions
diff --git a/blocks/.dockerignore b/blocks/.dockerignore
new file mode 100644
index 00000000..39bccca2
--- /dev/null
+++ b/blocks/.dockerignore
@@ -0,0 +1,26 @@
+**/.dockerignore
+**/Dockerfile*
+.git*
+.travis.yml
+env*
+*.md
+*.pdf
+*.pyc
+*.sqlite3
+*.swp
+**/migrations
+.DS_Store
+**/.env.*
+**/build
+**/node_modules
+tags
+.srcflake8
+.xcosblocks.txt
+scilab-log-*.txt
+U*.sci
+*.xml
+xcosblocks.py
+Xcos/xcosblocks.py
+blocks/xcosblocks/xcosblocks.py
+**/__pycache__
+**/__snapshots__
diff --git a/blocks/Dockerfile b/blocks/Dockerfile
new file mode 100644
index 00000000..6fec272f
--- /dev/null
+++ b/blocks/Dockerfile
@@ -0,0 +1,175 @@
+FROM ubuntu:22.04 AS base
+
+ENV DEBIAN_FRONTEND=noninteractive
+ENV UBUNTU_FRONTEND=noninteractive
+
+ENV HOME=/root
+
+ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
+ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
+
+ARG NODE_VERSION=v18.19.1
+ARG NODE=node-${NODE_VERSION}-linux-x64
+ARG NODE_DIR=${HOME}/${NODE}
+ENV PATH=${NODE_DIR}/bin:${PATH}
+
+SHELL ["/bin/bash", "-o", "pipefail", "-c"]
+
+# Install pre-requisites
+RUN apt-get update -qq && \
+ apt-get install -qq --no-install-recommends gcc g++ libgfortran5 make nginx openjdk-8-jre python3 sqlite3 tzdata && \
+ apt-get clean -qq && \
+ rm -f /var/lib/apt/lists/*_*
+
+# Set timezone info
+RUN ln -sf /usr/share/zoneinfo/Asia/Kolkata /etc/localtime && \
+ dpkg-reconfigure -f noninteractive tzdata
+
+
+FROM base AS build-scilab
+
+# Add sources and Install pre-requisites
+RUN sed -i 's/^# *\(deb-src .*\.ubuntu\.com\)/\1/' /etc/apt/sources.list
+# packages to be removed later
+RUN apt-get update -qq && \
+ apt-get install -qq --no-install-recommends devscripts equivs git openjdk-8-jdk && \
+ mk-build-deps scilab && \
+ apt-get install -qq --no-install-recommends ./scilab-build-deps_*.deb && \
+ rm -f ./scilab-build-deps_*
+
+# Build scilab
+ARG BRANCH=master-2023.1
+ARG SCILAB_DIR=${HOME}/scilab_for_xcos_on_cloud
+WORKDIR ${HOME}
+ADD https://api.github.com/repos/FOSSEE/scilab_for_xcos_on_cloud/git/ref/heads/${BRANCH} scilab_for_xcos_on_cloud.json
+RUN git clone -q -b ${BRANCH} --depth 1 https://github.com/FOSSEE/scilab_for_xcos_on_cloud
+WORKDIR ${SCILAB_DIR}
+RUN ./configure --disable-dependency-tracking --disable-build-help --disable-static-system-lib --without-tk
+RUN make -j4 -s V=0 || make
+RUN make -s V=0 install-strip
+
+# Cleanup
+RUN apt-get autoremove -qq --purge devscripts equivs git openjdk-8-jdk openjdk-11-jre-headless scilab-build-deps '^(bsd(main|extra)utils|file|libglib2.0-data|xz-utils)$'
+
+# Fix path in xml file
+RUN sed -i "s,/usr/share/java/,${SCILAB_DIR}/thirdparty/," /usr/local/share/scilab/etc/classpath.xml
+
+# Copy missing libs
+WORKDIR ${SCILAB_DIR}
+
+ARG LIBDIR=/usr/lib/x86_64-linux-gnu
+ARG ALTLIBDIR=${HOME}/_usr_lib_x86_64-linux-gnu
+RUN mkdir -p ${ALTLIBDIR}
+RUN find lib/thirdparty/ usr/lib/ -name \*.so -o -name \*.so.\* | \
+ sort | \
+ while read -r f; do \
+ g="${f##*/}"; \
+ test -e ${LIBDIR}/"$g" || { cp -a "$f" ${LIBDIR}/"$g"; cp -a "$f" ${ALTLIBDIR}/"$g"; }; \
+ done
+
+ARG SCILABLIBDIR=/usr/local/lib/scilab
+ARG MODULELIBDIR=/usr/local/share/scilab
+RUN find modules -name .libs | \
+ sort | \
+ while read -r f; do \
+ g="${f%/.libs}"; \
+ test ! -e ${MODULELIBDIR}/"$g" || ln -snf ${SCILABLIBDIR} ${MODULELIBDIR}/"$g"/.libs; \
+ done
+
+ARG JNILIBDIR=/usr/lib/jni
+RUN mkdir -p ${JNILIBDIR}
+RUN for lib in gluegen2-rt jogl_desktop jogl_mobile nativewindow_awt nativewindow_x11 newt; do \
+ g=lib"$lib".so; \
+ f=lib/thirdparty/"$g"; \
+ cp -a -f "$f" ${JNILIBDIR}/"$g"; \
+ done
+
+RUN rm -rf .git* modules thirdparty/docbook
+RUN find ! -type d ! -name \*.jar -print0 | xargs -0 rm -f
+RUN find . -mindepth 1 -type d -empty -print0 | xargs -0 rmdir -p 2> /dev/null || :
+
+# Cleanup
+RUN find /usr/local/share/scilab -depth -type d \( -name demos -o -name examples -o -name tests \) -print0 | \
+ xargs -0 rm -rf
+RUN ls /usr/local/share/locale | grep _ | grep -v en_US | \
+ while read -r d; do \
+ find . -type d -name "$d" -print0 | xargs -r0 rm -rf; \
+ done
+RUN apt-get clean -qq
+RUN rm -f /var/lib/apt/lists/*_*
+RUN rm -f /etc/{passwd,shadow,group,gshadow}-
+
+# Comparison
+#RUN dpkg-query -Wf '${Installed-Size}\t${Package}\t${Version}\n' > /tmp/dpkg-scilab
+#RUN find / -mount \( -path /tmp -o -path ${ALTLIBDIR} \) -prune -o ! -type d -print | sort > /tmp/filelist-scilab
+
+
+FROM base AS build-xcos
+
+# packages to be removed later
+RUN apt-get update -qq && \
+ apt-get install -qq --no-install-recommends gawk python3-pip python3-venv wget xz-utils
+
+WORKDIR ${HOME}
+RUN wget -q --no-hsts https://nodejs.org/download/release/${NODE_VERSION}/${NODE}.tar.xz
+RUN tar xf ${NODE}.tar.xz
+RUN rm -f ${NODE}.tar.xz
+
+# Build XCos
+ARG XCOS_DIR=${HOME}/xcosblocks
+WORKDIR ${XCOS_DIR}
+COPY . .
+
+# Configure venv and sqlite3
+RUN ./install.sh
+
+# Cleanup
+RUN apt-get autoremove -qq --purge gawk python3-pip python3-venv wget xz-utils
+RUN apt-get clean -qq
+RUN rm -f /var/lib/apt/lists/*_*
+RUN rm -rf ${HOME}/.cache
+RUN rm -rf ${HOME}/.npm
+
+# Comparison
+#RUN dpkg-query -Wf '${Installed-Size}\t${Package}\t${Version}\n' > /tmp/dpkg-xcos
+#RUN find / -mount \( -path /tmp \) -prune -o ! -type d -print | sort > /tmp/filelist-xcos
+
+
+FROM base AS main
+
+EXPOSE 80
+
+# Install scilab
+COPY --from=build-scilab /usr/local /usr/local
+ARG LIBDIR=/usr/lib/x86_64-linux-gnu
+ARG ALTLIBDIR=${HOME}/_usr_lib_x86_64-linux-gnu
+COPY --from=build-scilab ${ALTLIBDIR} ${LIBDIR}
+ARG JNILIBDIR=/usr/lib/jni
+COPY --from=build-scilab ${JNILIBDIR} ${JNILIBDIR}
+ARG SCILAB_DIR=${HOME}/scilab_for_xcos_on_cloud
+COPY --from=build-scilab ${SCILAB_DIR} ${SCILAB_DIR}
+COPY --from=build-scilab ${SCILAB_DIR}.json ${SCILAB_DIR}.json
+
+# Install Node
+COPY --from=build-xcos ${NODE_DIR} ${NODE_DIR}
+
+# Install XCos
+ARG XCOS_DIR=${HOME}/xcosblocks
+COPY --from=build-xcos ${XCOS_DIR} ${XCOS_DIR}
+
+# Install nginx
+COPY --from=build-xcos /etc/nginx/sites-enabled/default /etc/nginx/sites-enabled/default
+
+# Comparison
+#COPY --from=build-scilab /tmp/dpkg-scilab /tmp/dpkg-scilab
+#COPY --from=build-xcos /tmp/dpkg-xcos /tmp/dpkg-xcos
+#RUN dpkg-query -Wf '${Installed-Size}\t${Package}\t${Version}\n' | sort > /tmp/dpkg-main
+#RUN sort -u /tmp/dpkg-scilab /tmp/dpkg-xcos | diff /tmp/dpkg-main -
+#COPY --from=build-scilab /tmp/filelist-scilab /tmp/filelist-scilab
+#COPY --from=build-xcos /tmp/filelist-xcos /tmp/filelist-xcos
+#RUN find / -mount \( -path /tmp \) -prune -o ! -type d -print | sort > /tmp/filelist-main
+#RUN sort -u /tmp/filelist-scilab /tmp/filelist-xcos | diff /tmp/filelist-main -
+
+WORKDIR ${XCOS_DIR}
+
+CMD ["./run.sh"]
diff --git a/blocks/Makefile b/blocks/Makefile
index bb01ec10..d93572a0 100644
--- a/blocks/Makefile
+++ b/blocks/Makefile
@@ -1,6 +1,6 @@
SHELL := /bin/bash
-BLOCKDIR := ../blocks/blocks/xcosblocks
+BLOCKDIR := blocks/xcosblocks
SRCFILES := $(sort $(wildcard Xcos/common/*.py))
SRCFILES += $(sort $(wildcard Xcos/blocks/*.py))
diff --git a/blocks/eda-frontend/.dockerignore b/blocks/eda-frontend/.dockerignore
deleted file mode 100644
index c2658d7d..00000000
--- a/blocks/eda-frontend/.dockerignore
+++ /dev/null
@@ -1 +0,0 @@
-node_modules/
diff --git a/blocks/install.sh b/blocks/install.sh
new file mode 100755
index 00000000..655aad43
--- /dev/null
+++ b/blocks/install.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+set -e
+
+cd eda-frontend
+npm install --silent
+echo 'WDS_SOCKET_PORT=8000' > .env.local
+
+cd ..
+python3 -m venv env
+. env/bin/activate
+pip install -q -U pip setuptools wheel
+pip install -q -r requirements.txt
+pip uninstall -q -y pip wheel
+
+make -s
+python manage.py makemigrations -v0 simulationAPI xcosblocks
+python manage.py migrate -v0
+python manage.py loaddata -v0 xcosblocks
+
+sed -i \
+ -e "s/\\(SCILAB_DIR = \\).*/\\1'\/usr\/local'/" \
+ blocks/settings.py
+
+sed -i -e '/^\s*location \/ {/,/^\s*}/c\
+ location / {\
+ proxy_pass http://127.0.0.1:3500;\
+ }\
+\
+ location /api/ {\
+ proxy_pass http://127.0.0.1:8000;\
+ proxy_buffering off;\
+ proxy_cache off;\
+ }\
+\
+ location /django_static/ {\
+ proxy_pass http://127.0.0.1:8000;\
+ }\
+\
+ location /ws {\
+ proxy_pass http://127.0.0.1:3500;\
+ proxy_http_version 1.1;\
+ proxy_set_header Upgrade $http_upgrade;\
+ proxy_set_header Connection "Upgrade";\
+ proxy_set_header Host $host;\
+ proxy_buffering off;\
+ proxy_cache off;\
+ }' /etc/nginx/sites-enabled/default
diff --git a/blocks/run.sh b/blocks/run.sh
new file mode 100755
index 00000000..6c10f18e
--- /dev/null
+++ b/blocks/run.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+set -e
+
+service nginx start
+
+. env/bin/activate
+
+cd eda-frontend
+npm start &
+
+cd ..
+python manage.py runserver