Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

46 docker backend #48

Merged
merged 24 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f4ccd62
First version of Home View. Modified it to be the first view, redirec…
lauratbg Feb 27, 2024
56ac9cc
Extracted the navBar to a separated .js, added a button to intruction…
lauratbg Feb 28, 2024
5338915
Improvements of Instructions and Nav (now it has a button '?' but it …
lauratbg Feb 28, 2024
b8d4851
First modifications of login
lauratbg Mar 1, 2024
0bc1a87
When clicking help button in nav it redirects you to the intructions …
lauratbg Mar 1, 2024
e7a2d9d
Home improved: redirections to the login, instructions and register n…
lauratbg Mar 1, 2024
ab9073c
Question generation logic started
Mister-Mario Mar 1, 2024
ff0f998
Added JSON library and trying to test the call
uo289267 Mar 1, 2024
c643e9e
Simple css for home done
lauratbg Mar 1, 2024
508caf8
Register done the same way as the login, both use the same css, the l…
lauratbg Mar 1, 2024
3ca7618
Little error solved
lauratbg Mar 1, 2024
6b86c5e
Fixed the code:
Mister-Mario Mar 1, 2024
074fff6
Added Question's View Need to improve logic
uo289267 Mar 2, 2024
9197d8a
Fixed logic, but cannot handle server errors, like having the server …
Mister-Mario Mar 2, 2024
3cc31fa
QuestionView CSS added
uo289267 Mar 2, 2024
1ae245b
Little change
lauratbg Mar 4, 2024
2060fdb
Merge branch 'FrontEnd-Integration' into 32-question-view-logic
lauratbg Mar 4, 2024
8f5f7fd
Merge branch 'QuestionGeneration' into 46-docker-backend
Mister-Mario Mar 4, 2024
520fafb
Everything works:
Mister-Mario Mar 4, 2024
fd70ac1
Modified the backend and some of the front end to be able to do the f…
Mister-Mario Mar 4, 2024
17c6f28
Added first implementation of the backend's Dockerfile
sinne10 Mar 5, 2024
ee57908
Added Dockerfile to docker compose
sinne10 Mar 5, 2024
7c64de4
Tested and now docker works
Mister-Mario Mar 6, 2024
6da2a4a
Merge branch 'master' into 46-docker-backend
Mister-Mario Mar 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions backend/wiq/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
########################################
# Build stage
########################################
# Maven base image
FROM maven:3.9.6-eclipse-temurin-17-alpine AS build
# Working directory
WORKDIR /app
# Copy project
COPY pom.xml .
COPY src ./src
# Build jar file
RUN mvn clean package

########################################
# Package stage
########################################
# Java base image
FROM openjdk:17-jdk-alpine
# Copy jar file built in previous stage
COPY --from=build /app/target/wiq-0.0.1-SNAPSHOT.jar wiq-0.0.1-SNAPSHOT.jar
# Expose port
EXPOSE 8090
# Launch application
CMD ["java","-jar","/wiq-0.0.1-SNAPSHOT.jar"]
17 changes: 17 additions & 0 deletions backend/wiq/src/main/java/com/wiq/wiq/CustomConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.wiq.wiq;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CustomConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000")
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wiq.wiq.services.TestService;
import com.wiq.wiq.services.QuestionGeneratorService;

import org.springframework.web.bind.annotation.RequestParam;


@RestController
public class TestController {
private TestService t;

public TestController(TestService t){
this.t = t;
}
private QuestionGeneratorService questionGeneratorService;

public TestController(QuestionGeneratorService questionGeneratorService){
this.questionGeneratorService = questionGeneratorService;
}

@RequestMapping("/test") //http://localhost:8090/test
public String getList() {
return t.getTest().getName();
@RequestMapping("/question")
public String requestMethodName() {
return questionGeneratorService.getQuestions();
}

}
12 changes: 0 additions & 12 deletions backend/wiq/src/main/java/com/wiq/wiq/model/TestClass.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.wiq.wiq.services;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;
import org.springframework.stereotype.Service;

import com.wiq.wiq.services.questionGenerator.QuestionGenerator;
import com.wiq.wiq.services.questionGenerator.question.QuestionType;

@Service
public class QuestionGeneratorService {

private QuestionType[] types = {QuestionType.POPULATION, QuestionType.CAPITAL, QuestionType.SIZE,
QuestionType.LANGUAGE};

public String getQuestions() {
QuestionGenerator qg = new QuestionGenerator("en");
List<String> toRet = new ArrayList<>();
for(QuestionType t : types) {
toRet.addAll(run(qg, t));
}
return this.listToJSON(toRet);

}

private List<String> run(QuestionGenerator qg, QuestionType type) {
List<String> toRet = new ArrayList<>();
for(int i=0; i<3; i++) {
toRet.add(qg.generateQuestion(type));
System.out.println("Generated");
}
return toRet;
}

/**
* Receives a list of Strings in JSON format and creates a JSON with the keys 0-N, N = size of list
* @param list
* @return String in JSON format
*/
private String listToJSON(List<String> list){
JSONObject json = new JSONObject();
for(int i = 0; i < list.size(); i++)
json.accumulate((i + ""), list.get(i));
return json.toString();
}

}
21 changes: 0 additions & 21 deletions backend/wiq/src/main/java/com/wiq/wiq/services/TestService.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
package com.wiq.wiq.services.questionGenerator;

import com.wiq.wiq.services.questionGenerator.question.QuestionType;
Expand All @@ -23,3 +24,4 @@ private static void run(QuestionGenerator qg, QuestionType type) {
}

}
*/
214 changes: 112 additions & 102 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,110 +1,120 @@
version: '3'
services:
mongodb:
container_name: mongodb-${teamname:-defaultASW}
image: mongo
profiles: ["dev", "prod"]
volumes:
- mongodb_data:/data/db
ports:
- "27017:27017"
networks:
- mynetwork
version: '3'
services:
mongodb:
container_name: mongodb-${teamname:-defaultASW}
image: mongo
profiles: ["dev", "prod"]
volumes:
- mongodb_data:/data/db
ports:
- "27017:27017"
networks:
- mynetwork

authservice:
container_name: authservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_en1b/authservice:latest
profiles: ["dev", "prod"]
build: ./users/authservice
depends_on:
- mongodb
ports:
- "8002:8002"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb
authservice:
container_name: authservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_en1b/authservice:latest
profiles: ["dev", "prod"]
build: ./users/authservice
depends_on:
- mongodb
ports:
- "8002:8002"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb

userservice:
container_name: userservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_en1b/userservice:latest
profiles: ["dev", "prod"]
build: ./users/userservice
depends_on:
- mongodb
ports:
- "8001:8001"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb
userservice:
container_name: userservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_en1b/userservice:latest
profiles: ["dev", "prod"]
build: ./users/userservice
depends_on:
- mongodb
ports:
- "8001:8001"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb

gatewayservice:
container_name: gatewayservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_en1b/gatewayservice:latest
profiles: ["dev", "prod"]
build: ./gatewayservice
depends_on:
- mongodb
- userservice
- authservice
ports:
- "8000:8000"
networks:
- mynetwork
environment:
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001
backend:
container_name: backend_wiq-${teamname:-defaultASW}
profiles: ["dev", "prod"]
build:
context: ./backend/wiq
dockerfile: Dockerfile
ports:
- 8090:8090

webapp:
container_name: webapp-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_en1b/webapp:latest
profiles: ["dev", "prod"]
build: ./webapp
depends_on:
- gatewayservice
ports:
- "3000:3000"
gatewayservice:
container_name: gatewayservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_en1b/gatewayservice:latest
profiles: ["dev", "prod"]
build: ./gatewayservice
depends_on:
- mongodb
- userservice
- authservice
- backend
ports:
- "8000:8000"
networks:
- mynetwork
environment:
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001

prometheus:
image: prom/prometheus
container_name: prometheus-${teamname:-defaultASW}
profiles: ["dev"]
networks:
- mynetwork
volumes:
- ./gatewayservice/monitoring/prometheus:/etc/prometheus
- prometheus_data:/prometheus
ports:
- "9090:9090"
depends_on:
- gatewayservice

grafana:
image: grafana/grafana
container_name: grafana-${teamname:-defaultASW}
profiles: ["dev"]
networks:
- mynetwork
volumes:
- grafana_data:/var/lib/grafana
- ./gatewayservice/monitoring/grafana/provisioning:/etc/grafana/provisioning
environment:
- GF_SERVER_HTTP_PORT=9091
- GF_AUTH_DISABLE_LOGIN_FORM=true
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
ports:
- "9091:9091"
depends_on:
- prometheus
webapp:
container_name: webapp-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_en1b/webapp:latest
profiles: ["dev", "prod"]
build: ./webapp
depends_on:
- gatewayservice
ports:
- "3000:3000"

prometheus:
image: prom/prometheus
container_name: prometheus-${teamname:-defaultASW}
profiles: ["dev"]
networks:
- mynetwork
volumes:
- ./gatewayservice/monitoring/prometheus:/etc/prometheus
- prometheus_data:/prometheus
ports:
- "9090:9090"
depends_on:
- gatewayservice

grafana:
image: grafana/grafana
container_name: grafana-${teamname:-defaultASW}
profiles: ["dev"]
networks:
- mynetwork
volumes:
- grafana_data:/var/lib/grafana
- ./gatewayservice/monitoring/grafana/provisioning:/etc/grafana/provisioning
environment:
- GF_SERVER_HTTP_PORT=9091
- GF_AUTH_DISABLE_LOGIN_FORM=true
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
ports:
- "9091:9091"
depends_on:
- prometheus

volumes:
mongodb_data:
prometheus_data:
grafana_data:

networks:
mynetwork:
driver: bridge
volumes:
mongodb_data:
prometheus_data:
grafana_data:

networks:
mynetwork:
driver: bridge
Loading
Loading