Commit b53eec6c authored by M. Huang's avatar M. Huang
Browse files

fdi docker w/o server v1.6

parent 9e2e2021
......@@ -232,16 +232,6 @@ docs_html:
cd $(SDIR) && make html
########
DOCKER_NAME = fdi_no_pool
FDI_NP =mh/fdi_no_pool:v1
SERVER_NAME =httppool_server
PORT =9884
EXTPORT =$(PORT)
IMAGE_NAME =mh/httppool_server:v3
IP_ADDR =10.0.10.114
DOCKERFILE =fdi/pns/resources/httppool_server.docker
SECFILE = $${HOME}/.secret
secret:
@echo These have been appended to $(SECFILE). Edit it. Be careful not to have whitespace. and use as
......@@ -258,40 +248,53 @@ secret:
@echo export MQ_PASS= >> $(SECFILE)
@cat $(SECFILE)
DOCKER_NAME = fdi
VERS = v1
#DOCKER_NAME =httppool_server
#VERS = v3
PORT =9884
EXTPORT =$(PORT)
IMAGE_NAME =mh/$(DOCKER_NAME):$(VERS)
IP_ADDR =10.0.10.114
POOL_DOCKERFILE =fdi/pns/resources/httppool_server.docker
PROXIP = localhost
PROXY = --build-arg http_proxy=socks5://$(PROXIP):7777 --build-arg https_proxy=socks5://$(PROXIP):7777
PROXY =
build_docker:
DOCKER_BUILDKIT=1 docker build -t $(FDI_NP) --secret id=envs,src=$${HOME}/.secret --build-arg fd=$(fd) --build-arg re=$(re) -f $(DOCKERFILE) $(D) .
DOCKER_BUILDKIT=1 docker build -t $(DOCKER_NAME) --secret id=envs,src=$${HOME}/.secret --build-arg fd=$(fd) --build-arg re=$(re) $(PROXY) $(D) .
launch_docker:
docker run -it --network=bridge --env-file $(SECFILE) --name $(DOCKER_NAME) $(D) $(FDI_NP) $(B)
docker run -it --network=bridge --env-file $(SECFILE) --name $(DOCKER_NAME) $(D) $(DOCKER_NAME) $(B)
build_server:
DOCKER_BUILDKIT=1 docker build -t $(IMAGE_NAME) --secret id=envs,src=$${HOME}/.secret --build-arg fd=$(fd) --build-arg re=$(re) -f $(DOCKERFILE) $(D) .
DOCKER_BUILDKIT=1 docker build -t $(IMAGE_NAME) --secret id=envs,src=$${HOME}/.secret --build-arg fd=$(fd) --build-arg re=$(re) -f $(POOL_DOCKERFILE) $(D) .
launch_server:
docker run -d -it --network=bridge --env-file $(SECFILE) --name $(SERVER_NAME) $(D) $(IMAGE_NAME) -p $(PORT):$(EXTPORT) $(B)
docker run -d -it --network=bridge --env-file $(SECFILE) --name $(DOCKER_NAME) $(D) $(IMAGE_NAME) -p $(PORT):$(EXTPORT) $(B)
sleep 2
docker ps -n 1
rm_server:
docker stop $(SERVER_NAME) || echo not running
docker rm $(SERVER_NAME)
docker stop $(DOCKER_NAME) || echo not running
docker rm $(DOCKER_NAME)
rm_serveri:
docker stop $(SERVER_NAME) || echo not running
docker rm $(SERVER_NAME) || echo go on ...
docker stop $(DOCKER_NAME) || echo not running
docker rm $(DOCKER_NAME) || echo go on ...
docker image rm $(IMAGE_NAME)
B =/bin/bash
it:
docker exec -it $(D) $(SERVER_NAME) $(B)
docker exec -it $(D) $(DOCKER_NAME) $(B)
its:
docker exec -it $(D) $(SERVER_NAME) /bin/bash
docker exec -it $(D) $(DOCKER_NAME) /bin/bash
t:
docker exec -it $(D) $(SERVER_NAME) /usr/bin/tail -n 100 -f /home/apache/error-ps.log
docker exec -it $(D) $(DOCKER_NAME) /usr/bin/tail -n 100 -f /home/apache/error-ps.log
i:
docker exec -it $(D) $(SERVER_NAME) /usr/bin/less -f /home/apache/error-ps.log
docker exec -it $(D) $(DOCKER_NAME) /usr/bin/less -f /home/apache/error-ps.log
# syntax=docker/dockerfile:1.2
FROM ubuntu:18.04 AS fdi
LABEL fd1 1.6
# 0.2-4 M. Huang <mhuang@nao.cas.cn>
# 0.1 yuxin<syx1026@qq.com>
#ARG DEBIAN_FRONTEND=noninteractive
#ENV TZ=Etc/UTC
RUN apt-get update \
&& apt-get install -y apt-utils sudo \
&& apt-get install -y nano \
&& apt-get install -y git python3-pip
# rebuild mark
ARG re=rebuild
# setup env
# setup user
ARG USR=fdi
ARG UHOME=/home/${USR}
RUN groupadd ${USR} && useradd -g ${USR} ${USR} -m --home=${UHOME} -G sudo \
&& mkdir -p ${UHOME}/.config \
&& /bin/echo -e '\n'${USR} ALL = NOPASSWD: ALL >> /etc/sudoers
WORKDIR ${UHOME}
ENV PATH="${UHOME}/.local/bin:$PATH"
# setup config files
COPY fdi/pns/config.py .config/pnslocal.py
# config software
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.6 0 \
&& python3 -m pip install pip -U
# convinience aliases
COPY fdi/pns/resources/profile .
RUN cat profile >> .bashrc && rm profile
# Configure permission
RUN for i in /var/run/lock/ ${UHOME}/; \
do chown -R ${USR}:${USR} $i; echo $i; done
# If install fdi repo, instead of package
# make dir for fdi.
ENV PKGS_DIR=${UHOME}
RUN mkdir -p ${PKGS_DIR} && chown ${USR}:${USR} ${PKGS_DIR}
# Run as user
USER ${USR}
# install and test fdi
ARG fd=rebuild
WORKDIR ${PKGS_DIR}
ARG PKG=fdi
# from local repo
COPY --chown=${USR}:${USR} ./ /tmp/fdi_repo/
RUN git clone --depth 20 -b develop file:///tmp/fdi_repo ${PKG}
WORKDIR ${PKGS_DIR}/${PKG}/
RUN make install EXT="[DEV,SERV]" I="--user"
# If installing fdi package
# no [DEV] needed
#RUN python3 -m pip install http://mercury.bao.ac.cn:9006/mh/fdi/-/archive/develop/fdi-develop.tar.gz#egg=fdi[DEV,SERV]
#RUN python3 -m pip install fdi[DEV,SERV]
WORKDIR ${UHOME}
# entrypoint.sh is used for replacing IP/ports and configurations.
USER root
RUN chmod 755 ./entrypoint.sh
USER ${USR}
# get passwords etc from ~/.secret
RUN --mount=type=secret,id=envs sudo cp /run/secrets/envs . \
&& sudo chown ${USR} envs \
&& for i in `cat ./envs`; do export $i; done \
&& ./httppool_server_entrypoint.sh
WORKDIR ${PKGS_DIR}/${PKG}/
RUN make test \
&& rm -rf /tmp/fdi_repo
WORKDIR ${UHOME}
RUN /bin/ls -la; \
date > build
#!/bin/bash
id | tee ~/lastent
echo ######
IP=`ifconfig -a | grep "inet" | grep -v 127.0.0.1 | grep -v "inet6" | awk '{print $2}'`
sed -i "s/^EXTHOST =.*$/EXTHOST = \'$IP\'/g" ~/.config/pnslocal.py
sed -i "s/^EXTPORT =.*$/EXTPORT = $HOST_PORT/g" ~/.config/pnslocal.py
sed -i "s/^EXTUSER =.*$/EXTUSER = \'$HOST_USER\'/g" ~/.config/pnslocal.py
sed -i "s/^EXTPASS =.*$/EXTPASS = \'$HOST_PASS\'/g" ~/.config/pnslocal.py
sed -i "s/^MQHOST =.*$/MQHOST = \'$MQ_HOST\'/g" ~/.config/pnslocal.py
sed -i "s/^MQPORT =.*$/MQPORT = $MQ_PORT/g" ~/.config/pnslocal.py
sed -i "s/^MQUSER =.*$/MQUSER = \'$MQ_USER\'/g" ~/.config/pnslocal.py
sed -i "s/^MQPASS =.*$/MQPASS = \'$MQ_PASS\'/g" ~/.config/pnslocal.py
sed -i "s/^conf\s*=\s*.*$/conf = 'external'/g" ~/.config/pnslocal.py
echo ===== .config/pnslocal.py >> ~/lastent
grep ^conf ~/.config/pnslocal.py >> ~/lastent
grep ^EXTHOST ~/.config/pnslocal.py >> ~/lastent
grep ^EXTPORT ~/.config/pnslocal.py >> ~/lastent
#service apache2 reload && echo apache2 reloaded
date >> ~/lastent
cat ~/lastent
echo @@@ $@
for i in $@; do
if [ $i = no-run ]; then exit 0; fi;
done
echo enabling site ... >> ~/lastent
sudo a2ensite httppool_server.conf
sudo a2dissite 000-default.conf
#service apache2 reload && echo apache2 reloaded
echo running apachectl >> ~/lastent ;
exec /usr/sbin/apache2ctl -DFOREGROUND 2>&1 >> ~/lastent ;
fi
......@@ -128,15 +128,15 @@ def leapseconds(tzfiles=['/usr/share/zoneinfo/right/UTC',
"""
file.read(timecnt * 5 + typecnt * 6 + charcnt) # skip
result = [LeapSecond(datetime(1972, 1, 1), timedelta(seconds=10))]
result = [LeapSecond(datetime(1972, 1, 1, tzinfo=timezone.utc), timedelta(seconds=10))]
nleap_seconds = 10
tai_epoch_as_tai = datetime(1970, 1, 1, 0, 0, 10)
tai_epoch_as_tai = datetime(1970, 1, 1, 0, 0, 10, tzinfo=timezone.utc)
buf = Struct(">2i")
for _ in range(leapcnt): # read leap seconds
t, cnt = buf.unpack_from(file.read(buf.size))
dTAI_UTC = nleap_seconds + cnt
utc = tai_epoch_as_tai + timedelta(seconds=t - dTAI_UTC + 1)
assert utc - datetime(utc.year, utc.month, utc.day) == timedelta(0)
assert utc - datetime(utc.year, utc.month, utc.day, tzinfo=timezone.utc) == timedelta(0)
result.append(LeapSecond(utc, timedelta(seconds=dTAI_UTC)))
result.append(sentinel)
return result
......
......@@ -45,7 +45,6 @@ def opt(ops, argv=None):
# print help information and exit:
# will print something like "option -a not recognized"
logger.error(str(err) + 'Received: ' + str(argv))
print(msg)
sys.exit(2)
logger.debug('Command line options %s args %s' % (opts, args))
......
......@@ -36,7 +36,7 @@ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.6 0 \
# convinience aliases
COPY fdi/pns/resources/profile .
RUN cat profile >> .bashrc && rm profile \
RUN cat profile >> .bashrc && rm profile
# Configure permission
RUN for i in /var/run/lock/ ${PROJ_DIR} ${UHOME}/; \
......
......@@ -48,7 +48,6 @@ setup(
'pytest>=5.4.1',
'pytest-cov',
'aiohttp>=3.6.2',
'nox>=2019.11.9',
],
'SERV': [
'Flask_HTTPAuth>=3.3.0',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment