Skip to content

Commit

Permalink
Change: Prepare IRI to have its version injected by CI (iotaledger#1359)
Browse files Browse the repository at this point in the history
* Parse version from jar manifest

* Parse version from pom when running directly from IDE

* update pom version

* add commit hash to version

* get correct version wiht travis

* delete unneccessary comment

*  change travis.yml to release properly

* add doc and delete unused imports
  • Loading branch information
GalRogozinski authored Mar 13, 2019
1 parent cb08095 commit d4f2a50
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 13 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ script:
- git checkout -f $TRAVIS_BRANCH
- git checkout $build_head
- git merge $TRAVIS_BRANCH
- mvn integration-test -Dlogging-level=INFO
#run jar sanity tests
- VERSION=$(mvn help:evaluate -Dexpression=project.version | grep -E '^[0-9.]+')
- VERSION=$(mvn git-commit-id:revision help:evaluate -Dexpression=project.version | grep -E '^[0-9.]+')
- VERSION=${VERSION/DEV*/RELEASE}
- echo $VERSION
- mvn versions:set -DnewVersion=$VERSION
#run jar sanity tests
- mvn integration-test -Dlogging-level=INFO
#jacoco prep (appends to mvn run)
- JACOCO_V=$(mvn help:evaluate -Dexpression=jacoco.version | grep -E '^[0-9.]+')
- export _JAVA_OPTIONS="$_JAVA_OPTIONS -javaagent:$HOME/.m2/repository/org/jacoco/org.jacoco.agent/$JACOCO_V/org.jacoco.agent-$JACOCO_V-runtime.jar=destfile=$PWD/target/jacoco.exec,output=file,append=true,dumponexit=true"
Expand Down Expand Up @@ -61,7 +63,7 @@ deploy:
api_key:
secure: "j+KolvRrsinh6OTqjli1y5I4gdPdD5MT6RFahVRrznxtcb2t7y6x41PknkI/8BksxLJKKQ1f40L307Aquzih9FmLesWcrYrCOS/B40dlCc3uV8DEZKhZF+QWqvsDpZ0EfiluGFljqGpxwngb/miNObqQzQvzpdUXBpZcuzxgqziynJD6jt3TYbNn544m/i4cWbb++b1h2Bm+jwELzJcf6/CZ1TxUh49vdM4S6yTpvnKwg4NLeH6g8s9oYEN1iwYtQokGKlH/emBZDsqDtF4KH7kXPpEKTcho4nH504XWJpanVAQ02Pha4SAnyVu4rKiLH4e6v99xZOBLVTH/qkvlwzvkNYr2xS5q9T9G7DZBRE+oc2MIbcnuSkhHwrUcmf2Hc0zCIP4RLCXAUuVlNEmIQUKgTezVzaqaEQLsa+EFIoosS+8pT/kVnaLbwxrITUmgM246+gvzMcVg8SmyPvVj6iRxfR6spTd7V2M0ePdqWlCL8P9RY4YrtxR2yJ6/3C0XNf29t+s/r1jat8fwWp8Gf7GiCaJEYG9VO24Chhi+MZCKBJnmx5G/98zvLw3f6a1FsEGZrw9RhF2vJKK6sD3rIvNkUsYmf0OhM7bf0NceFMGTJ/mFzM/JX0OHMtIyAvUfyyPVbQkIHNcGBgQMZasx07K3fjcn2lqv4FbHVi3HbdM="
file_glob: true
file: target/*.jar*
file: target/*RELEASE.jar*
skip_cleanup: true
before_deploy: openssl aes-256-cbc -K $encrypted_5a15fa813cca_key -iv $encrypted_5a15fa813cca_iv -in codesigning.asc.enc -out codesigning.asc -d && gpg --fast-import codesigning.asc
deploy: mvn package -P build-extras -Dlogging-level=INFO
Expand Down
6 changes: 3 additions & 3 deletions DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

Run the official iotaledger/iri container, passing the mandatory -p option:

```docker run iotaledger/iri:v1.6.1-RELEASE -p 14265```
```docker run iotaledger/iri:vX.X.X-RELEASE -p 14265```

This will get your a running IRI with its API listening on port 14265, no neighbours and an empty database. The IRI Docker container by default expects data at /iri/data. Use the `-v` option of the `docker run` command to mount volumes so to have persistent data. You can also pass more command line options to the docker run command and those will be passed to IRI.

If you want to use a iri.ini file with the docker container, supposing it's stored under /path/to/conf/iri.ini on your docker host, then pass `-v /path/to/conf:/iri/conf` and add -c /iri/conf/iri.ini as docker run arguments. So for example the `docker run` command above would become:

```docker run -v /path/to/conf:/iri/conf -v /path/to/data:/iri/data iotaledger/iri:v1.6.1-RELEASE -p 14265 -c /iri/conf/iri.ini```
```docker run -v /path/to/conf:/iri/conf -v /path/to/data:/iri/data iotaledger/iri:vX.X.X-RELEASE -p 14265 -c /iri/conf/iri.ini```

Please refer to the IRI documentation for further command line options and iri.ini options.

Expand Down Expand Up @@ -61,7 +61,7 @@ ExecStart=/usr/bin/docker run \
-p 14265:14265 \
-p 15600:15600 \
-p 14600:14600/udp \
iotaledger/iri:v1.6.1-RELEASE \
iotaledger/iri:vX.X.X-RELEASE \
-p 14265 \
--zmq-enabled \
--testnet
Expand Down
33 changes: 32 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.iota</groupId>
<artifactId>iri</artifactId>
<version>1.6.1-RELEASE</version>
<version>1.6.1-DEV-${version.number}</version>
<name>IRI</name>
<description>IOTA Reference Implementation</description>

Expand All @@ -22,6 +22,7 @@
<checkstyle-version>3.0.0</checkstyle-version>
<undertow.version>1.4.26.Final</undertow.version>
<jacoco.version>0.7.9</jacoco.version>
<version.number>${git.commit.id.abbrev}</version.number>
<!-- Setting the checkstyle.config.location here will make checkstyle use this file in every maven target.
This variable will be load by checkstyle plugin automatically. It is more global than setting the
configLocation attribute on every maven goal. -->
Expand Down Expand Up @@ -218,6 +219,36 @@
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<generateGitPropertiesFile>false</generateGitPropertiesFile><!-- somehow necessary. otherwise the variables are not available in the pom -->
</configuration>
</plugin>
<!-- Controls how jar is being created -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<!-- The javadoc plugin can be called by running "mvn javadoc:javadoc" and will generate the classic javadoc
files in folder "target/site/apidocs" -->
<plugin>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/iota/iri/IRI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.iota.iri.conf.ConfigFactory;
import com.iota.iri.conf.IotaConfig;
import com.iota.iri.service.API;
import com.iota.iri.utils.IotaUtils;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -42,7 +43,6 @@ public class IRI {

public static final String MAINNET_NAME = "IRI";
public static final String TESTNET_NAME = "IRI Testnet";
public static final String VERSION = "1.6.1-RELEASE";

/**
* The entry point of IRI.
Expand Down Expand Up @@ -114,7 +114,8 @@ private static class IRILauncher {
*/
public static void main(String [] args) throws Exception {
IotaConfig config = createConfiguration(args);
log.info("Welcome to {} {}", config.isTestnet() ? TESTNET_NAME : MAINNET_NAME, VERSION);
String version = IotaUtils.getIriVersion();
log.info("Welcome to {} {}", config.isTestnet() ? TESTNET_NAME : MAINNET_NAME, version);

iota = new Iota(config);
ixi = new IXI(iota);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/iota/iri/conf/BaseIotaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public JCommander parseConfigFromArgs(String[] args) throws ParameterException {
.acceptUnknownOptions(true)
.allowParameterOverwriting(true)
//This is the first line of JCommander Usage
.programName("java -jar iri-" + IRI.VERSION + ".jar")
.programName("java -jar iri-" + IotaUtils.getIriVersion() + ".jar")
.build();
if (ArrayUtils.isNotEmpty(args)) {
jCommander.parse(args);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/iota/iri/service/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.iota.iri.service.tipselection.impl.WalkValidatorImpl;
import com.iota.iri.utils.Converter;
import com.iota.iri.utils.IotaIOUtils;
import com.iota.iri.utils.IotaUtils;
import com.iota.iri.utils.MapIdentityManager;
import io.undertow.Undertow;
import io.undertow.security.api.AuthenticationMechanism;
Expand Down Expand Up @@ -884,8 +885,8 @@ private AbstractResponse getNodeInfoStatement() throws Exception{
MilestoneViewModel milestone = MilestoneViewModel.first(instance.tangle);

return GetNodeInfoResponse.create(
name,
IRI.VERSION,
name,
IotaUtils.getIriVersion(),
Runtime.getRuntime().availableProcessors(),
Runtime.getRuntime().freeMemory(),
System.getProperty("java.version"),
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/iota/iri/utils/IotaUtils.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.iota.iri.utils;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.iota.iri.IRI;
import com.iota.iri.model.Hash;

import java.io.FileReader;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.util.ArrayList;
Expand All @@ -17,6 +23,29 @@

public class IotaUtils {

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

/**
* Returns the current version IRI is running by reading the Jar manifest.
* If we run not from a jar or the manifest is missing we read straight from the pom
*
* @return the implementation version of IRI
*/
public static String getIriVersion() {
String implementationVersion = IRI.class.getPackage().getImplementationVersion();
//If not in manifest (can happen when running from IDE)
if (implementationVersion == null) {
MavenXpp3Reader reader = new MavenXpp3Reader();
try {
Model model = reader.read(new FileReader("pom.xml"));
implementationVersion = model.getVersion();
} catch (Exception e) {
log.error("Failed to parse version from pom", e);
}
}
return implementationVersion;
}

public static List<String> splitStringToImmutableList(String string, String regexSplit) {
return Arrays.stream(string.split(regexSplit))
.filter(StringUtils::isNoneBlank)
Expand Down

0 comments on commit d4f2a50

Please sign in to comment.