...
 
Commits (2)
......@@ -6,9 +6,9 @@ For example, to run up the CSPEC demo:
git checkout cspec-demo
```
Or for YMIR:
Or for Loki:
```
git checkout ymir
git checkout loki-demo
```
You get the idea ;) `git branch` is your friend.
......
version: '2.4'
services:
zookeeper:
image: zookeeper:3.4
networks:
- backend
kafka:
image: wurstmeister/kafka:1.0.0
depends_on:
- zookeeper
hostname: kafka
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_MESSAGE_MAX_BYTES: 20000000
KAFKA_BROKER_ID: 0
KAFKA_CREATE_TOPICS: "TEST_writerCommand:1:1,TEST_writerStatus:1:1,hist_commands:1:1,fake_events:1:1,just-bin-it:1:1,jbi_heartbeat:1:1,TEST_forwarderConfig:1:1,TEST_forwarderStatus:1:1,TEST_nicosCacheCompacted:1:1,TEST_nicosCacheHistory:1:1"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- backend
- frontend
file-writer:
image: screamingudder/file-writer:3e667e1
depends_on:
- kafka
environment:
KAFKA_BROKER: kafka
CONFIG_FILE: "/config-files/file_writer_config.ini"
volumes:
- ./config-files/:/config-files/
- ./output-files/:/output-files/
- ./logs/:/fw_logs/
networks:
- backend
forwarder:
image: screamingudder/forwarder:0ba4430
depends_on:
- kafka
environment:
KAFKA_BROKER: kafka
CONFIG_FILE: "/config-files/forwarder_config.ini"
volumes:
- ./config-files/:/config-files/
- ./logs/:/fw_logs/
networks:
- backend
just-bin-it:
image: screamingudder/just-bin-it:latest
depends_on:
- kafka
environment:
PARAMETERS: "-b kafka:9092 -t hist_commands -s -hb jbi_heartbeat -l 3"
networks:
- backend
- frontend
nicos-cache:
image: screamingudder/nicos:cspec-demo-cache
depends_on:
- file-writer
- kafka
ports:
- "14869:14869"
volumes:
......@@ -41,7 +104,7 @@ services:
stdin_open: true
nicos-client:
image: screamingudder/nicos:cspec-demo
image: screamingudder/nicos:cspec-demo-daemon
depends_on:
- nicos-daemon
volumes:
......
FROM ubuntu:bionic
RUN apt-get update && \
apt install -yq vim build-essential git tmux iputils-ping wget curl lsof
RUN adduser --disabled-password --gecos "" nicos
RUN mkdir /opt/nicos-data && \
chown nicos /opt/nicos-data && \
chgrp nicos /opt/nicos-data
RUN git clone https://github.com/ess-dmsc/nicos.git /home/nicos/nicos-core && \
chown -R nicos /home/nicos/nicos-core && \
chgrp -R nicos /home/nicos/nicos-core
USER nicos
WORKDIR /home/nicos
RUN wget -O miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
sh miniconda.sh -b -p /home/nicos/miniconda && \
chown nicos /home/nicos/miniconda && \
/home/nicos/miniconda/bin/conda create -n env python=3.7 && \
echo "/home/nicos/miniconda/bin/conda activate env" >> ~/.bashrc
ENV PATH /home/nicos/miniconda/envs/env/bin:$PATH
# Expose the necessary ports
EXPOSE 1301 14869
EXPOSE 80 443 3128
FROM screamingudder/nicos:base
ARG GIT_BRANCH=cspec-demo
USER nicos
WORKDIR /home/nicos
# Switch to the requested branch
RUN cd /home/nicos/nicos-core && \
git fetch && \
git checkout $GIT_BRANCH && git pull
RUN cd /home/nicos/nicos-core && \
pip install -r requirements.txt && \
cd nicos_ess && \
pip install -r requirements.txt
CMD cd /home/nicos/nicos-core && \
./bin/nicos-cache
FROM screamingudder/nicos:base
ARG GIT_BRANCH=cspec-demo
USER nicos
WORKDIR /home/nicos
# Switch to the requested branch
RUN cd /home/nicos/nicos-core && \
git fetch && \
git checkout $GIT_BRANCH && git pull
RUN cd /home/nicos/nicos-core && \
pip install -r requirements.txt && \
cd nicos_ess && \
pip install -r requirements.txt
COPY scripts/wait_for_cache_ready.py .
CMD python wait_for_cache_ready.py && \
cd /home/nicos/nicos-core && \
./bin/nicos-daemon
FROM screamingudder/nicos:base
ARG GIT_BRANCH=cspec-demo
USER nicos
WORKDIR /home/nicos
# Switch to the requested branch
RUN cd /home/nicos/nicos-core && \
git fetch && \
git checkout $GIT_BRANCH && git pull
RUN cd /home/nicos/nicos-core && \
pip install -r requirements.txt && \
cd nicos_ess && \
pip install -r requirements.txt
CMD cd /home/nicos/nicos-core && \
./bin/nicos-poller
# NICOS Docker
## Creating the base image
This is the image upon the actual NICOS services will be built. It can be used for any instrument.
It is not always necessary to build the base as there is one on DockerHub. It only needs to be built if the Dockerfile changes.
Build it:
```
docker build --no-cache -t nicos-base -f Dockerfile .
```
Tag it:
```
docker tag nicos-base screamingudder/nicos:base
```
Push it:
```
docker push screamingudder/nicos:base
```
Alternatively, there is a script:
```
sh upload_base_image.sh
```
## Creating a NICOS image
This example creates the CSPEC demo based on the corresponding branch in Git.
To build from a different branch change the GIT_BRANCH argument and image names appropriately.
The GIT_BRANCH to be built with can be chosen from those available at
https://github.com/ess-dmsc/nicos.git
### The cache
Build it:
```
docker build --build-arg "GIT_BRANCH=cspec-demo" -t nicos-cspec-demo-cache -f Dockerfile.cache .
```
Tag it:
```
docker tag nicos-cspec-demo-cache screamingudder/nicos:cspec-demo-cache
```
Push:
```
docker push screamingudder/nicos:cspec-demo-cache
```
## The poller
Build it:
```
docker build --build-arg "GIT_BRANCH=cspec-demo" -t nicos-cspec-demo-poller -f Dockerfile.poller .
```
Tag it:
```
docker tag nicos-cspec-demo-cache screamingudder/nicos:cspec-demo-poller
```
Push:
```
docker push screamingudder/nicos:cspec-demo-poller
## The daemon
Build it:
```
docker build --build-arg "GIT_BRANCH=cspec-demo" -t nicos-cspec-demo-poller -f Dockerfile.daemon .
```
Tag it:
```
docker tag nicos-cspec-demo-cache screamingudder/nicos:cspec-demo-daemon
```
Push:
```
docker push screamingudder/nicos:cspec-demo-daemon
## The script
Alternatively, there is a script:
```
sh upload_nicos_images.sh cspec-demo cspec-demo
```
Where the first parameter is the git branch name and the second is the docker tag.
## Pulling and running
Pulling:
```
docker pull screamingudder/nicos:cspec-demo
```
Running on Linux (production)
```
docker run --network host -it screamingudder/nicos:cspec-demo
```
Network is in host mode to enable access to the PVs etc. This only works on Linux.
Running on OSX (testing)
```
docker run -p 1301:1301 -it screamingudder/nicos:cspec-demo
```
Restarting the container will automatically get the latest changes from the NICOS GitHub for the associated branch, so this is an easy way to update setup files etc.
## Connecting the NICOS GUI
A local version of the NICOS GUI will be able to connect to the running Docker image via localhost.
## Connecting to the running container
Get the running container name:
```
docker ps
```
Connect:
```
docker exec -it amazing_kowalevski bash
```
This can be used to change the to the NICOS setup files etc. for testing without having to rebuild the Docker image. Note: the changes are lost when the container is restarted.
from kafka import KafkaConsumer
import time
CACHE_TOPIC = "TEST_nicosCacheCompacted"
HIST_TOPIC = "TEST_nicosCacheHistory"
while True:
try:
consumer = KafkaConsumer(bootstrap_servers=["kafka:9092"])
topics = consumer.topics()
if CACHE_TOPIC in topics and HIST_TOPIC in topics:
break
except:
pass
time.sleep(1)
# Give the cache some time to get going
time.sleep(10)
#!/bin/sh
docker build --no-cache -t nicos-base -f Dockerfile .
docker tag nicos-base screamingudder/nicos:base
docker push screamingudder/nicos:base
#!/bin/sh
BRANCH=$1
LABEL=$2
docker build --no-cache --build-arg "GIT_BRANCH=$BRANCH" -t nicos-$LABEL-cache -f Dockerfile.cache .
docker tag nicos-$LABEL-cache screamingudder/nicos:$LABEL-cache
docker push screamingudder/nicos:$LABEL-cache
docker build --no-cache --build-arg "GIT_BRANCH=$BRANCH" -t nicos-$LABEL-poller -f Dockerfile.poller .
docker tag nicos-$LABEL-poller screamingudder/nicos:$LABEL-poller
docker push screamingudder/nicos:$LABEL-poller
docker build --no-cache --build-arg "GIT_BRANCH=$BRANCH" -t nicos-$LABEL-daemon -f Dockerfile.daemon .
docker tag nicos-$LABEL-daemon screamingudder/nicos:$LABEL-daemon
docker push screamingudder/nicos:$LABEL-daemon
\ No newline at end of file