diff --git a/backend/Dockerfile b/backend/Dockerfile index c3a3b1682..f0605d26d 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -37,25 +37,9 @@ RUN apt-get update && \ make -j2 && \ make install && \ cd .. && \ - rm -rf ./imagemagick; \ - git clone https://github.com/creationix/nvm.git .nvm; \ - bash -c "source .nvm/nvm.sh && nvm install v7.7.1"; \ - bash -c "source .nvm/nvm.sh && nvm alias default v7.7.1"; \ - .nvm/nvm.sh + rm -rf ./imagemagick -COPY ./scripts/lein /home/uxbox/.local/bin/lein -RUN bash -c "/home/uxbox/.local/bin/lein version" - -# Copy backend source and build release -COPY ./* /home/uxbox/backend/ -RUN bash -c "/home/uxbox/backend/scripts/dist" - - - -# Once application has been built, prepare production image -FROM openjdk:8-alpine - -LABEL maintainer="mathieu.brunot at monogramm dot io" +ENV NVM_DIR="/home/uxbox/.nvm" RUN useradd -m -g users -s /bin/bash uxbox; \ passwd uxbox -d; \ @@ -64,16 +48,41 @@ RUN useradd -m -g users -s /bin/bash uxbox; \ USER uxbox WORKDIR /home/uxbox +COPY ./scripts/lein /home/uxbox/.local/bin/lein +RUN git clone https://github.com/creationix/nvm.git .nvm; \ + bash -c "source .nvm/nvm.sh && nvm install v7.7.1"; \ + bash -c "source .nvm/nvm.sh && nvm alias default v7.7.1"; \ + bash -c ".nvm/nvm.sh"; \ + bash -c "/home/uxbox/.local/bin/lein version" + +# Copy backend source and build release +COPY ./* /home/uxbox/backend/ +RUN bash -c "/home/uxbox/backend/scripts/dist" + + + +# Once application has been built, prepare production image +FROM openjdk:8-jre-alpine + +LABEL maintainer="mathieu.brunot at monogramm dot io" + # Add uxbox as provided by builder -COPY --from=0 /home/uxbox/backend/dist/uxbox-backend.jar /home/uxbox +COPY --from=0 /home/uxbox/backend/dist/uxbox-backend.jar /srv/uxbox/app.jar + +VOLUME /srv/uxbox/resources/public + +WORKDIR /srv/uxbox/ RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen; \ - locale-gen && update-locale LANG=en_US.UTF-8 LC_ALL=C.UTF-8 - + locale-gen && update-locale LANG=en_US.UTF-8 LC_ALL=C.UTF-8; \ + mkdir -p /srv/uxbox/resources/public/media; \ + mkdir -p /srv/uxbox/resources/public/static; ENV \ # Locale setup LANG=en_US.UTF-8 LC_ALL=C.UTF-8 \ + # Application configuration + UXBOX_CONFIG=/srv/uxbox/config/application.properties \ # Security setup UXBOX_SECRET=youshouldoverwritethiswithsomethingelse \ # Debug setup @@ -99,5 +108,5 @@ ENV \ EXPOSE 6060 -COPY docker-entrypoint.sh .start.sh -CMD .start.sh +ENTRYPOINT ["sh", "/entrypoint.sh"] +CMD ["java", "-jar", "app.jar"] diff --git a/backend/docker-entrypoint.sh b/backend/docker-entrypoint.sh index 03351745c..77f966ab7 100644 --- a/backend/docker-entrypoint.sh +++ b/backend/docker-entrypoint.sh @@ -1,33 +1,56 @@ #!/usr/bin/env bash +set -e -echo 'UXBOX backend' +echo "UXBOX backend Docker entrypoint initialization..." -cd uxbox/backend -echo 'Backend configuration' -sed -i \ - -e "s/:secret .*/:secret \"${UXBOX_SECRET}\"/g" \ - \ - -e "s/:host .*/:host \"${UXBOX_DEBUG}\"/g" \ - \ - -e "s/:host .*/:host \"${UXBOX_SMTP_HOST}\"/g" \ - -e "s/:port .*/:port \"${UXBOX_SMTP_PORT}\"/g" \ - -e "s/:user .*/:user \"${UXBOX_SMTP_USER}\"/g" \ - -e "s/:pass .*/:pass \"${UXBOX_SMTP_PASSWORD}\"/g" \ - -e "s/:ssl .*/:ssl \"${UXBOX_SMTP_SSL}\"/g" \ - -e "s/:tls .*/:tls \"${UXBOX_SMTP_TLS}\"/g" \ - -e "s/:enabled .*/:enabled \"${UXBOX_SMTP_ENABLED}\"/g" \ - \ - -e "s/:host .*/:host \"${UXBOX_MAIL_REPLY}\"/g" \ - -e "s/:port .*/:port \"${UXBOX_MAIL_FROM}\"/g" \ - \ - -e "s/:adapter .*/:adapter \"${UXBOX_DB_TYPE}\"/g" \ - -e "s/:username .*/:username \"${UXBOX_DB_USER}\"/g" \ - -e "s/:password .*/:password \"${UXBOX_DB_PASSWORD}\"/g" \ - -e "s/:database-name .*/:database-name \"${UXBOX_DB_NAME}\"/g" \ - -e "s/:server-name .*/:server-name \"${UXBOX_DB_HOST}\"/g" \ - -e "s/:port-number .*/:port-number \"${UXBOX_DB_PORT}\"/g" \ - ./config/default.edn +echo 'Backend configuration...' + +# If no config provided in volume, setup a default config from environment variables +if [ ! -f $APP_CONFIG ]; then + echo "Setting up initial application configuration..." + echo "# Initial configuration generated at $(date +%Y-%m-%dT%H:%M:%S%z)" > $APP_CONFIG + + echo "# ~~~~~" >> $APP_CONFIG + echo "# Security Configuration" >> $APP_CONFIG + echo "# ~~~~~" >> $APP_CONFIG + echo "secret=${UXBOX_SECRET}" >> $APP_CONFIG + + -e "s/:host .*/:host \"${UXBOX_DEBUG}" >> $APP_CONFIG + + echo "# ~~~~~" >> $APP_CONFIG + echo "# SMTP Configuration" >> $APP_CONFIG + echo "# ~~~~~" >> $APP_CONFIG + echo "smtp.host=${UXBOX_SMTP_HOST}" >> $APP_CONFIG + echo "smtp.port=${UXBOX_SMTP_PORT}" >> $APP_CONFIG + echo "smtp.user=${UXBOX_SMTP_USER}" >> $APP_CONFIG + echo "smtp.pass=${UXBOX_SMTP_PASSWORD}" >> $APP_CONFIG + echo "smtp.ssl=${UXBOX_SMTP_SSL}" >> $APP_CONFIG + echo "smtp.tls=${UXBOX_SMTP_TLS}" >> $APP_CONFIG + echo "smtp.enabled=${UXBOX_SMTP_ENABLED}" >> $APP_CONFIG + + echo "# ~~~~~" >> $APP_CONFIG + echo "# Email Configuration" >> $APP_CONFIG + echo "# ~~~~~" >> $APP_CONFIG + echo "email.host=${UXBOX_MAIL_REPLY}" >> $APP_CONFIG + echo "email.port=${UXBOX_MAIL_FROM}" >> $APP_CONFIG + + echo "# ~~~~~" >> $APP_CONFIG + echo "# Database Configuration" >> $APP_CONFIG + echo "# ~~~~~" >> $APP_CONFIG + echo "database.adapter=${UXBOX_DB_TYPE}" >> $APP_CONFIG + echo "database.username=${UXBOX_DB_USER}" >> $APP_CONFIG + echo "database.password=${UXBOX_DB_PASSWORD}" >> $APP_CONFIG + echo "database.database-name=${UXBOX_DB_NAME}" >> $APP_CONFIG + echo "database.server-name=${UXBOX_DB_HOST}" >> $APP_CONFIG + echo "database.port-number=${UXBOX_DB_PORT}" >> $APP_CONFIG + + echo "Configuration generated." +else + echo "Configuration found." +fi + +# TODO Find how to actually pass configuration file to JAR echo 'Running backend' -java -jar /home/uxbox/uxbox-backend.jar +exec "$@" diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 65e836376..f4221d4a1 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -37,14 +37,23 @@ RUN apt-get update && \ make -j2 && \ make install && \ cd .. && \ - rm -rf ./imagemagick; \ - git clone https://github.com/creationix/nvm.git .nvm; \ - bash -c "source .nvm/nvm.sh && nvm install v7.7.1"; \ - bash -c "source .nvm/nvm.sh && nvm alias default v7.7.1"; \ - .nvm/nvm.sh + rm -rf ./imagemagick + +ENV NVM_DIR="/home/uxbox/.nvm" + +RUN useradd -m -g users -s /bin/bash uxbox; \ + passwd uxbox -d; \ + echo "uxbox ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +USER uxbox +WORKDIR /home/uxbox COPY ./scripts/lein /home/uxbox/.local/bin/lein -RUN bash -c "/home/uxbox/.local/bin/lein version" +RUN git clone https://github.com/creationix/nvm.git .nvm; \ + bash -c "source .nvm/nvm.sh && nvm install v7.7.1"; \ + bash -c "source .nvm/nvm.sh && nvm alias default v7.7.1"; \ + bash -c ".nvm/nvm.sh"; \ + bash -c "/home/uxbox/.local/bin/lein version" ENV API_URL http://127.0.0.1:6060/api