-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from ts4nfdi/feature/add-ontoportal-api-key-en…
…v-var Feature: Add OntoPortal APIKEY env variable
- Loading branch information
Showing
5 changed files
with
131 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,93 @@ | ||
name: Continuous Integration | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
tags: [ "*" ] | ||
branches: | ||
- "main" | ||
tags: | ||
- "*" | ||
|
||
env: | ||
KUBECONFIG: .kube/config | ||
KUBECONFIG_FILE: ${{ secrets.KUBECONFIG }} | ||
|
||
jobs: | ||
build: | ||
name: "Build Image" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- id: generate-image-tag | ||
name: Generate Image Tag | ||
env: | ||
ref_name: "${{ github.ref_name }}" | ||
head_ref: "${{ github.head_ref }}" | ||
run: | | ||
head_ref="${head_ref/\//-}" | ||
ref_name="${head_ref:-${ref_name/main/latest}}" | ||
echo "::set-output name=imageTag::${ref_name#v}" | ||
head_ref="${GITHUB_HEAD_REF//\//-}" | ||
ref_name="${head_ref:-${GITHUB_REF_NAME/main/latest}}" | ||
echo "imageTag=${ref_name#v}" >> $GITHUB_ENV | ||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up JDK | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'temurin' | ||
distribution: 'temurin' | ||
java-version: '11' | ||
|
||
- name: Build with Maven | ||
run: mvn clean install | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: ./ | ||
file: ./Dockerfile | ||
push: true | ||
tags: | | ||
ghcr.io/${{ github.repository }}:${{ steps.generate-image-tag.outputs.imageTag }} | ||
ghcr.io/${{ github.repository }}:${{ env.imageTag }} | ||
ghcr.io/${{ github.repository }}:${{ github.event.pull_request.head.sha || github.sha }} | ||
deploy_main: | ||
needs: build | ||
if: github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
steps: | ||
needs: build | ||
if: github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- id: generate-image-tag | ||
name: Generate Image Tag | ||
env: | ||
ref_name: "${{ github.ref_name }}" | ||
head_ref: "${{ github.head_ref }}" | ||
run: | | ||
head_ref="${head_ref/\//-}" | ||
ref_name="${head_ref:-${ref_name/main/latest}}" | ||
echo "::set-output name=imageTag::${ref_name#v}" | ||
head_ref="${GITHUB_HEAD_REF//\//-}" | ||
ref_name="${head_ref:-${GITHUB_REF_NAME/main/latest}}" | ||
echo "imageTag=${ref_name#v}" >> $GITHUB_ENV | ||
- uses: actions/checkout@v2 | ||
- run: | | ||
|
||
- name: Set up Kubernetes config | ||
run: | | ||
mkdir -p .kube | ||
echo "${{ env.KUBECONFIG_FILE }}" > $KUBECONFIG | ||
- uses: stefanprodan/kube-tools@v1 | ||
echo "${{ secrets.KUBECONFIG }}" > $KUBECONFIG | ||
- name: Create Kubernetes secret for ONTOPORTAL_APIKEY | ||
run: | | ||
kubectl create secret generic ontoportal-secret \ | ||
--from-literal=ONTOPORTAL_APIKEY=${{ secrets.ONTOPORTAL_APIKEY }} \ | ||
--dry-run=client -o yaml | kubectl apply -f - | ||
- name: Deploy to Kubernetes | ||
uses: stefanprodan/kube-tools@v1 | ||
with: | ||
helmv3: 3.12.0 | ||
command: | | ||
kubectl get nodes | ||
helmv3 repo add api-gateway-deployment https://ts4nfdi.github.io/api-gateway-deployment/ | ||
helmv3 repo update | ||
helmv3 upgrade ts4nfdi \ | ||
--install \ | ||
api-gateway-deployment/api-gateway | ||
--install \ | ||
api-gateway-deployment/api-gateway |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/org/semantics/apigateway/service/ConfigurationLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.semantics.apigateway.service; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.Getter; | ||
import org.semantics.apigateway.config.DatabaseConfig; | ||
import org.semantics.apigateway.config.OntologyConfig; | ||
import org.semantics.apigateway.model.DynTransformResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.core.io.ResourceLoader; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.StreamUtils; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Service | ||
@Getter | ||
public class ConfigurationLoader { | ||
|
||
@Autowired | ||
private ConfigurableEnvironment environment; | ||
|
||
@Autowired | ||
private ResourceLoader resourceLoader; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(DynSearchService.class); | ||
private List<OntologyConfig> ontologyConfigs; | ||
private Map<String, Map<String, String>> responseMappings; | ||
|
||
// Method invoked after on server start, loads database configurations and replace environment variables | ||
@PostConstruct | ||
public void loadDbConfigs() throws IOException { | ||
Resource resource = resourceLoader.getResource("classpath:response-config.json"); | ||
String jsonContent = StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8); | ||
|
||
for (Map.Entry<String, Object> property : environment.getSystemEnvironment().entrySet()) { | ||
String key = property.getKey(); | ||
String value = (String) property.getValue(); | ||
jsonContent = jsonContent.replace("${" + key + "}", value); | ||
} | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
DatabaseConfig dbConfig = objectMapper.readValue(jsonContent, DatabaseConfig.class); | ||
this.ontologyConfigs = dbConfig.getDatabases(); | ||
this.responseMappings = loadResponseMappings(); | ||
ontologyConfigs.forEach(config -> logger.info("Loaded config: {}", config)); | ||
} | ||
|
||
// Loads response mappings from a json configuration file | ||
private Map<String, Map<String, String>> loadResponseMappings() throws IOException { | ||
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("response-mappings.json"); | ||
if (inputStream != null) { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
Map<String, Map<String, String>> mappings = objectMapper.readValue(inputStream, new TypeReference<Map<String, Map<String, String>>>() { | ||
}); | ||
if (mappings != null) { | ||
return mappings; | ||
} | ||
} | ||
return Collections.emptyMap(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters