Skip to content

Commit

Permalink
add application CDS
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Apr 28, 2024
1 parent d563d51 commit 536ff17
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 51 deletions.
38 changes: 25 additions & 13 deletions build.gradle
Expand Up @@ -19,6 +19,7 @@ buildscript {
//
}


repositories {
maven {
url "https://plugins.gradle.org/m2/"
Expand All @@ -28,21 +29,21 @@ buildscript {
}

plugins {
id 'io.freefair.lombok' version '8.4'
id 'io.freefair.lombok' version '8.6'
id 'java'
id 'idea'
id 'org.kordamp.gradle.jacoco' version '0.54.0'
id 'com.github.ben-manes.versions' version '0.51.0'
id 'com.github.hierynomus.license' version '0.16.1'
id 'net.researchgate.release' version '3.0.2'
id 'org.springframework.boot' version '3.2.5'
id 'org.sonarqube' version '4.4.1.3373'
id 'org.springframework.boot' version '3.3.0-RC1'
id 'io.spring.dependency-management' version '1.1.4'
id 'org.sonarqube' version '5.0.0.4638'
// id 'net.ltgt.errorprone' version '3.1.0'
id 'com.github.node-gradle.node' version '7.0.2'
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'project-report'
Expand Down Expand Up @@ -99,6 +100,7 @@ configurations {
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}

dependencies {
Expand All @@ -121,7 +123,8 @@ dependencies {
/**/
implementation 'com.google.zxing:core:3.5.3'
implementation 'com.google.zxing:javase:3.5.3'
implementation "org.flywaydb:flyway-core"
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-database-postgresql'
implementation "org.postgresql:postgresql"
implementation "com.zaxxer:HikariCP"

Expand All @@ -141,7 +144,10 @@ dependencies {
implementation 'net.sf.biweekly:biweekly:0.6.6'
implementation 'com.atlassian.commonmark:commonmark:0.17.0'
implementation 'com.atlassian.commonmark:commonmark-ext-gfm-tables:0.17.0'
implementation 'com.ryantenney.passkit4j:passkit4j:2.0.1'
implementation 'com.ryantenney.passkit4j:passkit4j:2.0.1', {
exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
}
implementation 'org.bouncycastle:bcprov-jdk15on:1.70'
implementation 'com.github.ben-manes.caffeine:caffeine'
implementation 'com.github.scribejava:scribejava-core:8.3.3'
implementation 'ch.digitalfondue.vatchecker:vatchecker:1.6.0'
Expand Down Expand Up @@ -287,7 +293,7 @@ compileJava {
compileJava.dependsOn(processResources)

//propagate the system properties to the tests
test {
tasks.named('test') {
useJUnitPlatform()
systemProperties = System.properties
systemProperties.remove("java.endorsed.dirs")
Expand Down Expand Up @@ -375,17 +381,23 @@ tasks.register('publicFrontendIndexTransform', FrontendIndexTransformTask) {
//}

tasks.register('distribution', Copy) {
from zipTree(project.layout.buildDirectory.file("libs/alfio-${project.version}-boot.war"))
from project.layout.buildDirectory.file("libs/alfio-${project.version}-boot.jar")
rename(new Transformer<String, String>() {
@Override
String transform(String s) {
return "alfio-boot.jar"
}
})
into layout.buildDirectory.dir("dockerize")
dependsOn publicFrontendIndexTransform, build, dockerize
}

tasks.register('clever', Copy) {
from project.layout.buildDirectory.file("libs/alfio-${project.version}-boot.war")
from project.layout.buildDirectory.file("libs/alfio-${project.version}-boot.jar")
rename(new Transformer<String, String>() {
@Override
String transform(String s) {
return "alfio-boot.war"
return "alfio-boot.jar"
}
})
into project.layout.buildDirectory.dir("clevercloud")
Expand All @@ -401,17 +413,17 @@ release {
}
}

bootWar {
bootJar {
dependsOn publicFrontendIndexTransform//, adminFrontendIndexTransform
archiveClassifier.set('boot')
from(tasks.named("frontendBuild")) {
into 'resources'
}
from(tasks.named("publicFrontendIndexTransform")) {
rename 'alfio-public-frontend-index.html', 'WEB-INF/classes/alfio-public-frontend-index.html'
rename 'alfio-public-frontend-index.html', 'BOOT-INF/classes/alfio-public-frontend-index.html'
}
/*from(tasks.named("adminFrontendIndexTransform")) {
rename 'alfio-admin-frontend-index.html', 'WEB-INF/classes/alfio-admin-frontend-index.html'
rename 'alfio-admin-frontend-index.html', 'BOOT-INF/classes/alfio-admin-frontend-index.html'
}*/
def bowerDir = "resources/bower_components"
def excludesFile = new File("./lib_exclude")
Expand Down
2 changes: 1 addition & 1 deletion clevercloud/jar.json
Expand Up @@ -4,6 +4,6 @@
"goal": "clever -x test"
},
"deploy": {
"jarName": "build/clevercloud/alfio-boot.war"
"jarName": "build/clevercloud/alfio-boot.jar"
}
}
4 changes: 2 additions & 2 deletions etc/cloudfoundry/manifest.yml
@@ -1,9 +1,9 @@
---
applications:
- name: alfio
path: alf.io-boot.war
path: alf.io-boot.jar
instances: 1
buildpack: https://github.com/cloudfoundry/java-buildpack.git
memory: 256m
env:
JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ } }'
JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 17.+ } }'
2 changes: 1 addition & 1 deletion etc/heroku/Procfile
@@ -1 +1 @@
web: java -Dserver.port=$PORT $JAVA_OPTS -jar alfio-*-boot.war
web: java -Dserver.port=$PORT $JAVA_OPTS -jar alfio-*-boot.jar
2 changes: 1 addition & 1 deletion etc/heroku/system.properties
@@ -1 +1 @@
java.runtime.version=11
java.runtime.version=17
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
8 changes: 8 additions & 0 deletions settings.gradle
@@ -1 +1,9 @@
pluginManagement {
repositories {
maven { url 'https://repo.spring.io/milestone' }
gradlePluginPortal()
}
}

rootProject.name = 'alfio'

12 changes: 7 additions & 5 deletions src/main/dist/Dockerfile
Expand Up @@ -6,7 +6,7 @@
#

FROM azul/zulu-openjdk-alpine:17 as zulu

COPY alfio-boot.jar .
RUN $JAVA_HOME/bin/jlink --compress=1 --strip-java-debug-attributes --no-header-files --no-man-pages \
--module-path $JAVA_HOME/jmods \
# see https://docs.oracle.com/en/java/javase/11/security/oracle-providers.html#GUID-9224B90B-7B2F-41F9-BB96-C0A1B6A0FEAA
Expand All @@ -15,6 +15,9 @@ RUN $JAVA_HOME/bin/jlink --compress=1 --strip-java-debug-attributes --no-header-
--output /jlinked

RUN /jlinked/bin/java -Xshare:dump -XX:+UseSerialGC -version
RUN $JAVA_HOME/bin/java -Djarmode=tools -jar alfio-boot.jar extract --destination /cds && \
(cd /cds && java -XX:ArchiveClassesAtExit=alfio-cds.jsa -Dspring.profiles.active=app-cds -Dspring.context.exit=onRefresh -jar alfio-boot.jar)


FROM alpine:3.19
LABEL org.opencontainers.image.source=https://github.com/alfio-event/alf.io
Expand All @@ -33,14 +36,13 @@ USER 1001
RUN mkdir /home/alfio/app
WORKDIR /home/alfio/app

RUN mkdir logs
COPY --chown=alfio WEB-INF WEB-INF
COPY --chown=alfio resources resources
COPY --chown=alfio --from=zulu /cds/alfio-cds.jsa .
COPY --chown=alfio alfio-boot.jar .

ENV ALFIO_JAVA_OPTS=""
ENV ALFIO_PERFORMANCE_OPTS="-Dspring.jmx.enabled=false -Dlog4j2.disableJmx=true"

CMD /opt/jdk/bin/java $ALFIO_JAVA_OPTS $ALFIO_PERFORMANCE_OPTS -XX:+UseContainerSupport \
-cp ./WEB-INF/classes:./resources:./WEB-INF/lib/*:./WEB-INF/lib-provided/* alfio.config.SpringBootLauncher
-XX:SharedArchiveFile=alfio-cds.jsa -jar alfio-boot.jar

EXPOSE 8080
41 changes: 14 additions & 27 deletions src/main/java/alfio/config/DataSourceConfiguration.java
Expand Up @@ -41,14 +41,14 @@
import ch.digitalfondue.npjt.mapper.ColumnMapperFactory;
import ch.digitalfondue.npjt.mapper.ParameterConverter;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.MigrationVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.EmptySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
Expand Down Expand Up @@ -98,7 +98,7 @@ public PlatformProvider getCloudProvider(Environment environment) {
@Bean
@Profile({"!"+Initializer.PROFILE_INTEGRATION_TEST, "travis"})
public DataSource getDataSource(Environment env, PlatformProvider platform) {
if(platform == PlatformProvider.CLOUD_FOUNDRY) {
if(platform == PlatformProvider.CLOUD_FOUNDRY || platform == PlatformProvider.DRY_RUN) {
return new FakeCFDataSource();
} else {
HikariDataSource dataSource = new HikariDataSource();
Expand Down Expand Up @@ -166,19 +166,25 @@ public Supplier<Executor> getNewSingleThreadExecutorSupplier() {
}

@Bean
public Flyway migrator(DataSource dataSource) {
public Flyway migrator(DataSource dataSource, Environment environment) {
boolean dryRun = environment.acceptsProfiles(Profiles.of(Initializer.PROFILE_APP_CDS));
var configuration = Flyway.configure();
var jdbcTemplate = new JdbcTemplate(dataSource);
var matches = jdbcTemplate.queryForObject("select count(*) from information_schema.tables where table_name = 'schema_version'", Integer.class);
var tableName = matches != null && matches > 0 ? "schema_version" : configuration.getTable();
String tableName = configuration.getTable();
if (!dryRun) {
var jdbcTemplate = new JdbcTemplate(dataSource);
var matches = jdbcTemplate.queryForObject("select count(*) from information_schema.tables where table_name = 'schema_version'", Integer.class);
tableName = matches != null && matches > 0 ? "schema_version" : configuration.getTable();
}
configuration.table(tableName)
.dataSource(dataSource)
.validateOnMigrate(false)
.target(MigrationVersion.LATEST)
.outOfOrder(true)
.locations("alfio/db/PGSQL/");
Flyway migration = new Flyway(configuration);
migration.migrate();
if (!dryRun) {
migration.migrate();
}
return migration;
}

Expand Down Expand Up @@ -318,7 +324,7 @@ DemoModeDataManager demoModeDataManager(UserRepository userRepository,
}

/**
* Fake DataSource used on Cloud Foundry. Oh yeah.
* Fake DataSource used on Cloud Foundry.
*/
private static class FakeCFDataSource extends AbstractDataSource {
@Override
Expand All @@ -331,24 +337,5 @@ public Connection getConnection(String username, String password) {
return null;
}

public boolean isWrapperFor(Class<?> iface) throws java.sql.SQLException {
return iface.isAssignableFrom(this.getClass());
}

public <T> T unwrap(Class<T> iface) throws java.sql.SQLException {
try {
if(iface.isAssignableFrom(this.getClass())) {
return iface.cast(this);
}
throw new java.sql.SQLException("Auto-generated unwrap failed; Revisit implementation");
} catch (Exception e) {
throw new java.sql.SQLException(e);
}
}

public java.util.logging.Logger getParentLogger() {
// TODO Auto-generated method stub
return null;
}
}
}
1 change: 1 addition & 0 deletions src/main/java/alfio/config/Initializer.java
Expand Up @@ -31,6 +31,7 @@

public class Initializer extends AbstractAnnotationConfigDispatcherServletInitializer {

public static final String PROFILE_APP_CDS = "app-cds";
public static final String PROFILE_DEV = "dev";
public static final String PROFILE_INTEGRATION_TEST = "integration-test";
public static final String PROFILE_LIVE = "!dev";
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/alfio/config/support/PlatformProvider.java
Expand Up @@ -16,7 +16,9 @@
*/
package alfio.config.support;

import alfio.config.Initializer;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;

import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -39,6 +41,13 @@
public enum PlatformProvider {
DEFAULT,

DRY_RUN {
@Override
public boolean isHosting(Environment env) {
return env.acceptsProfiles(Profiles.of(Initializer.PROFILE_APP_CDS));
}
},

//see
// https://developers.openshift.com/external-services/elephantsql.html
// http://docs.run.pivotal.io/marketplace/services/elephantsql.html
Expand Down

0 comments on commit 536ff17

Please sign in to comment.