Update code and build for deployment to ElasticBeanstalk.

This commit is contained in:
Jonathan Bernard 2016-12-17 13:22:57 -06:00
parent 409469c624
commit a132f6540c
6 changed files with 66 additions and 18 deletions

View File

@ -10,3 +10,5 @@ global:
profile: eb-cli
repository: null
sc: git
deploy:
artifact: build/ROOT.war

View File

@ -74,29 +74,29 @@ testWar.dependsOn compileScss
task incrementBuildNumber(
group: 'versioning',
description: "Increment the project's build number."
) << { ++version.build }
) { doLast { ++version.build } }
task incrementMinorNumber(
group: 'versioning',
description: "Increment the project's minor version number."
) << { ++version.minor }
) { doLast { ++version.minor } }
task incrementMajorNumber(
group: 'versioning',
description: "Increment the project's major version number."
) << { ++version.major }
) { doLast { ++version.major } }
task markReleaseBuild(
group: 'versioning',
description: "Mark this version of the project as a release version."
) << { version.release = true }
) { doLast { version.release = true } }
war.dependsOn << incrementBuildNumber
testWar.dependsOn << incrementBuildNumber
// ## Custom tasks for local deployment
task deployLocal(dependsOn: ['build']) << {
task deployLocal(dependsOn: ['build']) { doLast {
def warName = "${project.name}-${version.releaseVersion}.war"
def jettyHome = System.getenv("JETTY_HOME")
def deployedWar = new File("$jettyHome/webapps/$warName")
@ -105,16 +105,29 @@ task deployLocal(dependsOn: ['build']) << {
copy {
from "build/libs"
into "$jettyHome/webapps"
include warName } }
include warName } } }
task killJettyLocal() << {
task deployProd(dependsOn: ['build']) { doLast {
def warName = "${project.name}-${version.releaseVersion}.war"
def artifactName = "${project.name}.war"
copy {
from "build/libs"
into "build"
include warName
rename warName, artifactName }
shell_("eb", "deploy", "-l", "${project.name}-${version}")
} }
task killJettyLocal() { doLast {
def pidFile = new File(System.properties['user.home'] + "/temp/jetty.pid")
println "Killing old Jetty instance."
shell_("sh", "-c", 'kill $(jps -l | grep start.jar | cut -f 1 -d " ")') }
shell_("sh", "-c", 'kill $(jps -l | grep start.jar | cut -f 1 -d " ")') } }
task localJetty(dependsOn: ['killJettyLocal', 'deployLocal']) << {
spawn(["java", "-jar", "start.jar"], new File(jettyHome)) }
task localJetty(dependsOn: ['killJettyLocal', 'deployLocal']) { doLast {
spawn(["java", "-jar", "start.jar"], new File(jettyHome)) } }
// ## Project Version
class ProjectVersion {

View File

@ -0,0 +1,18 @@
import ch.qos.logback.core.*;
import ch.qos.logback.core.encoder.*;
import ch.qos.logback.core.read.*;
import ch.qos.logback.core.rolling.*;
import ch.qos.logback.core.status.*;
import ch.qos.logback.classic.net.*;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
appender("STDOUT", ConsoleAppender) {
encoder(PatternLayoutEncoder) {
pattern = "%level %logger - %msg%n"
}
}
root(INFO, ["STDOUT"])
logger('com.jdbernard', INFO)

View File

@ -7,7 +7,7 @@ import com.jdbernard.nlsongs.model.Song
public class NLSongsContext {
public static NLSongsDB songsDB
public static String mediaBaseUrl
public static String makeUrl(Service service, Song song) {

View File

@ -9,16 +9,31 @@ import com.jdbernard.nlsongs.db.NLSongsDB
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import org.slf4j.Logger
import org.slf4j.LoggerFactory
public final class NLSongsContextListener implements ServletContextListener {
private static final log = LoggerFactory.getLogger(NLSongsContextListener)
public void contextInitialized(ServletContextEvent event) {
def context = event.servletContext
// Load the context configuration.
Properties props = new Properties()
NLSongsContextListener.getResourceAsStream(
context.getInitParameter('context.config.file')).withStream { is ->
props.load(is) }
// Load database details from the context configuration.
String contextConfigFile = context.getInitParameter('context.config.file')
if (contextConfigFile) {
NLSongsContextListener.getResourceAsStream(contextConfigFile)
.withStream { is -> props.load(is) } }
// Load database configuration from environment variables (may
// override settings in file).
def env = System.getenv()
env.keySet().findAll { it.startsWith('DB_') }.each { key ->
props[key.substring(3)] = env[key] }
log.debug("Database configuration: {}", props)
// Create the pooled data source
HikariConfig hcfg = new HikariConfig(
@ -39,6 +54,6 @@ public final class NLSongsContextListener implements ServletContextListener {
// Shutdown the Songs DB instance (it will shut down the data source).
NLSongsDB songsDB = context.getAttribute('songsDB')
if (songsDB) songsDB.shutdown()
context.removeAttribute('songsDB') }
}

View File

@ -1,6 +1,6 @@
#
#Sat Apr 16 23:30:54 CDT 2016
#Sat Dec 17 17:15:27 CST 2016
major=2
version.release=false
minor=4
build=6
build=31