mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-03 12:16:10 +00:00
feat(git-version): Encode the latest release included in the build (#3535)
This commit is contained in:
parent
0079101740
commit
e01be7bb3d
13
build.gradle
13
build.gradle
@ -13,6 +13,10 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gorylenko.gradle-git-properties' version '2.3.1'
|
||||
}
|
||||
|
||||
project.ext.spec = [
|
||||
'product' : [
|
||||
'pegasus' : [
|
||||
@ -138,12 +142,21 @@ allprojects {
|
||||
|
||||
subprojects {
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'com.gorylenko.gradle-git-properties'
|
||||
|
||||
configurations.all {
|
||||
exclude group: "io.netty", module: "netty"
|
||||
exclude group: "log4j", module: "log4j"
|
||||
}
|
||||
|
||||
gitProperties {
|
||||
keys = ['git.commit.id','git.commit.id.describe','git.commit.time']
|
||||
// using any tags (not limited to annotated tags) for "git.commit.id.describe" property
|
||||
// see http://ajoberstar.org/grgit/grgit-describe.html for more info about the describe method and available parameters
|
||||
// 'it' is an instance of org.ajoberstar.grgit.Grgit
|
||||
customProperty 'git.commit.id.describe', { it.describe(tags: true) }
|
||||
}
|
||||
|
||||
plugins.withType(JavaPlugin) {
|
||||
dependencies {
|
||||
testCompile externalDependency.testng
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
package com.linkedin.metadata.version;
|
||||
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nonnull;
|
||||
import lombok.Value;
|
||||
|
||||
|
||||
@Value
|
||||
public class GitVersion {
|
||||
String version;
|
||||
String commitId;
|
||||
Optional<String> flag;
|
||||
|
||||
public static GitVersion getVersion(@Nonnull String commitId, @Nonnull String commitDescribe) {
|
||||
String version = commitDescribe.split("-")[0];
|
||||
return new GitVersion(version, commitId, Optional.empty());
|
||||
}
|
||||
}
|
||||
@ -1,20 +1,31 @@
|
||||
package com.linkedin.metadata.kafka;
|
||||
|
||||
import com.linkedin.gms.factory.common.GitVersionFactory;
|
||||
import com.linkedin.metadata.version.GitVersion;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
public class MaeConsumerConfig {
|
||||
Map<String, String> config = new HashMap<String, String>() {{
|
||||
put("noCode", "true");
|
||||
}};
|
||||
|
||||
@GetMapping("/config")
|
||||
@ResponseBody
|
||||
public Map<String, String> sayHello() {
|
||||
return config;
|
||||
}
|
||||
@Controller
|
||||
@Import(GitVersionFactory.class)
|
||||
public class MaeConsumerConfig {
|
||||
private final Map<String, String> config;
|
||||
|
||||
public MaeConsumerConfig(GitVersion gitVersion) {
|
||||
config = new HashMap<>();
|
||||
config.put("noCode", "true");
|
||||
|
||||
config.put("version", gitVersion.getVersion());
|
||||
config.put("commit", gitVersion.getCommitId());
|
||||
}
|
||||
|
||||
@GetMapping("/config")
|
||||
@ResponseBody
|
||||
public Map<String, String> getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package com.linkedin.metadata.kafka;
|
||||
|
||||
import com.linkedin.gms.factory.common.GitVersionFactory;
|
||||
import com.linkedin.metadata.version.GitVersion;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
|
||||
@Controller
|
||||
@Import(GitVersionFactory.class)
|
||||
public class MceConsumerConfig {
|
||||
private final Map<String, String> config;
|
||||
|
||||
public MceConsumerConfig(GitVersion gitVersion) {
|
||||
config = new HashMap<>();
|
||||
config.put("noCode", "true");
|
||||
|
||||
config.put("version", gitVersion.getVersion());
|
||||
config.put("commit", gitVersion.getCommitId());
|
||||
}
|
||||
|
||||
@GetMapping("/config")
|
||||
@ResponseBody
|
||||
public Map<String, String> getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package com.linkedin.gms.factory.common;
|
||||
|
||||
import com.linkedin.metadata.version.GitVersion;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:git.properties")
|
||||
public class GitVersionFactory {
|
||||
@Value("${git.commit.id}")
|
||||
private String commitId;
|
||||
|
||||
@Value("${git.commit.id.describe}")
|
||||
private String commitDescribe;
|
||||
|
||||
@Nonnull
|
||||
@Bean(name = "gitVersion")
|
||||
protected GitVersion getInstance() {
|
||||
return GitVersion.getVersion(commitId, commitDescribe);
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,11 @@
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile project(':metadata-io')
|
||||
compile externalDependency.httpClient
|
||||
compile externalDependency.servletApi
|
||||
compile externalDependency.gson
|
||||
compile externalDependency.jacksonDataBind
|
||||
compile externalDependency.springWebMVC
|
||||
annotationProcessor externalDependency.lombok
|
||||
}
|
||||
|
||||
@ -2,25 +2,37 @@ package com.datahub.gms.servlet;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.linkedin.metadata.version.GitVersion;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
|
||||
// Return a 200 for health checks
|
||||
public class Config extends HttpServlet {
|
||||
Map<String, String> config = new HashMap<String, String>() {{
|
||||
put("noCode", "true");
|
||||
}};
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private GitVersion getGitVersion(ServletContext servletContext) {
|
||||
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
|
||||
return (GitVersion) ctx.getBean("gitVersion");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
Map<String, String> config = new HashMap<>();
|
||||
config.put("noCode", "true");
|
||||
|
||||
GitVersion version = getGitVersion(req.getServletContext());
|
||||
config.put("version", version.getVersion());
|
||||
config.put("commit", version.getCommitId());
|
||||
|
||||
resp.setContentType("application/json");
|
||||
PrintWriter out = resp.getWriter();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user