Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from Informatievlaanderen/ci/combined-image
Browse files Browse the repository at this point in the history
ci: combine backend and frontend in one application
  • Loading branch information
Yalz authored Sep 27, 2023
2 parents 8ff250b + 9b948d3 commit d9449d7
Show file tree
Hide file tree
Showing 79 changed files with 202 additions and 272 deletions.
44 changes: 5 additions & 39 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,7 @@ env:
REGISTRY: ghcr.io

jobs:
Front-End:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: |
image=moby/buildkit:v0.10.6
- name: Log in to the GitHub Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: Informatievlaanderen
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/Informatievlaanderen/vsds-demonstrator-ui
tags: |
type=raw,value={{date 'YYYYMMDDHHmmss'}}
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: ./vue-frontend
push: true
file: ./vue-frontend/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64

Back-end:
demonstrator:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -55,7 +21,7 @@ jobs:
- name: Build and analyze
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -f ./spring-boot-backend/pom.xml -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=informatievlaanderen_vsds-demonstrator -Pcoverage
run: mvn -f ./pom.xml -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=informatievlaanderen_vsds-demonstrator -Pcoverage
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
Expand All @@ -73,15 +39,15 @@ jobs:
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/Informatievlaanderen/vsds-demonstrator-server
images: ${{ env.REGISTRY }}/Informatievlaanderen/vsds-demonstrator
tags: |
type=raw,value={{date 'YYYYMMDDHHmmss'}}
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: ./spring-boot-backend/
context: .
push: true
file: ./spring-boot-backend/Dockerfile
file: ./Dockerfile
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ bin/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store

node_modules
/frontend/node/
/.idea/
target
*.iml
./backend/src/main/resources/public/
derby.log
8 changes: 4 additions & 4 deletions spring-boot-backend/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ RUN mvn clean install -DskipTests
FROM openjdk:18-ea-bullseye
RUN apt-get update & apt-get upgrade

COPY --from=app-stage target/spring-boot-backend.jar ./
COPY --from=app-stage backend/target/vsds-demonstrator.jar ./

RUN useradd -u 2000 spring-boot-backed
USER spring-boot-backed
RUN useradd -u 2000 vsds-demonstrator
USER vsds-demonstrator

CMD ["java", "-jar", "spring-boot-backend.jar"]
CMD ["java", "-jar", "vsds-demonstrator.jar"]
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ graphdb:
url: "http://localhost:8080/rdf4j-server/repositories/"
repositoryId: "test"
server:
port: 8084
port: 8080
42 changes: 29 additions & 13 deletions spring-boot-backend/pom.xml → backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>

<groupId>be.informatievlaanderen.vsds.demonstrator</groupId>
<artifactId>spring-boot-backend</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>backend</artifactId>
<version>1.0.0-SNAPSHOT</version>


<properties>
Expand All @@ -29,17 +29,7 @@
<wiremock.version>2.35.0</wiremock.version>
<!-- RDF4j -->
<rdf4j.version>4.3.3</rdf4j.version>

<!-- Jacoco -->
<jacoco.version>0.8.10</jacoco.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml
</sonar.coverage.jacoco.xmlReportPaths>
<sonar.language>java</sonar.language>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.organization>informatievlaanderen</sonar.organization>
<sonar.projectKey>informatievlaanderen_vsds-demonstrator</sonar.projectKey>
</properties>

<dependencies>
Expand Down Expand Up @@ -199,7 +189,7 @@
</dependencyManagement>

<build>
<finalName>${project.artifactId}</finalName>
<finalName>vsds-demonstrator</finalName>
<pluginManagement>
<plugins>
<!-- SPRING BOOT -->
Expand All @@ -226,6 +216,32 @@
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy Vue.js frontend content</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/main/resources/public</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>..\frontend\target\dist</directory>
<includes>
<include>assets/</include>
<include>index.html</include>
<include>favicon.ico</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
public class Application {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package be.informatievlaanderen.vsds.demonstrator.member.application.exceptions;

public class NoGeometryProvidedException extends RuntimeException {
@Override
public String getMessage() {
return "No geometry could be found in the provided member";
}
@Override
public String getMessage() {
return "No geometry could be found in the provided member";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;

@RestController
@RequestMapping("api")
public class MembersController {
private final MemberService service;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package be.informatievlaanderen.vsds.demonstrator.member.rest.websocket;

import be.informatievlaanderen.vsds.demonstrator.member.application.valueobjects.MemberDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;

@Controller
public class MessageController {
private SimpMessagingTemplate template;
private static final Logger log = LoggerFactory.getLogger(WebSocketConfig.class);

@Autowired
public MessageController(SimpMessagingTemplate template) {
this.template = template;
}

public void send(MemberDto member) {
log.info("sending member");
this.template.convertAndSend("/broker/member", member);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api")
public class TriplesController {
private final TripleService tripleService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void when_MemberGeometryPresent_then_MemberGeomtryIsReturned_and_StatusIs200() t

when(service.getMemberById(ID)).thenReturn(dto);

mockMvc.perform(get("/geometry/" + ID).accept(MediaType.APPLICATION_JSON))
mockMvc.perform(get("/api/geometry/" + ID).accept(MediaType.APPLICATION_JSON))
.andExpect(content().json(json))
.andExpect(status().isOk());

Expand All @@ -83,7 +83,7 @@ void when_MemberGeometryPresent_then_MemberGeomtryIsReturned_and_StatusIs200() t
void when_MemberGeometryIsNotPresent_then_StatusIs404() throws Exception {
when(service.getMemberById(ID)).thenThrow(ResourceNotFoundException.class);

mockMvc.perform(get("/geometry/" + ID).accept(MediaType.APPLICATION_JSON))
mockMvc.perform(get("/api/geometry/" + ID).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());

verify(service).getMemberById(ID);
Expand All @@ -101,7 +101,7 @@ void when_MapBoundariesArePosted_then_ReturnMemberGeometries() throws Exception

when(service.getMembersInRectangle(rectangle, timestamp, timePeriod)).thenReturn(members);

mockMvc.perform(post("/in-rectangle")
mockMvc.perform(post("/api/in-rectangle")
.param("timestamp", timestamp.toString())
.param("timePeriod", timePeriod)
.contentType(MediaType.APPLICATION_JSON)
Expand All @@ -116,15 +116,15 @@ void when_MapBoundariesArePosted_then_ReturnMemberGeometries() throws Exception
class IngestMember {
@Test
void when_MemberWithInvalidGeometryIsPosted_then_Status400IsExpected() throws Exception {
mockMvc.perform(post("/members")
mockMvc.perform(post("/api/members")
.content(readDataFromFile("members/mobility-hindrance-with-invalid-wkt.nq"))
.contentType(Lang.NQUADS.getHeaderString()))
.andExpect(status().isBadRequest());
}

@Test
void when_MemberIsPosted_then_IngestMemberInService() throws Exception {
mockMvc.perform(post("/members")
mockMvc.perform(post("/api/members")
.content(readDataFromFile("members/mobility-hindrance.nq"))
.contentType(Lang.NQUADS.getHeaderString()))
.andExpect(status().isOk());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.junit.jupiter.api.Assertions.*;

@WireMockTest(httpPort = 8080)
@WireMockTest(httpPort = 8189)
class TripleRepositoryImplTest {
private static final String MEMBER_ID = "https://private-api.gipod.beta-vlaanderen.be/api/v1/mobility-hindrances/10810464/#ID";
private static final String ENDPOINT = "/rdf4j-server/repositories/test";
Expand All @@ -30,7 +30,7 @@ class TripleRepositoryImplTest {

@BeforeAll
static void beforeAll() {
graphDbConfig.setUrl("http://localhost:8080/rdf4j-server/repositories/");
graphDbConfig.setUrl("http://localhost:8189/rdf4j-server/repositories/");
graphDbConfig.setRepositoryId("test");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void when_triplesFetchingSucceeded_then_ReturnStatus200() throws Exception {
String json = new ObjectMapper().writeValueAsString(triples);
when(tripleService.getTriplesById(ID)).thenReturn(triples);

mockMvc.perform(get(URI.create("/triples/" + ID)))
mockMvc.perform(get(URI.create("/api/triples/" + ID)))
.andExpect(status().isOk())
.andExpect(content().json(json));

Expand All @@ -54,7 +54,7 @@ void when_triplesFetchingSucceeded_then_ReturnStatus200() throws Exception {
void when_triplesFetchingFails_then_ReturnStatus404() throws Exception {
when(tripleService.getTriplesById(ID)).thenThrow(new TripleFetchFailedException(ID, new RuntimeException()));

mockMvc.perform(get(URI.create("/triples/" + ID)))
mockMvc.perform(get(URI.create("/api/triples/" + ID)))
.andExpect(status().isNotFound());

verify(tripleService).getTriplesById(ID);
Expand Down
23 changes: 5 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ services:
volumes:
- ./gipod.config.yml:/ldio/application.yml:ro
depends_on:
- spring-boot-backend
- demonstrator
- rdf4j-server
networks:
- demonstrator

spring-boot-backend:
container_name: demonstrator-spring-boot-backend
image: demonstrator-spring-boot-backend
demonstrator:
container_name: demonstrator
image: vsds-demonstrator
build:
context: spring-boot-backend
context: .
dockerfile: Dockerfile
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgresql:5432/test
Expand All @@ -38,19 +38,6 @@ services:
networks:
- demonstrator

vue-frontend:
container_name: demonstrator-vue-frontend
image: demonstrator-vue-frontend
build:
context: vue-frontend
dockerfile: Dockerfile
ports:
- 8085:80
depends_on:
- spring-boot-backend
networks:
- demonstrator

rdf4j-server:
image: eclipse/rdf4j-workbench:latest
container_name: demonstrator-rdf4j-server
Expand Down
File renamed without changes.
File renamed without changes.
Binary file added frontend/node/node.exe
Binary file not shown.
Loading

0 comments on commit d9449d7

Please sign in to comment.