dachs-dockerfile 4.57 KB
ARG VERSION
FROM debian:$VERSION

ARG GITURL=https://voparis-gitlab.obspm.fr

ARG GITREPO_SERVER
ARG GITREPO_INSTITUTION
ARG HOMEPATH=/home/dachsroot
ARG DACHS_PORT
ARG APACHE_PORT
ARG SERVERNAME
ARG DOMAIN
ARG PROTOCOL



RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get install -y curl apt-utils

# add dachs source
RUN curl -o /etc/apt/trusted.gpg.d/gavo-archive.key.asc https://docs.g-vo.org/archive-key.asc
RUN echo "deb http://vo.ari.uni-heidelberg.de/debian release main" > /etc/apt/sources.list.d/dachs.list


###
# Server Configuration
###
RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get install -y postgresql-13 postgresql-13-q3c postgresql-13-pgsphere 
RUN apt-get install -y git wget awstats net-tools vim libgeo-ipfree-perl
RUN service postgresql restart && apt-get install -y gavodachs2-server
RUN apt-get install -y openssh-server openssh-client apache2 w3m 


#copy the configuration files into the docker
COPY . $HOMEPATH

#import dachs server configuration files from git
RUN echo cloning from $GITURL/vespa/dachs/servers/$GITREPO_INSTITUTION/$GITREPO_SERVER.git
RUN git clone $GITURL/vespa/dachs/servers/$GITREPO_INSTITUTION/$GITREPO_SERVER.git $HOMEPATH/server


# copy files at the right path
RUN cp $HOMEPATH/000-default.conf /etc/apache2/sites-enabled/000-default.conf
RUN cp $HOMEPATH/awstats.dachs.conf /etc/awstats/awstats.dachs.conf
RUN cp $HOMEPATH/docker-entrypoint.sh /usr/bin/docker-entrypoint.sh
RUN chmod +x /usr/bin/docker-entrypoint.sh

RUN cp $HOMEPATH/server/gavo.rc /etc/gavo.rc
RUN cp $HOMEPATH/server/defaultmeta.txt /var/gavo/etc/defaultmeta.txt
RUN mkdir /var/gavo/web/nv_static/img/ -p
RUN cp $HOMEPATH/logos/* /var/gavo/web/nv_static/img/


#import services from git
#clone all repositories from the group -- only if the gitlab project is Public
RUN wget -O $HOMEPATH/group.json $GITURL'/api/v4/groups/vespa%2Fdachs%2Fservices%2F'$GITREPO_INSTITUTION'%2F'$GITREPO_SERVER
RUN mkdir $HOMEPATH/services/ && cd $HOMEPATH/services/ && egrep -o 'https://[^"]+\.git' $HOMEPATH/group.json|xargs -n 1 -P 8 git clone
RUN cp -r $HOMEPATH/services/* /var/gavo/inputs/

#extract parameters values from gavo.rc
######
#replace infos into 000default.conf, awstats.dachs.conf, ports.conf
######

##Adapt 000-default.conf ports and maintainer (taken from gavo.rc)
RUN export maintainerAddress=`grep "^maintainerAddress:" /etc/gavo.rc | cut -d ":" -f 2` && sed -i "s/webmaster@localhost/${maintainerAddress}/g" /etc/apache2/sites-enabled/000-default.conf && less /etc/apache2/sites-enabled/000-default.conf
RUN sed -i "s/8080/${APACHE_PORT}/g" /etc/apache2/sites-enabled/000-default.conf

##Adapt ports.conf with APACHE PORT
RUN sed -i "s/80/${APACHE_PORT}/g" /etc/apache2/ports.conf

##Adapt awstats.dachs.conf with server address and domain
RUN if [ "$SERVERNAME" = "localhost" ]; then \
	sed -i "s/mydomain/localhost/g" /etc/awstats/awstats.dachs.conf && sed -i "s/myserver.mydomain/localhost/g" /etc/awstats/awstats.dachs.conf \
    ;else \
	sed -i "s/mydomain/${DOMAIN}/g" /etc/awstats/awstats.dachs.conf && sed -i "s/myserver/${SERVERNAME}/g" /etc/awstats/awstats.dachs.conf \
    ;fi

##Adapt gavo.rc with ports and server name

RUN sed -i "/serverPort/c\serverPort:${DACHS_PORT}"  /etc/gavo.rc
RUN sed -i "/corsOriginPat/c\corsOriginPat:${PROTOCOL}.*" /etc/gavo.rc

RUN if [ "$SERVERNAME" = "localhost" ]; then \
         sed -i "/serverURL/c\serverURL:" /etc/gavo.rc &&\
         echo "############################ WARNING gavo.rc overwrite -- localhost for dev only ###############################" \  
    ; else \
         sed -i "/serverURL/c\serverURL:${PROTOCOL}://${SERVERNAME}.${DOMAIN}:${DACHS_PORT}" /etc/gavo.rc &&\
         echo "Warning : gavo.rc overwritten by .env servername, domain, protocol and port values" \
    ; fi

###
#dachs configuration
###
RUN chown dachsroot:gavo /var/gavo/etc/defaultmeta.txt
RUN chown dachsroot:gavo /var/gavo/web/nv_static/img/logo*
RUN chown -R dachsroot:gavo /var/gavo/inputs/*
RUN chown -R dachsroot:gavo /var/gavo/logs


###
#apache configuration
###

RUN a2enmod cgi


###
# auto update awstats data using cron
###
RUN mkdir -p ${HOMEPATH}/dachslogs
RUN echo "#!/bin/bash" > /etc/cron.daily/awstats
RUN echo "/usr/bin/perl /usr/lib/cgi-bin/awstats.pl -config=dachs -update" >> /etc/cron.daily/awstats 
RUN chgrp 755 /etc/cron.daily/awstats


###
# script to set up services
###
#RUN echo "cd $HOMEPATH/$SERVER/$GIT/" >> /usr/bin/docker-entrypoint.sh
#RUN echo "git pull" >> /usr/bin/docker-entrypoint.sh

# add to the script to maintain docker up
RUN echo "tail -f /dev/null" >> /usr/bin/docker-entrypoint.sh


ENTRYPOINT /usr/bin/docker-entrypoint.sh && tail -f /dev/null