Skip to content

Commit

Permalink
Add version + refactor package name
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
  • Loading branch information
pditommaso committed Jun 4, 2023
1 parent 5bce64c commit 947189c
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

# Ignore Gradle build output directory
build
*.log
*.log
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
27 changes: 25 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ test {
useJUnitPlatform()
}

// read the version from the `VERSION` file
version = new File(rootDir,'VERSION').text.trim()
group = 'io.seqera'

application {
// Define the main class for the application.
mainClass = 'io.seqera.wavelit.app.App'
mainClass = 'io.seqera.wavelit.App'
// Run the Graalvm agent to resolve dynamic proxyes configuration
applicationDefaultJvmArgs = ["-agentlib:native-image-agent=config-merge-dir=conf/"]
}
Expand All @@ -52,7 +56,7 @@ graalvmNative {
binaries {
main {
imageName = 'wavelit'
mainClass = 'io.seqera.wavelit.app.App'
mainClass = 'io.seqera.wavelit.App'
configurationFileDirectories.from(file('conf'))
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(19)
Expand All @@ -62,3 +66,22 @@ graalvmNative {
toolchainDetection = true
testSupport = false
}

task buildInfo {
doLast {
def version = rootProject.file('VERSION').text.trim()
def commitId = System.env.getOrDefault("GITHUB_SHA", "unknown").substring(0,7)
def info = """\
name=${rootProject.name}
version=${version}
commitId=${commitId}
""".stripIndent().toString()
def f = file("src/main/resources/META-INF/build-info.properties")
f.parentFile.mkdirs()
f.text = info
}
}

compileJava {
dependsOn buildInfo
}
2 changes: 1 addition & 1 deletion app/conf/jni-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"name":"io.seqera.wavelit.app.App",
"name":"io.seqera.wavelit.App",
"methods":[{"name":"main","parameterTypes":["java.lang.String[]"] }]
},
{
Expand Down
14 changes: 10 additions & 4 deletions app/conf/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,29 @@
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.wavelit.app.App",
"name":"io.seqera.wavelit.App",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true
},
{
"name":"io.seqera.wavelit.app.json.ByteArrayAdapter",
"name":"io.seqera.wavelit.json.ByteArrayAdapter",
"queryAllDeclaredMethods":true
},
{
"name":"io.seqera.wavelit.app.json.DateTimeAdapter",
"name":"io.seqera.wavelit.json.DateTimeAdapter",
"queryAllDeclaredMethods":true,
"methods":[{"name":"deserializeInstant","parameterTypes":["java.lang.String"] }]
},
{
"name":"io.seqera.wavelit.app.json.PathAdapter",
"name":"io.seqera.wavelit.json.PathAdapter",
"queryAllDeclaredMethods":true
},
{
"name":"io.seqera.wavelit.util.CliVersionProvider",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"java.io.FilePermission"
},
Expand Down
3 changes: 3 additions & 0 deletions app/conf/resource-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"resources":{
"includes":[
{
"pattern":"\\QMETA-INF/build-info.properties\\E"
},
{
"pattern":"\\QMETA-INF/services/ch.qos.logback.classic.spi.Configurator\\E"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package io.seqera.wavelit.app;
package io.seqera.wavelit;

import java.io.IOException;
import java.net.URI;
Expand All @@ -24,37 +24,39 @@

import io.seqera.wave.api.SubmitContainerTokenRequest;
import io.seqera.wave.api.SubmitContainerTokenResponse;
import io.seqera.wavelit.app.exception.IllegalCliArgumentException;
import io.seqera.wavelit.exception.IllegalCliArgumentException;
import io.seqera.wavelit.util.CliVersionProvider;
import picocli.CommandLine;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static picocli.CommandLine.Command;
import static picocli.CommandLine.Option;

/**
* Wavelit entrypoint class
*/
@CommandLine.Command(name = "wavelit", description = "Wave command line tool", mixinStandardHelpOptions = true)
@Command(name = "wavelit", description = "Wave command line tool", mixinStandardHelpOptions = true, versionProvider = CliVersionProvider.class)
public class App implements Runnable {

@CommandLine.Option(names = {"-i", "--image"}, description = "Container image name to be provisioned")
@Option(names = {"-i", "--image"}, description = "Container image name to be provisioned")
private String image;

@CommandLine.Option(names = {"-c", "--containerfile"}, description = "Container file (i.e. Dockerfile) to be used to build the image")
@Option(names = {"-c", "--containerfile"}, description = "Container file (i.e. Dockerfile) to be used to build the image")
private String containerFile;

private String towerToken;

@CommandLine.Option(names = {"--tower-endpoint"}, description = "Tower service endpoint")
@Option(names = {"--tower-endpoint"}, description = "Tower service endpoint")
private String towerEndpoint;

private Long towerWorkspaceId;

@CommandLine.Option(names = {"--build-repo"}, description = "The container repository where image build by Wave will stored")
@Option(names = {"--build-repo"}, description = "The container repository where image build by Wave will stored")
private String buildRepository;

@CommandLine.Option(names = {"--cache-repo"}, description = "The container repository where image layer created by Wave will stored")
@Option(names = {"--cache-repo"}, description = "The container repository where image layer created by Wave will stored")
private String cacheRepository;


@CommandLine.Option(names = {"--wave-endpoint"}, description = "Wave service endpoint (default: ${DEFAULT-VALUE})")
@Option(names = {"--wave-endpoint"}, description = "Wave service endpoint (default: ${DEFAULT-VALUE})")
private String waveEndpoint = Client.DEFAULT_ENDPOINT;

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.wavelit.app;
package io.seqera.wavelit;

import java.io.IOException;
import java.net.URI;
Expand All @@ -27,8 +27,8 @@
import dev.failsafe.function.CheckedSupplier;
import io.seqera.wave.api.SubmitContainerTokenRequest;
import io.seqera.wave.api.SubmitContainerTokenResponse;
import io.seqera.wavelit.app.config.RetryOpts;
import io.seqera.wavelit.app.json.JsonHelper;
import io.seqera.wavelit.config.RetryOpts;
import io.seqera.wavelit.json.JsonHelper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.wavelit.app.config;
package io.seqera.wavelit.config;

import java.time.Duration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.wavelit.app.exception;
package io.seqera.wavelit.exception;

/**
* Exception thrown to report a CLI validation error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.wavelit.app.json;
package io.seqera.wavelit.json;

import java.util.Base64;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.wavelit.app.json;
package io.seqera.wavelit.json;

import java.time.Duration;
import java.time.Instant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.wavelit.app.json;
package io.seqera.wavelit.json;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.wavelit.app.json;
package io.seqera.wavelit.json;

import java.nio.file.Path;

Expand Down
51 changes: 51 additions & 0 deletions app/src/main/java/io/seqera/wavelit/util/BuildInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2023, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.wavelit.util;

import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
*/
public class BuildInfo {

private static final Logger log = LoggerFactory.getLogger(BuildInfo.class);

private static Properties properties;

static {
final String BUILD_INFO = "/META-INF/build-info.properties";
properties = new Properties();
try {
properties.load( BuildInfo.class.getResourceAsStream(BUILD_INFO) );
}
catch( Exception e ) {
log.warn("Unable to parse $BUILD_INFO - Cause: " + e.getMessage());
}
}

static Properties getProperties() { return properties; }

static public String getVersion() { return properties.getProperty("version"); }

static public String getCommitId() { return properties.getProperty("commitId"); }

static public String getName() { return properties.getProperty("name"); }

static public String getFullVersion() {
return getVersion() + "_" + getCommitId();
}

}
24 changes: 24 additions & 0 deletions app/src/main/java/io/seqera/wavelit/util/CliVersionProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2023, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.wavelit.util;

import picocli.CommandLine;

/**
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
*/
public class CliVersionProvider implements CommandLine.IVersionProvider {
@Override
public String[] getVersion() throws Exception {
return new String[] { BuildInfo.getVersion() };
}
}
3 changes: 3 additions & 0 deletions app/src/main/resources/META-INF/build-info.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name=wavelit
version=0.1.0
commitId=unknown
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.wavelit.app
package io.seqera.wavelit

import io.seqera.wave.api.SubmitContainerTokenRequest
import io.seqera.wavelit.app.json.JsonHelper
import io.seqera.wavelit.json.JsonHelper
import spock.lang.Specification;

/**
Expand Down
16 changes: 16 additions & 0 deletions app/src/test/groovy/io/seqera/wavelit/util/BuildInfoTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.seqera.wavelit.util

import spock.lang.Specification
/**
*
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
*/
class BuildInfoTest extends Specification {

def 'should load version and commit id' () {
expect:
BuildInfo.getName() == 'wavelit'
BuildInfo.getVersion()
BuildInfo.getCommitId()
}
}

0 comments on commit 947189c

Please sign in to comment.