Skip to content

Commit

Permalink
Merge pull request #26 from KPMP/develop
Browse files Browse the repository at this point in the history
Release v1.3
  • Loading branch information
rlreamy authored Mar 26, 2024
2 parents 78252c5 + e1ec1ec commit d58ef65
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 60 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.*
*.iml
gradle
src
build/*
!build/docker
53 changes: 53 additions & 0 deletions .github/workflows/build-gradle-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build hydra-data docker image

on:
push:

jobs:
build-gradle-project:
env:
IMAGE_TAG: 1.3
runs-on: ubuntu-latest
steps:
- name: Get branch names
id: branch-names
uses: tj-actions/branch-names@v8

- name: Get current branch name
if: steps.branch-names.outputs.is_default == 'false'
run: |
echo "Running on branch: ${{ steps.branch-names.outputs.current_branch }}"
- name: Checkout project sources
uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'oracle'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: 8.5

- name: Login to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.ENV_DOCKER_USER }}
password: ${{ secrets.ENV_DOCKER_PASS }}

- name: Run build with Gradle Wrapper
run: |
./gradlew build docker
- name: Push to Docker Hub if branch is develop
if: steps.branch-names.outputs.current_branch == 'develop'
run: |
docker push "kingstonduo/hydra-data:$IMAGE_TAG"
- name: Push to Docker Hub if branch is not develop
if: ${{ !steps.branch-names.outputs.current_branch == 'develop' }}
run: |
docker push "kingstonduo/hydra-data:${{ steps.branch-names.outputs.current_branch }}"
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM alpine
FROM alpine:3.19.1

RUN apk update && \
apk upgrade
RUN apk add openjdk8
RUN apk add openjdk21

VOLUME /tmp
ARG DEPENDENCY=target/dependency
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ If you have having troubles seeing changes during development, you can try to cl
# Build

`./gradlew build docker`
The default tag is the github branch if no verison is provided
To pass a version when building the docker image execute
`./gradlew build docker -Ptag=<tagNumber>`

# Restart Spring

Expand Down Expand Up @@ -41,3 +44,6 @@ If you have having troubles seeing changes during development, you can try to cl
4. SSH to the appropriate KE machine
5. Execute:
`curl -X GET http://localhost:3050/api/v1/repository/load-search`

# Pushing images to Docker
This repository is equipped to build and push an image to docker hub when pushing to the repository (except for master and develop). The image will be named `kingstonduo/hydra-data:<git-branch-name>`
64 changes: 43 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,48 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.3")
classpath("org.springframework.boot:spring-boot-gradle-plugin:3.2.2")
}
}

plugins {
id 'com.palantir.docker' version '0.22.1'
id 'com.palantir.docker' version '0.35.0'
id 'org.springframework.boot' version '3.2.2'
}

group='kingstonduo'
version='1.3'

group = 'kingstonduo'

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

jar {
baseName='hydra-data'
version= '1.0.0'
}


repositories {
mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web:2.6.3'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.6.3'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.3'
testImplementation 'org.springframework:spring-test:5.0.5.RELEASE'
implementation 'commons-io:commons-io:2.6'
implementation 'mysql:mysql-connector-java:8.0.15'
implementation 'org.apache.commons:commons-compress:1.17'
implementation 'org.apache.commons:commons-text:1.7'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.mysql:mysql-connector-j:8.3.0'

implementation 'com.graphql-java:graphql-spring-boot-starter:5.0.2'
implementation 'com.graphql-java:graphiql-spring-boot-starter:5.0.2'
implementation 'com.google.api-client:google-api-client:2.2.0'
implementation 'com.graphql-java:graphql-java-tools:5.2.4'
testImplementation 'org.mockito:mockito-core'
implementation 'org.springframework.boot:spring-boot-starter-cache:2.6.3'

testImplementation('org.mockito:mockito-junit-jupiter:3.12.4')
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework:spring-test:5.2.25.RELEASE'
testImplementation 'org.mockito:mockito-core'
}

springBoot {
Expand All @@ -59,8 +57,32 @@ task unpack(type: Copy) {
into("build/dependency")
}

def getCurrentGitBranch() {
if (project.hasProperty('tag')) {
def tagValue = project.property('tag')
return tagValue
} else {
def gitBranch = "Unknown branch"
try {
def workingDir = new File("${project.projectDir}")
def result = 'git rev-parse --abbrev-ref HEAD'.execute(null, workingDir)
result.waitFor()
if (result.exitValue() == 0) {
gitBranch = result.text.trim()
}
} catch (e) {
}
if (gitBranch == "develop" || gitBranch == "master"){
return project.version
}else{
return gitBranch
}
}
}


docker {
name "${project.group}/${jar.baseName}:latest"
name "kingstonduo/hydra-data:" + getCurrentGitBranch()
copySpec.from(tasks.unpack.outputs).into("dependency")
buildArgs(['DEPENDENCY': "dependency"])
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 1 addition & 3 deletions src/main/java/org/kpmp/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class Query implements GraphQLQueryResolver {
private RepositoryDatasetService repositoryDatasetService;

@Autowired
public Query(
RepositoryDatasetService repositoryDatasetService
) {
public Query(RepositoryDatasetService repositoryDatasetService) {
this.repositoryDatasetService = repositoryDatasetService;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/kpmp/WebConfig.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package org.kpmp;

import org.kpmp.repositoryDataset.RepositoryDatasetDisplay;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;


@Configuration
@EnableAutoConfiguration
@RegisterReflectionForBinding({RepositoryDatasetDisplay.class})
public class WebConfig implements WebMvcConfigurer {
@Bean
public RestTemplate restTemplate() {
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/kpmp/file/File.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.kpmp.file;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import jakarta.persistence.*;

@Entity
@Table(name = "file")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class RepositoryDatasetController {
Expand All @@ -18,8 +17,7 @@ public RepositoryDatasetController(RepositoryDatasetService repositoryDatasetSer
}

@RequestMapping(value = "/api/v1/repository/load-search", method = RequestMethod.GET)
public @ResponseBody String loadSearch(HttpServletRequest request) throws Exception {
public @ResponseBody String loadSearch() throws Exception {
return "Successfully added " + repositoryDatasetService.loadEnterpriseSearch().size() + " documents.";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.util.HashSet;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonProperty;

public class RepositoryDatasetDisplay {
private static final int UUID_LENGTH = 37;
private String dlFileId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,35 @@
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;
@Service

@Component
public class RepositoryDatasetService {

@Value("${enterprise-search.host}")
private String enterpriseSearchHost;
@Value("${enterprise-search.engine.name}")
private String enterpriseSearchEngineName;
private RepositoryFileDatasetRepository fileRepo;
@Value("${recently-released-date}")
private String recentlyReleasedDate;

private RestTemplate restTemplate;
private Environment env;

public static class ESResponse {
String id;
List errors;
List<String> errors;

public String getId() {
return id;
Expand All @@ -38,22 +44,17 @@ public void setId(String id) {
this.id = id;
}

public List getErrors() {
public List<String> getErrors() {
return errors;
}

public void setErrors(List errors) {
public void setErrors(List<String> errors) {
this.errors = errors;
}
}

public RepositoryDatasetService() {
// So spring doesn't yell at us
}

@Autowired
public RepositoryDatasetService(
RepositoryFileDatasetRepository fileRepo, RestTemplate restTemplate, Environment env) {
public RepositoryDatasetService(RepositoryFileDatasetRepository fileRepo, RestTemplate restTemplate, Environment env) {
this.fileRepo = fileRepo;
this.restTemplate = restTemplate;
this.env = env;
Expand Down Expand Up @@ -83,7 +84,7 @@ public List<RepositoryDatasetDisplay> getRepositoryDataset() throws Exception {
RepositoryDatasetDisplay displayFile = new RepositoryDatasetDisplay(repositoryDataset);

if (Double.compare(repositoryDataset.getReleaseVersion(), maxReleaseVersion) == 0) {
displayFile.setReleaseVersion("Recently Released");
displayFile.setReleaseVersion("Recently Released - " + recentlyReleasedDate);
} else {
displayFile.setReleaseVersion(null);
}
Expand All @@ -99,27 +100,37 @@ public List<RepositoryFileDataset> getRepositoryFileDataset() throws IOException
}

public List<ESResponse> loadEnterpriseSearch() throws Exception {

List<ESResponse> responses = new ArrayList<>();
List<RepositoryDatasetDisplay> datasets = getRepositoryDataset();
String token = env.getProperty("ES_API_TOKEN");
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer "+ token);
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Access-Control-Allow-Origin", "*");
int chunks = (int) Math.ceil((double) datasets.size() / 100.00);
for (int i = 0; i < chunks; i++) {
int beginIndex = i * 100;
int endIndex;
if (i == chunks - 1)
if (i == chunks - 1) {
endIndex = datasets.size();
else
}
else {
endIndex = (i * 100) + 100;
}
List<RepositoryDatasetDisplay> datasetSlice = datasets.subList(beginIndex, endIndex);
HttpEntity<Object> entity = new HttpEntity<>(datasetSlice, headers);
ESResponse[] response = restTemplate.postForObject(enterpriseSearchHost + "/api/as/v1/engines/" + enterpriseSearchEngineName + "/documents",
entity, ESResponse[].class);
ObjectMapper objectMapper = new ObjectMapper();
String jsonArray = objectMapper.writeValueAsString(datasetSlice);

HttpEntity<Object> entity = new HttpEntity<>(jsonArray, headers);
String uri = enterpriseSearchHost + "/api/as/v1/engines/" + enterpriseSearchEngineName + "/documents";
ESResponse[] response = restTemplate.postForObject(uri, entity, ESResponse[].class);
Collections.addAll(responses, response);
}
return responses;
}




}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.kpmp.repositoryDataset;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
import jakarta.persistence.*;
import org.springframework.lang.Nullable;

@Entity
Expand Down
Loading

0 comments on commit d58ef65

Please sign in to comment.