Skip to content
Snippets Groups Projects
Commit a0324533 authored by Petr Ježek's avatar Petr Ježek
Browse files

latex service

parent ba597ea0
No related branches found
No related tags found
No related merge requests found
Showing
with 1115 additions and 45 deletions
...@@ -31,3 +31,6 @@ build/ ...@@ -31,3 +31,6 @@ build/
### VS Code ### ### VS Code ###
.vscode/ .vscode/
### etmt specific ###
/out
# syntax=docker/dockerfile:experimental
########Maven build stage########
FROM maven:3.8.4-openjdk-17 as maven_build
WORKDIR /app
#copy pom
COPY pom.xml .
#copy source
COPY src ./src
# build the app and download dependencies only when these are new (thanks to the cache)
RUN --mount=type=cache,target=/root/.m2 mvn clean package -Dmaven.test.skip
# split the built app into multiple layers to improve layer rebuild
RUN mkdir -p target/docker-packaging && cd target/docker-packaging && jar -xf ../my-app*.jar
########JRE run stage########
FROM openjdk:17.0-slim
WORKDIR /app
#copy built app layer by layer
ARG DOCKER_PACKAGING_DIR=/app/target/docker-packaging
COPY --from=maven_build ${DOCKER_PACKAGING_DIR}/BOOT-INF/lib /app/lib
COPY --from=maven_build ${DOCKER_PACKAGING_DIR}/BOOT-INF/classes /app/classes
COPY --from=maven_build ${DOCKER_PACKAGING_DIR}/META-INF /app/META-INF
#run the app
CMD java -cp .:classes:lib/* \
-Djava.security.egd=file:/dev/./urandom \
foo.bar.MySpringBootApplication
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.5.6</version>
<relativePath>pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>cz.cvut.fel.pro</groupId>
<artifactId>etmt</artifactId>
<name>etmt</name>
<version>0.0.1-SNAPSHOT</version>
<description>etmt</description>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<excludeDevtools>false</excludeDevtools>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.5.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.5.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.5.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.5.6</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>spring-boot-test</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
<exclusion>
<artifactId>spring-boot-test-autoconfigure</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
<exclusion>
<artifactId>json-path</artifactId>
<groupId>com.jayway.jsonpath</groupId>
</exclusion>
<exclusion>
<artifactId>assertj-core</artifactId>
<groupId>org.assertj</groupId>
</exclusion>
<exclusion>
<artifactId>hamcrest</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
<exclusion>
<artifactId>junit-jupiter</artifactId>
<groupId>org.junit.jupiter</groupId>
</exclusion>
<exclusion>
<artifactId>mockito-core</artifactId>
<groupId>org.mockito</groupId>
</exclusion>
<exclusion>
<artifactId>mockito-junit-jupiter</artifactId>
<groupId>org.mockito</groupId>
</exclusion>
<exclusion>
<artifactId>jsonassert</artifactId>
<groupId>org.skyscreamer</groupId>
</exclusion>
<exclusion>
<artifactId>spring-test</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>xmlunit-core</artifactId>
<groupId>org.xmlunit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>5.5.3</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>spring-test</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.5.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.5.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>2.0.0-alpha4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.librepdf</groupId>
<artifactId>openpdf</artifactId>
<version>1.3.26</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
version: "3.8" version: "3.8"
services: services:
java-17:
mongodb: mongodb:
container_name: mongodb container_name: mongodb
image : mongo image : mongo
......
File deleted
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
<name>etmt</name> <name>etmt</name>
<description>etmt</description> <description>etmt</description>
<properties> <properties>
<java.version>17</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
...@@ -29,7 +31,6 @@ ...@@ -29,7 +31,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-security</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
...@@ -49,16 +50,29 @@ ...@@ -49,16 +50,29 @@
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<version>2.5.5</version> <version>2.5.5</version>
</dependency> </dependency>
<!-- Testing -->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>junit</groupId>
<artifactId>lombok</artifactId> <artifactId>junit</artifactId>
<optional>true</optional> <version>4.11</version>
<scope>test</scope>
</dependency> </dependency>
<!-- Logging -->
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.slf4j</groupId>
<artifactId>junit-jupiter-api</artifactId> <artifactId>slf4j-log4j12</artifactId>
<version>5.8.1</version> <version>2.0.0-alpha4</version>
</dependency> </dependency>
<!-- Other -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
<!-- PDF -->
<dependency> <dependency>
<groupId>com.github.librepdf</groupId> <groupId>com.github.librepdf</groupId>
<artifactId>openpdf</artifactId> <artifactId>openpdf</artifactId>
...@@ -81,6 +95,23 @@ ...@@ -81,6 +95,23 @@
<excludeDevtools>false</excludeDevtools> <excludeDevtools>false</excludeDevtools>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<!-- Activate the use of TCP to transmit events to the plugin -->
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
......
...@@ -2,6 +2,7 @@ package cz.cvut.fel.pro.emtt; ...@@ -2,6 +2,7 @@ package cz.cvut.fel.pro.emtt;
import cz.cvut.fel.pro.emtt.model.Question; import cz.cvut.fel.pro.emtt.model.Question;
import cz.cvut.fel.pro.emtt.repository.QuestionRepository; import cz.cvut.fel.pro.emtt.repository.QuestionRepository;
import cz.cvut.fel.pro.emtt.service.LatexService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
...@@ -20,12 +21,14 @@ public class App { ...@@ -20,12 +21,14 @@ public class App {
} }
@Bean @Bean
CommandLineRunner runner(QuestionRepository repository) { CommandLineRunner runner(QuestionRepository repository, LatexService latexService) {
return args -> { return args -> {
Question q = Question.builder().title("Epic question").text("This is something epic...?").build(); Question q = Question.builder().title("Epic question").text("This is something epic...?").build();
repository.insert(q); repository.insert(q);
log.info("question with id: {} is: {}", q.getId(), repository.findById(q.getId())); log.info("question with id: {} is: {}", q.getId(), repository.findById(q.getId()));
log.info("number of questions with title: {} is: {}", q.getTitle(), repository.findAllQuestionsByTitle(q.getTitle()).size()); log.info("number of questions with title: {} is: {}", q.getTitle(), repository.findAllQuestionsByTitle(q.getTitle()).size());
latexService.build();
}; };
} }
} }
package cz.cvut.fel.pro.emtt.config;
public class Constants {
public static final String OUT_PATH = "out/";
}
package cz.cvut.fel.pro.emtt.exception;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
@Slf4j
public class SimpleExceptionHandler
{
@ExceptionHandler(Exception.class)
public void handleAnyException(Exception e) {
log.error("server exception", e);
}
}
package cz.cvut.fel.pro.emtt.service;
import cz.cvut.fel.pro.emtt.config.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@Service
@Slf4j
public class FileService {
public File createFile(String filename, boolean overwrite) throws IOException {
String pathName = filename;
File file = new File(pathName);
if (overwrite) {
if (!file.delete()) {
log.warn("can't overwrite file {}", pathName);
}
}
if (!file.createNewFile()) {
log.warn("file '{}' already exists", pathName);
}
log.info("file {} created successfully", pathName);
return file;
}
public void writeToFile(String pathName, String what) throws IOException {
FileWriter fw = new FileWriter(pathName);
fw.write(what);
fw.close();
log.info("successfully written to file {}", pathName);
}
}
package cz.cvut.fel.pro.emtt.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.io.*;
@Service
@Slf4j
public class LatexService {
public void build() throws IOException, InterruptedException {
ProcessBuilder builder = new ProcessBuilder();
builder.command("docker", "exec", "pdflatex", "pdflatex", "-output-directory", "/home/out/", "/home/in/main.tex").inheritIO(); //"pdflatex", "-output-directory", "/usr/shared/", "/usr/shared/main.tex"
Process process = builder.start();
/*BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
log.info(line);
}*/
int exitCode = process.waitFor();
log.info("latex build process ended with code {}", exitCode);
}
}
\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{parskip}
\usepackage{fullpage}
\usepackage{enumitem}
\everymath{\displaystyle}
\title{Zápočtový test ZDM č.1}
\author{jméno: \texttt{\detokenize{______________}}}
\date{12.12.2021}
\begin{document}
\maketitle
\renewcommand{\abstractname}{Pokyny k vypracování}
\begin{abstract}
\noindent Test vypracovávnejte samostatně\\
Otázky mají následující typy: slovní odpověď, zaškrtávací s jednou správnou odpovědí, zaškrtávací s více správnými odpověďmi.\\
\end{abstract}
\begin{enumerate}
\item O množině D platí (více správných odpovědí) \hfill (3b)\\
\begin{enumerate}[label=\alph*),noitemsep]
\item \texttt{[ ]} Je to nějaká blbost\\
\item \texttt{[ ]} Množina je\\
\item \texttt{[ ]} Nevím\\
\end{enumerate}
\end{enumerate}
\begin{enumerate}
\item Dnes je (jedna správná odpověď) \hfill (1b)\\
\begin{enumerate}[label=\alph*),noitemsep]
\item \texttt{[ ]} Pondělí\\
\item \texttt{[ ]} Není\\
\item \texttt{[ ]} Neděle\\
\item \texttt{[ ]} Já vážně nevím, teď jsem vstal ale řeknu ti $f(x)=2x+6$\\
\end{enumerate}
\end{enumerate}
\end{document}
etmt-be/src/main/resources/tex/obr1.png

4.74 KiB

package cz.cvut.fel.pro.emtt.service;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.IOException;
@SpringBootTest
class FileServiceTest {
@Autowired
private FileService fileService;
@Test
public void testBasic() throws IOException {
fileService.createFile("testFile.tex", true);
fileService.writeToFile("testFile.tex", "\\title{Hello World}");
}
}
\ No newline at end of file
package cz.cvut.fel.pro.emtt.service;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.IOException;
@SpringBootTest
class LatexServiceTest {
@Autowired
public LatexService latexService;
@Test
public void test() throws IOException, InterruptedException {
latexService.build();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment