Commit 00ee52ab by Anton Sudak

Merge branch 'master' into PLAY-157

parents c77112ad 23869e57
......@@ -16,6 +16,7 @@ node_modules
*.iml
# Others
/data
/logs
/tmp
/dist
......
......@@ -33,6 +33,7 @@ deploy_live:
ANSIBLE_OPTION_DOCKER_REGISTRY_PASSWORD: ${PUBLISH_PASSWORD}
ANSIBLE_OPTION_MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ANSIBLE_OPTION_MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD}
ANSIBLE_OPTION_APP_BLUE_GREEN_ENABLE: "true"
only:
- master
......
[local]
localhost ansible_connection=local
[live]
play-cms-demo.insign.rocks ansible_connection=ssh ansible_user=insign
[all:children]
local
live
......@@ -2,4 +2,7 @@
-Dsbt.boot.directory=project/.boot
-Dsbt.ivy.home=project/.ivy
-Dplaycms.version=local
# Ensure line feed at file end because otherwise sbt in docker will ignore the last parameter
#-J-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
-J-Xms256m
-J-Xmx2g
-J-XX:MaxMetaspaceSize=512m
import play.sbt.PlayImport.PlayKeys.devSettings
import sbt.Project.projectToRef
lazy val uploadsFolder: String =
(file(".") / "data" / "uploads").getAbsoluteFile.getAbsolutePath
lazy val mysqlDataFolder: String =
(file(".") / "data" / "mysql").getAbsoluteFile.getAbsolutePath
lazy val mailhogDataFolder: String =
(file(".") / "data" / "mailhog").getAbsoluteFile.getAbsolutePath
scalaVersion := Settings.versions.scala
lazy val server = (project in file("server"))
......@@ -18,7 +28,7 @@ lazy val server = (project in file("server"))
resolvers ++= Settings.resolvers.value,
// a simple test support of non-dockerized application(for the usage of sbt:test outside of docker)
// a simple test support of application
javaOptions in Test += "-Dconfig.file=conf/application.test.conf",
// fixes problem with loading entities in prod mode,
......@@ -47,17 +57,104 @@ lazy val server = (project in file("server"))
// Add java options for packager
javaOptions in Universal ++= Seq(
// -J params will be added as jvm parameters
"-J-Xmx2048m",
"-J-Xmx2g",
"-J-Xms256m"
),
devSettings := {
val envVars = Map(
"APPLICATION_HOST" -> "localhost",
"MYSQL_HOST" -> "localhost",
"MYSQL_PORT" -> "3306",
"MYSQL_DATABASE" -> "db_play-cms-demo",
"MYSQL_USER" -> "play-cms-demo",
"MYSQL_PASSWORD" -> "s3cr3t",
"ELASTICSEARCH_ENABLE" -> "false",
"ELASTICSEARCH_INDEX" -> "play-cms-demo",
"ELASTICSEARCH_HOST" -> "localhost",
"ELASTICSEARCH_PORT" -> "9200",
"SMTP_MOCK" -> "false",
"SMTP_HOST" -> "localhost",
"SMTP_PORT" -> "1025",
"FILEMANAGER_BASE_URL" -> "http://localhost:8035/"
)
envVars.foreach { case (k, v) =>
java.lang.System.setProperty(k, v)
}
envVars.toSeq
},
dockerContainers := Seq(
/*DockerContainer(
id = "elasticsearch",
name = "docker.elastic.co/elasticsearch/elasticsearch",
version = "6.4.0",
ports = Seq(
9200 `:` 9200,
9300 `:` 9300
),
environment = Map(
"discovery.type" -> "single-node"
)
),*/
DockerContainer(
id = "play-cms-demo_mysql",
name = "mysql",
version = "5.7",
ports = Seq(
3306 `:` 3306
),
volumes = Seq(
"/var/lib/mysql" `:` mysqlDataFolder
),
environment = Map(
"MYSQL_ROOT_PASSWORD" -> "s3cr3t",
"MYSQL_DATABASE" -> "db_play-cms-demo",
"MYSQL_USER" -> "play-cms-demo",
"MYSQL_PASSWORD" -> "s3cr3t"
)
),
DockerContainer(
id = "play-cms-demo_mailhog",
name = "mailhog/mailhog",
version = "v1.0.0",
ports = Seq(
1025 `:` 1025,
8025 `:` 8025
),
volumes = Seq(
"/home/mailhog" `:` mailhogDataFolder
),
environment = Map(
"MH_CORS_ORIGIN" -> "*",
"MH_STORAGE" -> "maildir",
"MH_MAILDIR_PATH" -> "/home/mailhog"
)
),
DockerContainer(
id = "play-cms-demo_filemanager",
name = "docker.insign.rocks/responsive-filemanager",
ports = Seq(
80 `:` 8035
),
volumes = Seq(
"/var/www/html/source" `:` s"$uploadsFolder/source",
"/var/www/html/thumbs" `:` s"$uploadsFolder/thumbs"
),
environment = Map(
"AUTH_HOST" -> "app", // This works because it's in the container's /etc/hosts
"AUTH_PORT" -> "9000"
)
)
)
)
.enablePlugins(PlayJava, SbtWeb, DockerPlugin)
.enablePlugins(PlayJava, SbtWeb, DockerPlugin, DockerRun)
.dependsOn(sharedJvm)
.devModules(
"ch.insign" %% "play-cms" % Settings.playCmsVersion as "cms" at "modules/play-cms" when Settings.playCmsLocal,
"ch.insign" %% "play-auth" % Settings.playCmsVersion as "auth" at "modules/play-cms" when Settings.playCmsLocal,
"ch.insign" %% "play-commons" % Settings.playCmsVersion as "commons" at "modules/play-cms" when Settings.playCmsLocal,
"ch.insign" %% "play-theme-metronic" % Settings.playCmsVersion as "metronic" at "modules/play-cms" when Settings.playCmsLocal)
"ch.insign" %% "play-cms" % Settings.playCmsVersion as "cms" at "../play-cms" when Settings.playCmsLocal,
"ch.insign" %% "play-auth" % Settings.playCmsVersion as "auth" at "../play-cms" when Settings.playCmsLocal,
"ch.insign" %% "play-commons" % Settings.playCmsVersion as "commons" at "../play-cms" when Settings.playCmsLocal,
"ch.insign" %% "play-theme-metronic" % Settings.playCmsVersion as "metronic" at "../play-cms" when Settings.playCmsLocal)
//////////////////////////
// ScalaJs Integration
......@@ -115,14 +212,9 @@ lazy val sharedJs = shared.js
// End of ScalaJs Integration
//////////////////////////
name := Settings.name
// Fixes: compilation error "File name too long" which can happen on some encrypted or legacy file systems.
// Please see [SI-3623](https://issues.scala-lang.org/browse/SI-3623) for more details.
scalacOptions ++= Seq("-Xmax-classfile-name", "100")
// Resolve only newly added dependencies
updateOptions := updateOptions.value.withCachedResolution(true)
// loads the Play server project at sbt startup
onLoad in Global := (Command.process("project server", _: State)) compose (onLoad in Global).value
// Set default project
lazy val root = project.in(file("."))
.settings(
name := Settings.name,
onLoad in Global ~= (_ andThen ("project server" :: _))
)
# Copy this file to ".env" to override environment variables for services.yml or sbt.yml
# See https://docs.docker.com/compose/env-file/
# services.yml environment variables
APPLICATION_HOST=localhost
PROXY_HTTP_PORT=80
PROXY_HTTPS_PORT=443
APP_DEBUG_PORT=9999
# sbt.yml environment variables
SMTP_PORT=25
MAILHOG_PORT=8025
MYSQL_PORT=3306
FROM ubuntu:16.04
ENV SBT_HOME /home/sbt
# SBT is run with user `sbt`, uid = 1000
# If you bind mount a volume from the host or a data container,
# ensure you use the same uid
RUN useradd -d "$SBT_HOME" -u 1000 -m -s /bin/bash sbt
RUN chown -R sbt:sbt "$SBT_HOME"
# SBT home directory is a volume, so configuration and downloaded
# dependencies can be persisted and survive image upgrades
VOLUME /home/sbt
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
git \
curl \
wget \
zip \
unzip \
npm \
locales \
software-properties-common \
apt-transport-https \
imagemagick \
&& rm -rf /var/lib/apt/lists/*
# Set locales
RUN locale-gen en_GB.UTF-8
ENV LANG en_GB.UTF-8
ENV LC_CTYPE en_GB.UTF-8
# grab gosu for easy step-down from root
RUN gpg --keyserver pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture)" \
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/1.2/gosu-$(dpkg --print-architecture).asc" \
&& gpg --verify /usr/local/bin/gosu.asc \
&& rm /usr/local/bin/gosu.asc \
&& chmod +x /usr/local/bin/gosu
# Install Oracle Java 8
RUN apt-get update && echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections \
&& echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list \
&& echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list \
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 \
&& apt-get update && apt-get install -y \
oracle-java8-installer \
oracle-java8-set-default \
&& rm -rf /var/lib/apt/lists/*
# Install NodeJS
# gpg keys listed at https://github.com/nodejs/node
RUN set -ex \
&& for key in \
9554F04D7259F04124DE6B476D5A82AC7E37093B \
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \
FD3A5288F042B6850C66B31F09FE44734EB7990E \
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
B9AE9905FFD7803F25714661B63B535A4C206CA9 \
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
; do \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
done
ENV NPM_CONFIG_LOGLEVEL info
ENV NODE_VERSION 7.0.0
RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
&& grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
&& tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \
&& rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs
RUN npm install source-map-support
RUN npm install jsdom
# Install SBT
RUN echo "deb https://dl.bintray.com/sbt/debian /" | tee /etc/apt/sources.list.d/sbt.list \
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823 \
&& apt-get update \
&& apt-get install -y sbt
# Set the time zone to Europe/Zurich
ENV TZ Europe/Zurich
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo "$TZ" > /etc/timezone
RUN mkdir -p /var/app/current
WORKDIR /var/app/current
VOLUME /var/app/current
EXPOSE 9000
COPY ./entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["sbt", "-d", "run"]
deb http://apt.dockerproject.org/repo ubuntu-trusty main
#!/usr/bin/env bash
set -e
if [ "$1" = 'sbt' ]; then
# dev mode
# Make sure `sbt` user has the same uid as owner of the workdir
if [ -n "$SHARED_VOLUME_UID" ]; then
usermod -u $SHARED_VOLUME_UID sbt
chown -R sbt:sbt /var/app/current
chown -R sbt:sbt /home/sbt
fi
export HOME=/home/sbt
exec gosu sbt "$@"
else
exec "$@"
fi
#!/bin/bash
COMPOSE_PROJECT_NAME=playcmsdemo
export COMPOSE_PROJECT_NAME
PROJECT_ABS_PATH="$(cd $(dirname $0)/.. && pwd -P)"
export PROJECT_ABS_PATH
function resolveDockerHostVolumeUid() {
if [[ -z "$DOCKER_HOST_VOLUME_UID" ]]; then
if [ "$(uname)" == "Darwin" ]; then
STAT="stat -f"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
STAT="stat -c"
fi
if [[ -z "$DOCKER_MACHINE_NAME" && -n "$STAT" ]]; then
DOCKER_HOST_VOLUME_UID=`${STAT} "%u" $PROJECT_ABS_PATH`
else
DOCKER_HOST_VOLUME_UID=""
fi
fi
echo $DOCKER_HOST_VOLUME_UID
}
function resolveDockerHostAddr() {
# Resolve the address of the docker server
if [[ -z "$DOCKER_HOST_ADDR" ]]; then
if [[ -n "$DOCKER_MACHINE_NAME" ]]; then
DOCKER_HOST_ADDR=`docker-machine ip $DOCKER_MACHINE_NAME`
else
DOCKER_HOST_ADDR="127.0.0.1"
fi
fi
echo $DOCKER_HOST_ADDR
}
function resolveDockerClientHostAddr() {
# Resolve the address of the docker client as seen from docker containers
if [[ -z "$DOCKER_MACHINE_NAME" ]]; then
# If docker server runs locally then local host services can be accessed via gateway address of the default
# docker "bridge" network which is always "172.17.0.1"
DOCKER_CLIENT_HOST_ADDR="172.17.0.1"
else
# If docker server runs on the remote host then local host can be accessed via LAN address
# which is usually has a route to the Internet (or Google's DNS)
DOCKER_CLIENT_HOST_ADDR=`ip route get 8.8.8.8 | tr -d '\n' | sed -e 's/^.* src \([^ ]*\).*$/\1/'`
fi
echo $DOCKER_CLIENT_HOST_ADDR
}
function services_yml() {
if [[ -z "$COMPOSE_FILE" ]]; then
COMPOSE_FILE="${PROJECT_ABS_PATH}/devops/docker/services.yml"
fi
if [[ -z "$DOCKER_HOST_VOLUME_UID" ]]; then
DOCKER_HOST_VOLUME_UID="$(resolveDockerHostVolumeUid)"
fi
if [[ -z "$DOCKER_HOST_ADDR" ]]; then
DOCKER_HOST_ADDR="$(resolveDockerHostAddr)"
fi
if [[ -z "$DOCKER_CLIENT_HOST_ADDR" ]]; then
DOCKER_CLIENT_HOST_ADDR="$(resolveDockerClientHostAddr)"
fi
if [[ -z "$DOCKER_HOST_NAME" ]]; then
DOCKER_HOST_NAME=$(dig +short -x $DOCKER_HOST_ADDR | sed 's/.$//')
DOCKER_HOST_NAME=${DOCKER_HOST_NAME:-$DOCKER_HOST_ADDR}
fi
(cd $(dirname $0) && \
DOCKER_HOST_VOLUME_UID="${DOCKER_HOST_VOLUME_UID}" \
DOCKER_HOST_NAME="${DOCKER_HOST_NAME}" \
DOCKER_HOST_ADDR="${DOCKER_HOST_ADDR}" \
PROJECT_ABS_PATH="${PROJECT_ABS_PATH}" \
DOCKER_CLIENT_HOST_ADDR="${DOCKER_CLIENT_HOST_ADDR}" \
docker-compose -p ${COMPOSE_PROJECT_NAME} -f ${COMPOSE_FILE} "$@")
}
function sbt_yml() {
COMPOSE_FILE="${PROJECT_ABS_PATH}/devops/docker/sbt.yml" \
services_yml "$@"
}
function export_app_env() {
# Read environment variables from the 'app' service
sbt_yml up -d --no-deps app && sbt_yml kill app > /dev/null 2>&1
APP_SERVICE="${COMPOSE_PROJECT_NAME}_app_1"
APP_ENV=$(docker inspect \
-f '{{range $index, $value := .Config.Env}}export "{{$value}}"{{println}}{{end}}' ${APP_SERVICE} \
| grep -E "(APPLICATION_*|MYSQL_*|SBT_OPTS*|SMTP_*|UPLOADS_*)")
echo ${APP_ENV}
}
FROM php:5.6-apache
# Install php core extensions
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
# MCrypt
&& docker-php-ext-install iconv mcrypt mbstring \
# Graphics
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd
ADD host.conf /etc/apache2/sites-enabled/000-default.conf
RUN usermod -u 1000 www-data
RUN groupmod -g 1000 www-data
COPY ./entrypoint.sh /
RUN chmod +x /entrypoint.sh
CMD ["apache2-foreground"]
ENTRYPOINT ["/entrypoint.sh"]
#!/usr/bin/env bash
set -e
# Make sure `www-data` user has the same uid as owner of the shared volume
if [ -n "$SHARED_VOLUME_UID" ]; then
usermod -u $SHARED_VOLUME_UID www-data
chown -R www-data:www-data /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html
fi
# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- apache2-foreground "$@"
fi
exec "$@"
<VirtualHost *:80>
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
\ No newline at end of file
FROM mailhog/mailhog
ENV MH_CORS_ORIGIN *
ENV MH_STORAGE maildir
ENV MH_MAILDIR_PATH /var/app/mailhog
USER root
RUN mkdir -p /var/app/mailhog
RUN chown mailhog:mailhog /var/app/mailhog
USER mailhog
VOLUME /var/app/mailhog
EXPOSE 8025 1025
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
</head>
<body>
<article>
<h1>We&rsquo;ll be back soon!</h1>
<div>
<p>We apologize for the inconvenience, but we're performing some maintenance and we&rsquo;ll be back online shortly!</p>
<p>&mdash; insign gmbh</p>
</div>
</article>
</body>
</html>
\ No newline at end of file
FROM php:5.6-apache
RUN a2enmod xml2enc
RUN a2enmod proxy
RUN a2enmod proxy_balancer
RUN a2enmod lbmethod_byrequests
RUN a2enmod proxy_http
RUN a2enmod proxy_connect
RUN a2enmod proxy_html
RUN a2enmod proxy_wstunnel
RUN a2enmod rewrite
RUN a2enmod headers
RUN a2enmod ssl
RUN a2enmod remoteip
ARG SITE_CONFIG=proxy.conf
# Add SSL support
# https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-16-04
ADD ssl/apache-selfsigned.key /etc/ssl/certs/apache-selfsigned.key
ADD ssl/apache-selfsigned.crt /etc/ssl/certs/apache-selfsigned.crt
ADD ssl/ssl-params.conf /etc/apache2/conf-available/ssl-params.conf