mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Use environment for git sha url
This commit is contained in:
2
Makefile
2
Makefile
@@ -9,6 +9,7 @@ IMGFLOAT_GITHUB_CLIENT_REPO ?= client
|
|||||||
IMGFLOAT_GITHUB_CLIENT_VERSION ?= 1.0.0
|
IMGFLOAT_GITHUB_CLIENT_VERSION ?= 1.0.0
|
||||||
IMGFLOAT_ASSETS_PATH ?= ./assets
|
IMGFLOAT_ASSETS_PATH ?= ./assets
|
||||||
IMGFLOAT_PREVIEWS_PATH ?= ./previews
|
IMGFLOAT_PREVIEWS_PATH ?= ./previews
|
||||||
|
IMGFLOAT_COMMIT_URL_PREFIX ?= https://github.com/imgfloat/server/commit/
|
||||||
SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE ?= 10MB
|
SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE ?= 10MB
|
||||||
SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE ?= 10MB
|
SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE ?= 10MB
|
||||||
WATCHDIR = ./src/main
|
WATCHDIR = ./src/main
|
||||||
@@ -17,6 +18,7 @@ RUNTIME_ENV = IMGFLOAT_ASSETS_PATH=$(IMGFLOAT_ASSETS_PATH) \
|
|||||||
IMGFLOAT_GITHUB_CLIENT_OWNER=$(IMGFLOAT_GITHUB_CLIENT_OWNER) \
|
IMGFLOAT_GITHUB_CLIENT_OWNER=$(IMGFLOAT_GITHUB_CLIENT_OWNER) \
|
||||||
IMGFLOAT_GITHUB_CLIENT_REPO=$(IMGFLOAT_GITHUB_CLIENT_REPO) \
|
IMGFLOAT_GITHUB_CLIENT_REPO=$(IMGFLOAT_GITHUB_CLIENT_REPO) \
|
||||||
IMGFLOAT_GITHUB_CLIENT_VERSION=$(IMGFLOAT_GITHUB_CLIENT_VERSION) \
|
IMGFLOAT_GITHUB_CLIENT_VERSION=$(IMGFLOAT_GITHUB_CLIENT_VERSION) \
|
||||||
|
IMGFLOAT_COMMIT_URL_PREFIX=$(IMGFLOAT_COMMIT_URL_PREFIX) \
|
||||||
IMGFLOAT_DB_PATH=$(IMGFLOAT_DB_PATH) \
|
IMGFLOAT_DB_PATH=$(IMGFLOAT_DB_PATH) \
|
||||||
SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE=$(SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE) \
|
SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE=$(SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE) \
|
||||||
SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE=$(SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE)
|
SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE=$(SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE)
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ Optional:
|
|||||||
|
|
||||||
| Variable | Description | Example Value |
|
| Variable | Description | Example Value |
|
||||||
|----------|-------------|---------------|
|
|----------|-------------|---------------|
|
||||||
|
| `IMGFLOAT_COMMIT_URL_PREFIX` | Git commit URL prefix used for the build link badge (unset to hide the badge) | https://github.com/imgfloat/server/commit/ |
|
||||||
| `TWITCH_REDIRECT_URI` | Override default redirect URI | http://localhost:8080/login/oauth2/code/twitch |
|
| `TWITCH_REDIRECT_URI` | Override default redirect URI | http://localhost:8080/login/oauth2/code/twitch |
|
||||||
|
|
||||||
During development environment variables can be placed in the `.env` file at the project root to automatically load them. Be aware that these are only loaded when using the [Makefile](./Makefile) command `make run`.
|
During development environment variables can be placed in the `.env` file at the project root to automatically load them. Be aware that these are only loaded when using the [Makefile](./Makefile) command `make run`.
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ public class ViewController {
|
|||||||
model.addAttribute("version", versionService.getVersion());
|
model.addAttribute("version", versionService.getVersion());
|
||||||
model.addAttribute("releaseVersion", githubReleaseService.getClientReleaseVersion());
|
model.addAttribute("releaseVersion", githubReleaseService.getClientReleaseVersion());
|
||||||
model.addAttribute("downloadBaseUrl", githubReleaseService.getDownloadBaseUrl());
|
model.addAttribute("downloadBaseUrl", githubReleaseService.getDownloadBaseUrl());
|
||||||
|
model.addAttribute("showCommitChip", gitInfoService.shouldShowCommitChip());
|
||||||
model.addAttribute("buildCommitShort", gitInfoService.getShortCommitSha());
|
model.addAttribute("buildCommitShort", gitInfoService.getShortCommitSha());
|
||||||
model.addAttribute("buildCommitUrl", gitInfoService.getCommitUrl());
|
model.addAttribute("buildCommitUrl", gitInfoService.getCommitUrl());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,19 +7,21 @@ import java.io.InputStreamReader;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class GitInfoService {
|
public class GitInfoService {
|
||||||
|
|
||||||
private static final String FALLBACK_GIT_SHA = "unknown";
|
private static final String FALLBACK_GIT_SHA = "unknown";
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(GitInfoService.class);
|
private static final Logger LOG = LoggerFactory.getLogger(GitInfoService.class);
|
||||||
private static final String COMMIT_URL_PREFIX = "https://github.com/Kruhlmann/imgfloat-j/commit/";
|
|
||||||
|
|
||||||
private final String commitSha;
|
private final String commitSha;
|
||||||
private final String shortCommitSha;
|
private final String shortCommitSha;
|
||||||
|
private final String commitUrlPrefix;
|
||||||
|
|
||||||
public GitInfoService() {
|
public GitInfoService(@Value("${IMGFLOAT_COMMIT_URL_PREFIX:}") String commitUrlPrefix) {
|
||||||
CommitInfo commitInfo = resolveFromGitProperties();
|
CommitInfo commitInfo = resolveFromGitProperties();
|
||||||
if (commitInfo == null) {
|
if (commitInfo == null) {
|
||||||
commitInfo = resolveFromGitBinary();
|
commitInfo = resolveFromGitBinary();
|
||||||
@@ -36,6 +38,7 @@ public class GitInfoService {
|
|||||||
|
|
||||||
this.commitSha = defaultValue(full);
|
this.commitSha = defaultValue(full);
|
||||||
this.shortCommitSha = defaultValue(abbreviated);
|
this.shortCommitSha = defaultValue(abbreviated);
|
||||||
|
this.commitUrlPrefix = normalize(commitUrlPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCommitSha() {
|
public String getCommitSha() {
|
||||||
@@ -47,10 +50,17 @@ public class GitInfoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getCommitUrl() {
|
public String getCommitUrl() {
|
||||||
if (commitSha == null || commitSha.isBlank() || FALLBACK_GIT_SHA.equalsIgnoreCase(commitSha)) {
|
if (!shouldShowCommitChip()
|
||||||
|
|| commitSha == null
|
||||||
|
|| commitSha.isBlank()
|
||||||
|
|| FALLBACK_GIT_SHA.equalsIgnoreCase(commitSha)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return COMMIT_URL_PREFIX + commitSha;
|
return commitUrlPrefix + commitSha;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldShowCommitChip() {
|
||||||
|
return StringUtils.hasText(commitUrlPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommitInfo resolveFromGitProperties() {
|
private CommitInfo resolveFromGitProperties() {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
<span class="muted">Version</span>
|
<span class="muted">Version</span>
|
||||||
<span class="version-badge" th:text="${version}">unknown</span>
|
<span class="version-badge" th:text="${version}">unknown</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="build-chip">
|
<div class="build-chip" th:if="${showCommitChip}">
|
||||||
<span class="muted">Build</span>
|
<span class="muted">Build</span>
|
||||||
<a
|
<a
|
||||||
class="version-badge version-link"
|
class="version-badge version-link"
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
<span class="muted">Version</span>
|
<span class="muted">Version</span>
|
||||||
<span class="version-badge" th:text="${version}">unknown</span>
|
<span class="version-badge" th:text="${version}">unknown</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="build-chip">
|
<div class="build-chip" th:if="${showCommitChip}">
|
||||||
<span class="muted">Build</span>
|
<span class="muted">Build</span>
|
||||||
<a
|
<a
|
||||||
class="version-badge version-link"
|
class="version-badge version-link"
|
||||||
|
|||||||
Reference in New Issue
Block a user