Skip to content

Commit

Permalink
new approach
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaiR committed Jan 20, 2019
1 parent e4d2d94 commit 0790a2a
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 256 deletions.
File renamed without changes.
27 changes: 17 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
FROM openjdk:8-jdk-alpine as build
WORKDIR /usr/workspace
WORKDIR /tools
COPY . .
RUN ./gradlew cleanProject build

FROM openjdk:8-jre-alpine
WORKDIR /usr/tauwebmap
FROM openjdk:8-jre-alpine as render
WORKDIR /render

ENV BUILD_SPACE /usr/workspace
ENV WEB_MAP TauWebMap.jar

COPY --from=build $BUILD_SPACE/server/build/libs/$WEB_MAP .
COPY --from=build $BUILD_SPACE/render/build/libs/render.jar .
COPY --from=build /tools/render/build/libs/render.jar .
COPY .revisions .

RUN apk update && \
apk add git pngquant && \
mkdir -p tmp/repo && \
git clone --progress https://github.com/TauCetiStation/TauCetiClassic.git tmp/repo
git clone --progress https://github.com/TauCetiStation/TauCetiClassic.git tmp/repo && \
java -Xms1g -Xmx1g -jar render.jar

FROM openjdk:8-jre-alpine
WORKDIR /usr/tauwebmap

ENV WEB_MAP TauWebMap.jar

COPY --from=build /tools/server/build/libs/$WEB_MAP .
COPY --from=render /render/data data/
COPY .revisions .

EXPOSE 3000

ENTRYPOINT ["sh", "-c"]
CMD ["exec java -Xms32m -Xmx64m -jar $WEB_MAP"]
CMD ["exec java -Xms16m -Xmx32m -jar $WEB_MAP"]
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = "io.github.spair"
version = "1.1-SNAPSHOT"
version = "1.0"

plugins {
`build-scan`
Expand Down
31 changes: 21 additions & 10 deletions render/src/main/java/io/github/spair/tauwebmap/Render.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
import java.awt.image.PixelGrabber;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.nio.file.Files;
import java.util.List;
import java.util.*;

public class Render {

private static final String DME_PATH = "tmp/repo/taucetistation.dme";
private static final String DMM_PATH = "tmp/repo/maps/z1.dmm";
private static final String REPO_PATH = "tmp/repo";
private static final String DME_PATH = REPO_PATH + "/taucetistation.dme";
private static final String DMM_PATH = REPO_PATH + "/maps/z1.dmm";

private static final String[] IGNORE_TYPES = {"/turf/space", "/area", "/obj/effect/landmark"};
private static final String[] COMPRESSION_ARGS = {"pngquant", "--ext=.png", "--force", "--strip", "--speed=1", "--nofs", "--posterize=2"};

private final String mapFolderPath;

// Numbers that are divisible by 8160 without remainder
private Map<Integer, Integer> zoomFactors = new HashMap<Integer, Integer>() {
{
Expand All @@ -43,19 +43,30 @@ public class Render {
}
};

private Render(String mapFolderPath) {
this.mapFolderPath = mapFolderPath;
private void run() throws Exception {
File revisions = new File(".revisions");
Files.lines(revisions.toPath()).forEach(line -> {
String revision = line.split(" ")[1];
try {
new ProcessBuilder("git", "checkout", revision).directory(new File(REPO_PATH)).start().waitFor();
System.out.print("Rendering for " + revision + "...");
render("data/maps/" + revision);
System.out.println(" Done!");
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}

private void run() throws Exception {
private void render(String mapFolderPath) throws Exception {
BufferedImage generatedImg = generateMapImage();

for (Map.Entry<Integer, Integer> entry : zoomFactors.entrySet()) {
Integer zoom = entry.getKey();
Integer zoomFactor = entry.getValue();

File zoomFolder = new File(mapFolderPath + "/" + zoom);
zoomFolder.mkdir();
zoomFolder.mkdirs();

createSubImages(generatedImg, zoomFolder.getPath(), zoomFactor, scaleFactors.get(zoom));
}
Expand Down Expand Up @@ -136,6 +147,6 @@ private boolean isBlankImage(BufferedImage img) throws Exception {
}

public static void main(String[] args) throws Exception {
new Render(args[0]).run();
new Render().run();
}
}
2 changes: 1 addition & 1 deletion server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tasks {
withType<ShadowJar> {
archiveFileName.set("${rootProject.name}.jar")
manifest {
attributes("Main-Verticle" to "io.github.spair.tauwebmap.MainVerticle")
attributes("Main-Verticle" to "io.github.spair.tauwebmap.ViewVerticle")
}
}
}
Expand Down
44 changes: 0 additions & 44 deletions server/src/main/kotlin/io/github/spair/tauwebmap/MainVerticle.kt

This file was deleted.

60 changes: 0 additions & 60 deletions server/src/main/kotlin/io/github/spair/tauwebmap/MapVerticle.kt

This file was deleted.

This file was deleted.

39 changes: 11 additions & 28 deletions server/src/main/kotlin/io/github/spair/tauwebmap/ViewVerticle.kt
Original file line number Diff line number Diff line change
@@ -1,37 +1,28 @@
package io.github.spair.tauwebmap

import io.vertx.core.AbstractVerticle
import io.vertx.core.Future
import io.vertx.core.buffer.Buffer
import io.vertx.core.http.HttpHeaders
import io.vertx.core.http.HttpServerResponse
import io.vertx.ext.web.Router
import io.vertx.ext.web.handler.FaviconHandler
import io.vertx.ext.web.handler.StaticHandler
import java.io.File
import java.net.HttpURLConnection

class ViewVerticle : AbstractVerticle() {

private var currentRevision: String? = null
const val REVISIONS_FILE = ".revisions"
const val MAPS_FOLDER = "data/maps"

override fun start(startFuture: Future<Void>) {
vertx.eventBus().localConsumer<String>(EB_VIEW_REVISION_UPDATE) { currentRevision = it.body() }
class ViewVerticle : AbstractVerticle() {

override fun start() {
vertx.createHttpServer().requestHandler(Router.router(vertx).apply {
route().handler(FaviconHandler.create())
route().handler(StaticHandler.create())

get("/revision").handler { ctx ->
if (currentRevision == null) {
ctx.response().setStatusCode(HttpURLConnection.HTTP_NOT_FOUND).end()
} else {
ctx.response().infoTextHeaders().end(currentRevision)
}
}

get("/revision/history").handler { ctx ->
ctx.response().infoTextHeaders().end(Buffer.buffer(javaClass.classLoader.getResource(REVISION_HISTORY_FILE).readBytes()))
get("/revisions").handler { ctx ->
ctx.response()
.putHeader(HttpHeaders.CACHE_CONTROL, "no-cache")
.putHeader(HttpHeaders.CONTENT_TYPE, "text/plain")
.sendFile(REVISIONS_FILE)
}

get("/tiles/:revision/:zoom/:y/:x").handler { ctx ->
Expand All @@ -43,8 +34,7 @@ class ViewVerticle : AbstractVerticle() {
with(ctx.response()) {
putHeader(HttpHeaders.CACHE_CONTROL, "public, max-age=2592000")

val revisionFolderName = if (revision == currentRevision) CURRENT_FOLDER else revision
val tilePath = "$MAPS_FOLDER/$revisionFolderName/$zoom/$y-$x.png"
val tilePath = "$MAPS_FOLDER/$revision/$zoom/$y-$x.png"

if (File(tilePath).exists()) {
sendFile(tilePath)
Expand All @@ -53,13 +43,6 @@ class ViewVerticle : AbstractVerticle() {
}
}
}
}).listen(3000, reporter(startFuture))
}

private fun HttpServerResponse.infoTextHeaders(): HttpServerResponse {
return apply {
putHeader(HttpHeaders.CACHE_CONTROL, "no-cache")
putHeader(HttpHeaders.CONTENT_TYPE, "text/plain")
}
}).listen(3000)
}
}
6 changes: 0 additions & 6 deletions server/src/main/kotlin/io/github/spair/tauwebmap/event_bus.kt

This file was deleted.

12 changes: 0 additions & 12 deletions server/src/main/kotlin/io/github/spair/tauwebmap/file_paths.kt

This file was deleted.

21 changes: 0 additions & 21 deletions server/src/main/kotlin/io/github/spair/tauwebmap/reporter.kt

This file was deleted.

Loading

0 comments on commit 0790a2a

Please sign in to comment.