Skip to content

Commit

Permalink
Changes to provide commit hash and version in docker solarthing
Browse files Browse the repository at this point in the history
  • Loading branch information
retrodaredevil committed Jul 12, 2023
1 parent 291c29c commit 0b5dc50
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ jobs:
file: docker/${{ matrix.data.image-name }}/Dockerfile
build-args: |
JAR_LOCATION=${{ matrix.data.jar-location }}
COMMIT_HASH=${{ github.sha }}
VERSION=${{ github.ref#refs/(tags|heads)/v? }}
push: true
platforms: ${{ env.platforms }}
tags: ${{ steps.meta.outputs.tags }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
abstract class PacketHandlingOptionBase extends TimeZoneOptionBase implements PacketHandlingOption, ActionsOption, CommandOption, AnalyticsOption {
private static final Logger LOGGER = LoggerFactory.getLogger(PacketHandlingOptionBase.class);

@JsonProperty
@JsonProperty("databases")
@JsonPropertyDescription("An array of strings that each represent a database configuration file relative to the program directory.")
private List<Path> databases = null;
@JsonProperty("database_config")
Expand All @@ -31,7 +31,7 @@ abstract class PacketHandlingOptionBase extends TimeZoneOptionBase implements Pa
private String source = "default";
@JsonProperty(value = "fragment", required = true)
private int fragment;
@JsonProperty
@JsonProperty("unique")
private Integer unique = null;
@JsonProperty("short")
private boolean isShortId = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static String getJarInfo() {

public static int doMainCommand(CommandOptions commandOptions, Path baseConfigFile) {
String user = System.getProperty("user.name");
if (!user.equals("solarthing")) {
if (!"solarthing".equals(user) && !SolarThingEnvironment.isRunningInDocker()) {
if (user.equals("root")) {
LOGGER.warn("Running as root user!");
System.out.println("\n\nHey! We noticed you are running as root! Instead of\n sudo ./run.sh\nPlease do\n sudo -u solarthing ./run.sh\n instead.\n");
Expand Down Expand Up @@ -235,9 +235,13 @@ private static int doMain(String[] args){
private static int outputVersion() {
JarUtil.Data data = JarUtil.getData();
Instant lastModified = data.getLastModifiedInstantOrNull();
String commitHash = SolarThingEnvironment.getGitCommitHash();
String version = SolarThingEnvironment.getVersion();
System.out.println("SolarThing made by Lavender Shannon\n" +
"Jar: " + data.getJarFileNameOrNull() + "\n" +
"Jar last modified: " + (lastModified == null ? "unknown" : lastModified.toString()) + "\n" +
(commitHash == null ? "" : "Commit hash: " + commitHash) +
(version == null ? "" : "Version: " + version) +
"Java version: " + System.getProperty("java.version"));
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package me.retrodaredevil.solarthing.program;

import me.retrodaredevil.solarthing.annotations.Nullable;
import me.retrodaredevil.solarthing.annotations.UtilityClass;

@UtilityClass
public final class SolarThingEnvironment {
private SolarThingEnvironment() { throw new UnsupportedOperationException(); }

public static boolean isRunningInDocker() {
return System.getenv("DOCKER") != null;
}
public static @Nullable String getGitCommitHash() {
return emptyToNull(System.getenv("COMMIT_HASH"));
}
public static @Nullable String getVersion() {
return emptyToNull(System.getenv("VERSION"));
}
private static String emptyToNull(String s) {
if (s.isEmpty()) {
return null;
}
return s;
}
}
5 changes: 5 additions & 0 deletions docker/solarthing/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
FROM eclipse-temurin:19-jre-jammy
ARG JAR_LOCATION
ARG COMMIT_HASH=""
ARG VERSION=""

RUN ["mkdir", "/app"]
WORKDIR "/app"
COPY --chmod=0444 ${JAR_LOCATION} solarthing.jar
ENV DOCKER=""
ENV COMMIT_HASH="$COMMIT_HASH"
ENV VERSION="$VERSION"

# Currently this entry point does not need any allow opens.
# The default raw_solarthing will run solarthing.jar with `--add-opens=java.base/java.lang.invoke=ALL-UNNAMED`
Expand Down

0 comments on commit 0b5dc50

Please sign in to comment.