Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into main
  • Loading branch information
Fabi-02 committed Feb 19, 2024
2 parents f01e743 + 7b70798 commit 8cc65a2
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
personal-playground/
.DS_Store
mongo-data
10 changes: 5 additions & 5 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*
!target/*-runner
!target/*-runner.jar
!target/lib/*
!target/quarkus-app/*
# *
# !target/*-runner
# !target/*-runner.jar
# !target/lib/*
# !target/quarkus-app/*
34 changes: 28 additions & 6 deletions backend/src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,38 @@
# accessed directly. (example: "foo.example.com,bar.example.com")
#
###
FROM registry.access.redhat.com/ubi8/openjdk-21:1.17

ENV LANGUAGE='en_US:en'

FROM registry.access.redhat.com/ubi8/openjdk-21:latest as builder

# copy the pom.xml and all the necessary files (copy .pem files after build)
WORKDIR /project
COPY pom.xml /project/pom.xml
COPY src /project/src
COPY .mvn /project/.mvn
COPY mvnw /project/mvnw

# build the application
RUN ./mvnw package -DskipTests

# Start the runner image
FROM registry.access.redhat.com/ubi8/openjdk-21:latest as runner

ENV LANGUAGE='en_US:en'

# We make four distinct layers so if there are application changes the library layers can be re-used
COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/
COPY --chown=185 target/quarkus-app/*.jar /deployments/
COPY --chown=185 target/quarkus-app/app/ /deployments/app/
COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/
COPY --from=builder --chown=185 /project/target/quarkus-app/lib/ /deployments/lib/
COPY --from=builder --chown=185 /project/target/quarkus-app/*.jar /deployments/
COPY --from=builder --chown=185 /project/target/quarkus-app/app/ /deployments/app/
COPY --from=builder --chown=185 /project/target/quarkus-app/quarkus/ /deployments/quarkus/

# Ensure group permissions are added to the runner
USER root
RUN chgrp -R 0 /deployments && chmod -R g=u /deployments
USER 185

# copy the pem files
COPY src/main/resources/*.pem /deployments/quarkus-app/

EXPOSE 8080
USER 185
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ private static List<QuestionWrapper> questionWrappersFromApiFeedbackFormQuestion
apiFeedbackQuestion.getDescription(),
FeedbackQuestionType.valueOf(apiFeedbackQuestion.getType()),
apiFeedbackQuestion.getOptions(),
apiFeedbackQuestion.getKey()
apiFeedbackQuestion.getKey(),
apiFeedbackQuestion.getRangeLow(),
apiFeedbackQuestion.getRangeHigh()
);

course.addFeedbackQuestion(feedbackQuestion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
public class FeedbackQuestion extends Question {

public FeedbackQuestionType type;
public String rangeLow;
public String rangeHigh;

public FeedbackQuestion() {
}

public FeedbackQuestion(String name, String description, FeedbackQuestionType type, List<String> options, String key) {
public FeedbackQuestion(String name, String description, FeedbackQuestionType type, List<String> options, String key, String rangeLow, String rangeHigh) {
super(name, description, options, key);
this.type = type;
this.rangeLow = rangeLow;
this.rangeHigh = rangeHigh;
}

public FeedbackQuestion copy() {
FeedbackQuestion copy = new FeedbackQuestion(this.name, this.description, this.type, this.options, this.key);
FeedbackQuestion copy = new FeedbackQuestion(this.name, this.description, this.type, this.options, this.key, this.rangeLow, this.rangeHigh);
copy.id = this.id;
return copy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,56 +45,72 @@ public Object addData() {
"Wie verständlich war das Thema Kombinatorik?",
FeedbackQuestionType.STARS,
null,
"F-Q-COMBINATORICS"
"F-Q-COMBINATORICS",
null,
null
);
FeedbackQuestion question2 = new FeedbackQuestion(
"Kurzweiligkeit",
"Wie kurzweilig war die Vorlesung? (links = langweilig, rechts = kurzweilig)",
"Wie kurzweilig war die Vorlesung?",
FeedbackQuestionType.SLIDER,
null,
"F-Q-ENTERTAINMENT"
"F-Q-ENTERTAINMENT",
"langweilig",
"spannend"
);
FeedbackQuestion question3 = new FeedbackQuestion(
"Praxisbezug",
"Wie bewerten Sie den Praxisbezug der Vorlesung? (links = wenig Praxisbezug, rechts = viel Praxisbezug)",
"Wie bewerten Sie den Praxisbezug der Vorlesung?",
FeedbackQuestionType.SLIDER,
null,
"F-Q-PRACTICALITY"
"F-Q-PRACTICALITY",
"wenig Praxisbezug",
"viel Praxisbezug"
);
FeedbackQuestion question4 = new FeedbackQuestion(
"Sprachbarriere",
"Die Vorlesung wurde auf Englisch gehalten. Wie fanden Sie die Verständlichkeit?",
FeedbackQuestionType.SLIDER,
null,
"F-Q-ENGLISH"
"F-Q-ENGLISH",
null,
null
);
FeedbackQuestion question5 = new FeedbackQuestion(
"Prüfungsvorbereitung",
"Wenn jetzt direkt die Prüfung wäre, wie gut fühlen Sie sich vorbereitet?",
FeedbackQuestionType.STARS,
null,
"F-Q-EXAM"
"F-Q-EXAM",
null,
null
);
FeedbackQuestion question6 = new FeedbackQuestion(
"Technische Mittel",
"Wie bewerten Sie die technischen Mittel, die in der Vorlesung verwendet wurden?",
FeedbackQuestionType.STARS,
null,
"F-Q-TECHNOLOGY"
"F-Q-TECHNOLOGY",
null,
null
);
FeedbackQuestion question7 = new FeedbackQuestion(
"Schwierigstes Thema",
"Welches Thema war für Sie am schwierigsten?",
FeedbackQuestionType.SINGLE_CHOICE,
List.of("Kombinatorik", "Graphen", "Relationen", "Formale Sprachen", "Endliche Automaten", "Turingmaschinen", "Berechenbarkeit"),
"F-Q-HARDEST-TOPIC"
"F-Q-HARDEST-TOPIC",
null,
null
);
FeedbackQuestion question8 = new FeedbackQuestion(
"Schwierigstes Thema",
"Welches Thema war für Sie am schwierigsten?",
FeedbackQuestionType.SINGLE_CHOICE,
List.of("Multitenancy", "Microservices", "Cloud Foundry", "Docker", "Kubernetes", "Cloud Native", "Cloud Native Buildpacks"),
"F-Q-HARDEST-TOPIC-2"
"F-Q-HARDEST-TOPIC-2",
null,
null
);

// generate a Course
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ public static class ApiFeedbackQuestion {
public String type; // SLIDER, STARS, FULLTEXT, YES_NO, SINGLE_CHOICE
public List<String> options;
public String key;
public String rangeLow;
public String rangeHigh;

public ApiFeedbackQuestion() {
}

public ApiFeedbackQuestion(String name, String description, String type, List<String> options, String key) {
public ApiFeedbackQuestion(String name, String description, String type, List<String> options, String key, String rangeLow, String rangeHigh) {
this.name = name;
this.description = description;
this.type = type;
this.options = options;
this.key = key;
this.rangeLow = rangeLow;
this.rangeHigh = rangeHigh;
}

public String getKey() { return this.key; }
Expand All @@ -29,6 +33,8 @@ public ApiFeedbackQuestion(String name, String description, String type, List<St
public List<String> getOptions() {
return this.options != null ? this.options : List.of();
}
public String getRangeLow() { return this.rangeLow; }
public String getRangeHigh() { return this.rangeHigh; }
}

public String name;
Expand Down
63 changes: 63 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
version: "3.1"
services:

# mongo db
mobile-learning-mongo:
image: mongo
container_name: mobile-learning-mongo
environment:
- MONGO_INITDB=mobilelearning
ports:
- 27017:27017
expose:
- 27017
volumes:
- ./mongo-data:/data/db

# java quarkus backend
mobile-learning-backend:
build:
context: ./backend
dockerfile: src/main/docker/Dockerfile.jvm
# dockerfile: Dockerfile
container_name: mobile-learning-backend
restart: always
ports:
- 8080:8080
depends_on:
- mobile-learning-mongo
environment:
- MONGODB_HOST=mobile-learning-mongo
- MONGODB_PORT=27017
- MONGODB_DATABASE=mobilelearning
volumes:
- ./backend/src/main/resources/privateKey.pem:/deployments/privateKey.pem
- ./backend/src/main/resources/publicKey.pem:/deployments/publicKey.pem
- ./backend/src/main/resources/application.properties:/deployments/application.properties
# extra_hosts:
# - "host.docker.internal:host-gateway"
network_mode: "host"

# flutter frontend
mobile-learning-frontend:
build:
context: ./frontend
dockerfile: Dockerfile
ports:
- "5000:80"
container_name: mobile-learning-frontend
restart: always


# nginx reverse proxy
mobile-learning-nginx:
build: ./nginx
container_name: mobile-learning-nginx
environment:
- MOBILE_LEARNING_BACKEND_URL=http://localhost:8080
- MOBILE_LEARNING_FRONTEND_URL=http://localhost:5000
ports:
- 80:80
depends_on:
- mobile-learning-backend
network_mode: "host"
47 changes: 47 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Environemnt to install flutter and build web
FROM debian:latest AS build-env

# install all needed stuff
RUN apt-get update
RUN apt-get install -y curl git unzip

# define variables
ARG FLUTTER_SDK=/usr/local/flutter
ARG FLUTTER_VERSION=3.16.7
ARG APP=/app/

#clone flutter
RUN git clone https://github.com/flutter/flutter.git $FLUTTER_SDK
# change dir to current flutter folder and make a checkout to the specific version
RUN cd $FLUTTER_SDK && git fetch && git checkout $FLUTTER_VERSION

# setup the flutter path as an enviromental variable
ENV PATH="$FLUTTER_SDK/bin:$FLUTTER_SDK/bin/cache/dart-sdk/bin:${PATH}"

# Start to run Flutter commands
# doctor to see if all was installes ok
RUN flutter doctor -v

# create folder to copy source code
RUN mkdir $APP
# copy source code to folder
COPY . $APP
# stup new folder as the working directory
WORKDIR $APP

# Run build: 1 - clean, 2 - pub get, 3 - build web
RUN flutter clean
RUN flutter pub get
RUN flutter build web

# once heare the app will be compiled and ready to deploy

# use nginx to deploy
FROM nginx:1.25.2-alpine

# copy the info of the builded web app to nginx
COPY --from=build-env /app/build/web /usr/share/nginx/html

# Expose and run nginx but on port 5000
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
17 changes: 14 additions & 3 deletions frontend/lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ import 'package:flutter/foundation.dart';

String getBackendUrl({String protocol = 'http'}) {
// final String? backendUrl = Platform.environment['BACKEND_URL']; // later maybe
if (defaultTargetPlatform == TargetPlatform.android) {
return '$protocol://10.0.2.2:8080';

// get the current domain (when running in a browser)
final String domain = Uri.base.host;

// if the domain is localhost, use the local backend
if (domain == 'localhost') {
if (defaultTargetPlatform == TargetPlatform.android) {
return '$protocol://10.0.2.2:8080';
}
return '$protocol://localhost:8080';

// if the domain is not localhost, use the deployed backend
} else {
return '$protocol://$domain/api';
}
return '$protocol://localhost:8080';
}
5 changes: 5 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:stable

COPY ./default.conf.template /etc/nginx/templates/default.conf.template

EXPOSE 80
31 changes: 31 additions & 0 deletions nginx/default.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
server {
listen 80;

location /api {
rewrite /api/(.*) /$1 break;
proxy_pass ${MOBILE_LEARNING_BACKEND_URL};
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_connect_timeout 7d;
proxy_send_timeout 7d;
proxy_read_timeout 7d;
}

location / {
rewrite /(.*) /$1 break;
proxy_pass ${MOBILE_LEARNING_FRONTEND_URL};
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}


}

0 comments on commit 8cc65a2

Please sign in to comment.