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

Docker build #81

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
hs_err_pid*
target/
nohup.out

.idea
16 changes: 12 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# syntax=docker/dockerfile:1
FROM maven:eclipse-temurin AS builder

WORKDIR /tmp

COPY src /tmp/src
COPY resources /tmp/resources
COPY static /tmp/static
COPY pom.xml /tmp/pom.xml

RUN mvn -B -f /tmp/pom.xml clean package

FROM ubuntu:latest

Expand All @@ -17,12 +27,10 @@ RUN apt install -y ghostscript pdf2svg texlive-extra-utils

RUN apt install -y openjdk-11-jre

COPY src /app/src
COPY resources /app/resources
COPY static /app/static
COPY pom.xml /app/pom.xml

# Assumes mvn install was run prior to build Dockerfile
ADD target/antlr4-lab-$LAB_VERSION-complete.jar antlr4-lab-$LAB_VERSION-complete.jar
ENTRYPOINT java -jar /app/antlr4-lab-$LAB_VERSION-complete.jar
COPY --from=builder /tmp/target/antlr4-lab-*-complete.jar antlr4-lab-complete.jar
ENTRYPOINT ["java", "-jar", "/app/antlr4-lab-complete.jar"]
EXPOSE 80
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,16 @@ If you are running the server locally on your box, visit [http://localhost/index

### Docker

I created a [Dockerfile](Dockerfile), although I'm not sure how useful it will be to people. This might be useful for deploying in the cloud later.

Here's how to build the docker file:

Docker builds both jar and the image:
```bash
cd antlr4-lab
mvn clean package # has to be built first as docker copies in the jar
docker build --tag antlr4-lab-docker .
docker build -t antlr4-lab .
```

and here's how to use the docker to launch:

To run docker image:
```bash
docker run -p80:80 --rm antlr4-lab-docker
docker run -p 8080:80 antlr4-lab
```

@kaby76 reports the following: Seems to work fine. But I had to do some things to get it to work on Windows/WSL2.

In Windows: Install Docker Desktop

In WSL2/Ubuntu:
Expand Down
47 changes: 11 additions & 36 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>9</version>
</parent>

<groupId>org.antlr</groupId>
<artifactId>antlr4-lab</artifactId>
Expand Down Expand Up @@ -47,55 +42,35 @@
<artifactId>antlr4</artifactId>
<version>4.13.1</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>ST4</artifactId>
<version>4.3.4</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>11.0.11</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>11.0.11</version>
<version>11.0.18</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.8.0-beta4</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.11</version>
<artifactId>logback-classic</artifactId>
<version>1.4.11</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.6</version>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>us.parr</groupId>
<artifactId>parrtlib</artifactId>
<version>0.5-SNAPSHOT</version>
<version>0.4</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
<version>2.10.1</version>
</dependency>
</dependencies>
<build>
Expand Down
3 changes: 2 additions & 1 deletion resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
</appender>
<logger name="org.antlr.v4.server.ANTLRHttpServer" level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
</logger>

<root level="ERROR">
<appender-ref ref="STDOUT" />
</root>
</configuration>
</configuration>
6 changes: 5 additions & 1 deletion src/org/antlr/v4/server/GrammarProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.Tree;
import org.antlr.v4.tool.*;
import us.parr.lib.ParrtSys;

import static org.antlr.v4.gui.Interpreter.profilerColumnNames;
import static org.antlr.v4.server.ANTLRHttpServer.IMAGES_DIR;
import static org.antlr.v4.server.ANTLRHttpServer.ParseServlet.LOGGER;
import static us.parr.lib.ParrtSys.execInDir;

import java.io.*;
import java.nio.file.Files;
Expand Down Expand Up @@ -259,6 +259,10 @@ public static String toSVG(Tree t, List<String> ruleNames) throws IOException {
return svg;
}

private static String[] execInDir(String imagesDir, String program, String... args) {
return ParrtSys.exec("env --chdir=" + imagesDir + " " + program + " " + String.join(" ", args));
}

public static final int nodeCount(Tree t) {
if (t == null) {
return 0;
Expand Down