Skip to content

Commit

Permalink
add docker based development with src watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
EugenMayer committed Sep 25, 2018
1 parent bb21e75 commit 489c250
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 55 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This project is basically an extended version of [jodconverter-sample-rest](http

You can use this project as is using docker with `eugenmayer/kontextwork-converter` or build it here yourself.

## build
## Build

local java build, when you have all the build tools present + libreoffice locally installed

Expand All @@ -29,14 +29,30 @@ or better use the docker image with all included, no dev tools/LO needed locally
# or dev mode with swagger and a debugger on 5001
docker run --memory 512m --name converter-dev --rm -p 5001:5001 -p 8080:8080 eugenmayer/kontextwork-converter:development

## Development

You can either use the IDE task or the local gradle

./gradlew -Pdev bootRun

Or even better, use the development container. You will not need any LibreOffice/Gradle installed locally

make start-src # basically just docker-compose up
This fires up a docker container, mounts your source. To auto-rebuild and auto-restart he app very quick do this

make watch
# or just run ./watch.sh localy
## Debugging

Of course you can just start using your IDE and debug that, but if you want to debug inside the docker container

make start

And now connect(attach) to localhost 8000 for debugging `eugenmayer/kontextwork-converter:development` has a default remote
debugging port enabled on 8000
And now connect(attach) to localhost 5001 for debugging `eugenmayer/kontextwork-converter:development` has a default remote
debugging port enabled on 5001

## REST endpoints

Start the project and access `http://localhost:8080/swagger-ui.html` to browse, inspect and try the REST endpoints.
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "2"

services:
app:
container_name: converter-dev
image: eugenmayer/kontextwork-converter:development
working_dir: /src
entrypoint: ./gradlew
command: -Pdev bootRun
volumes:
- ./:/src
ports:
- 5001:5001
- 8080:8080
mem_limit: 512M
6 changes: 6 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ push:
docker push eugenmayer/kontextwork-converter:development
docker push eugenmayer/kontextwork-converter:production

start-src: stop
./start.sh

watch:
./watch.sh

start: stop
# 5001 is the remote debugger port, which we enable by default
docker run -m 512m --name converter-dev --rm -p 5001:5001 -p 8080:8080 eugenmayer/kontextwork-converter:development
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/de/kontextwork/converter/ConverterApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Collections;

@SpringBootApplication
Expand All @@ -21,5 +20,31 @@ public class ConverterApplication {
public static void main(String[] args) {
SpringApplication.run(ConverterApplication.class, args);
}
@Configuration
@EnableSwagger2
@Profile("dev")
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.select()
.apis(RequestHandlerSelectors.basePackage("de.kontextwork.converter"))
.paths(PathSelectors.regex("/conversion.*"))
.build()
.apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
return new ApiInfo(
"Conversion REST API",
"Conversion REST API for Online conversion. Automates conversions between office document formats using JODconverter, LibreOffice or Apache OpenOffice.",
"0.1",
"Terms of service",
new Contact("No", "kontextwork.de", "[email protected]"),
"Unknown",
"Unknown",
Collections.emptyList());
}
}
}
7 changes: 0 additions & 7 deletions src/main/java/de/kontextwork/converter/config/Profiles.java

This file was deleted.

43 changes: 0 additions & 43 deletions src/main/java/de/kontextwork/converter/config/SwaggerConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
@RestController
@RequestMapping("/conversion")
public class ConversionRestController {
//, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE

@Autowired
private ConverterService converterService;
//, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE

@RequestMapping(path = "", method = RequestMethod.POST)
public ResponseEntity<?> convert(@RequestParam(name="format", defaultValue = "pdf") final String targetFormatExt, @RequestParam("data") final MultipartFile inputMultipartFile) throws IOException, OfficeException {
if (!converterService.validateFormat(targetFormatExt)) {
Expand All @@ -41,3 +42,4 @@ public ResponseEntity<?> convert(@RequestParam(name="format", defaultValue = "pd
return ResponseEntity.ok().headers(headers).body(convertedFile.toByteArray());
}
}

3 changes: 3 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

docker-compose up "$@"
2 changes: 2 additions & 0 deletions wach.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
docker exec --workdir /src converter-dev ./gradlew build --continuous

0 comments on commit 489c250

Please sign in to comment.