Skip to content

Commit

Permalink
OWASP#440 Refactor of Docker build and deploy (OWASP#441)
Browse files Browse the repository at this point in the history
* Closes OWASP#440

* Making sure branch is master or dev and renaming deploy script for depoly
  • Loading branch information
ismisepaul authored and markdenihan committed Oct 15, 2018
1 parent 18523fc commit e8cce39
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 144 deletions.
28 changes: 9 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,19 @@ jobs:
include:
- stage: build
language: java
services:
- mysql
- stage: deploy-master
services: mysql
- stage: deploy
name: "Deploy to Dockerhub"
language: generic
provider: script
skip_cleanup: true
script: skip
services:
- docker
services: docker
before_install:
- mvn install -P docker -DskipTests
- docker-compose build web
script: bash docker/deploy/push_master.sh
- stage: deploy-dev
provider: script
script: skip
services:
- docker
before_install:
- mvn install -P docker -DskipTests
- docker-compose build web
script: bash docker/deploy/push_dev.sh
script: bash docker/scripts/deploy-dockerhub.sh $TRAVIS_BRANCH
stages:
- build
- name: deploy-master
if: branch = master AND type = push
- name: deploy-dev
if: branch = dev AND type = push
- name: deploy
if: branch IN (master, dev) AND type = push
13 changes: 0 additions & 13 deletions docker/deploy/push_dev.sh

This file was deleted.

14 changes: 0 additions & 14 deletions docker/deploy/push_master.sh

This file was deleted.

13 changes: 13 additions & 0 deletions docker/scripts/convert-sql-scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

core="docker/mysql/coreSchema.sql"
module="docker/mysql/moduleSchemas.sql"

sed -i 's/-- DELIMITER \$\$/DELIMITER \$\$/g' ${core}
sed -i 's/-- DELIMITER \$\$/DELIMITER \$\$/g' ${module}

sed -i 's/-- \$\$/\$\$/g' ${core}
sed -i 's/-- \$\$/\$\$/g' ${module}

sed -i 's/-- DELIMITER \;/DELIMITER \;/g' ${core}
sed -i 's/-- DELIMITER \;/DELIMITER \;/g' ${module}
27 changes: 27 additions & 0 deletions docker/scripts/deploy-dockerhub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# Pull in the .env file
if [ -f .env ]
then
export $(cat .env | xargs)
else
export $(cat ../../.env | xargs)
fi

# Check if its master or dev branch and deploy accordingly
if [ $1 == 'master' ]
then
export TAG=latest

docker login -u=$DOCKER_USER -p=$DOCKER_PASS
docker tag $IMAGE_TOMCAT:$TAG $IMAGE_TOMCAT:$VERSION
docker push $IMAGE_TOMCAT:$TAG
docker push $IMAGE_TOMCAT:$VERSION
elif [ $1 == 'dev' ]
then
export TAG=dev

docker login -u=$DOCKER_USER -p=$DOCKER_PASS
docker tag ${IMAGE_TOMCAT}:latest ${IMAGE_TOMCAT}:${TAG}
docker push ${IMAGE_TOMCAT}:${TAG}
fi
193 changes: 95 additions & 98 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>owaspSecurityShepherd</groupId>
<artifactId>owaspSecurityShepherd</artifactId>
<version>3.1.0-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
Expand Down Expand Up @@ -135,85 +140,77 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>docker</id>
<build>
<plugins>
<plugin>
<!-- Copy the SQL scripts and modify them so they can be run from mysql -->
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy-db-scripts</id>
<phase>package</phase>
<configuration>
<target>
<echo>ANT TASK - Copying database files and modifying for use with mysql</echo>
<copy todir="${basedir}/docker/mysql" overwrite="true" flatten="true">
<fileset dir="${basedir}/src/main/resources/database" includes="*.sql" >
<include name="*.sql" />
</fileset>
</copy>
<copy todir="${basedir}/docker/mongo" overwrite="true" flatten="true">
<fileset dir="${basedir}/src/database" includes="*.js" >
<include name="*.js" />
</fileset>
</copy>
<exec executable="sed">
<arg value="-i" />
<arg value="s/-- DELIMITER \$\$/DELIMITER \$\$/g" />
<arg value="${basedir}/docker/mysql/coreSchema.sql" />
<arg value="${basedir}/docker/mysql/moduleSchemas.sql" />
</exec>
<exec executable="sed">
<arg value="-i" />
<arg value="s/-- \$\$/\$\$/g" />
<arg value="${basedir}/docker/mysql/coreSchema.sql" />
<arg value="${basedir}/docker/mysql/moduleSchemas.sql" />
</exec>
<exec executable="sed">
<arg value="-i" />
<arg value="s/-- DELIMITER \;/DELIMITER \;/g" />
<arg value="${basedir}/docker/mysql/coreSchema.sql" />
<arg value="${basedir}/docker/mysql/moduleSchemas.sql" />
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>generate-tls-key</id>
<goals>
<goal>generateKeyPair</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<alias>${ALIAS}</alias>
<keyalg>${KEY_ALG}</keyalg>
<keystore>${basedir}/target/${TLS_KEYSTORE_FILE}</keystore>
<dname>${DNAME}</dname>
<storepass>${TLS_KEYSTORE_PASS}</storepass>
<keypass>${TLS_KEYSTORE_PASS}</keypass>
<deststoretype>${STORE_TYPE}</deststoretype>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<profiles>
<profile>
<id>docker</id>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-sql-scripts</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/docker/mysql</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/database</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>convert-sql-scripts</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/docker/scripts/convert-sql-scripts.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>generate-tls-key</id>
<phase>generate-resources</phase>
<goals>
<goal>generateKeyPair</goal>
</goals>
</execution>
</executions>
<configuration>
<alias>${ALIAS}</alias>
<keyalg>${KEY_ALG}</keyalg>
<keystore>${basedir}/target/${TLS_KEYSTORE_FILE}</keystore>
<dname>${DNAME}</dname>
<storepass>${TLS_KEYSTORE_PASS}</storepass>
<keypass>${TLS_KEYSTORE_PASS}</keypass>
<deststoretype>${STORE_TYPE}</deststoretype>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<build>
<finalName>${project.artifactId}</finalName>
Expand All @@ -225,24 +222,24 @@
</resources>

<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/.env</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/.env</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
Expand Down

0 comments on commit e8cce39

Please sign in to comment.