diff --git a/.gitignore b/.gitignore index 7b92c35..f03b393 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,4 @@ yarn-debug.log* .yarn-integrity reset.sh +docker diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..98dda2f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,78 @@ +FROM phusion/passenger-ruby24:1.0.9 + +MAINTAINER Benjamin FAURE + +# Setting some env vars +ENV HOME=/root \ + PASSENGER_DOWNLOAD_NATIVE_SUPPORT_BINARY=0 \ + LANGUAGE=fr_FR.UTF-8 \ + LANG=fr_FR.UTF-8 \ + LC_ALL=fr_FR.UTF-8 \ + RUBY_VERSION=2.4.9 + + +# Fetching Yarn +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ + && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list + +# Installing package dependencies +RUN apt-get -qqy update \ + && apt-get install vim \ + build-essential \ + git \ + curl \ + locales \ + libreadline-dev \ + libssl-dev \ + libsqlite3-dev \ + wget \ + imagemagick \ + xz-utils \ + libcurl4-gnutls-dev \ + libxrender1 \ + libfontconfig1 \ + apt-transport-https \ + tzdata \ + xfonts-base \ + xfonts-75dpi \ + yarn \ + ca-certificates -qqy \ + && rm -rf /var/lib/apt/lists/* + +# Fetching WKHTMLTOPDF +RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb \ + && dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb \ + && apt-get install -f + +# Set locale to UTF8 +RUN locale-gen --no-purge fr_FR.UTF-8 \ + && update-locale LANG=fr_FR.UTF-8 \ + && DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales + +# Git config +# ENV DMPOPIDOR_VERSION=V2.3.0_alpha14 +# RUN mkdir /dmponline +# RUN git config --system http.proxy $http_proxy \ +# && git config --global user.email "benjamin.faure@inist.fr" \ +# && git config --global user.name "Benjamin FAURE" \ +# && git config --global url."https://".insteadOf git:// +# WORKDIR /dmponline +# RUN git clone https://github.com/OPIDoR/DMPOPIDoR . \ +# && git checkout tags/$DMPOPIDOR_VERSION + +# Copying project files +COPY . /dmponline + +WORKDIR /dmponline + +# Installing Ruby and Node dependencies +RUN echo $RUBY_VERSION > .ruby-version \ + && gem install bundler -v 1.17.3 \ + && echo 'gem "tzinfo-data"' >> Gemfile \ + && bundle install --without mysql puma thin + +# Run the app using the rails.sh script +COPY ./rails.sh /usr/local/bin/ +RUN chmod a+x /usr/local/bin/rails.sh +RUN mkdir -p /dmponline/public/system/dragonfly && chmod a+rw -R /dmponline/public/system/dragonfly +CMD ["rails.sh"] diff --git a/rails.sh b/rails.sh new file mode 100644 index 0000000..7d60d46 --- /dev/null +++ b/rails.sh @@ -0,0 +1,43 @@ +#!/bin/bash +set -u + + +#Timezone +export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true +export PASSENGER_DOWNLOAD_NATIVE_SUPPORT_BINARY=0 +ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime +dpkg-reconfigure --frontend noninteractive tzdata +# Vérification de l'initialisation de la base +if [ ! -f /dmponline/db/.dbinit/.temoin ] ; then + # if bundle exec rake db:setup --trace RAILS_ENV=$RAILS_ENV ; then + if bundle exec rake db:create && rake db:schema:load && rake db:migrate ; then + touch /dmponline/db/.dbinit/.temoin + fi +fi + +# Création des certifs SSL si le serveur est de prod +if [ $RAILS_ENV == "production" ] ; then + # Si la clé n'existe pas, on la crée + if [ ! -f /dmponline/.ssl/localhost.key ] ; then + openssl req -new -newkey rsa:2048 -sha1 \ + -subj "/CN=`hostname`" \ + -days 365 -nodes -x509 -keyout ./.ssl/localhost.key -out ./.ssl/localhost.crt + + fi + # On copie la clé au bon endroit + cp ./.ssl/localhost.key /etc/ssl/certs + cp ./.ssl/localhost.crt /etc/ssl/certs + echo "127.0.0.1 `hostname`" | tee -a /etc/hosts + #RAILS_ENV=$RAILS_ENV bundle exec rake db:migrate + RAILS_ENV=$RAILS_ENV bundle exec rake assets:precompile + # Démarrage du serveur en SSL avec l'emplacement des clés + # bundle exec thin start -p 3001 --ssl --ssl-key-file /etc/ssl/certs/localhost.key --ssl-cert-file /etc/ssl/certs/localhost.crt + #bundle exec rails server -p 3001 -e $RAILS_ENV + nginx -c /etc/nginx/nginx.conf -t + chmod 666 /var/log/nginx/production.log + service nginx start +else + sleep 2h + #bundle exec rails server -p 40000 + +fi