Skip to content

Commit

Permalink
fixed host forwarding and added docker CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbe Louwet committed Mar 16, 2024
1 parent 3a47ad2 commit d8ea389
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v2

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'gradle'

- name: Build with Gradle
run: ./gradlew build

# Registry login
- name: Login to Docker Hub
run: docker login -u ${{ secrets.DOCKER_REGISTRY_USERNAME }} -p ${{ secrets.DOCKER_REGISTRY_PASSWORD }}

# Publish velocity-dedicated
- name: Build and Push velocity-dedicated
run: |
docker build -t robbelouwet/velocity-dedicated docker
docker push robbelouwet/velocity-dedicated
20 changes: 20 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM --platform=linux/amd64 ubuntu:latest

EXPOSE 25565/tcp
EXPOSE 25565/udp

WORKDIR /

COPY ./entrypoint.sh /entrypoint.sh
COPY ../proxy/build/libs/*-all.jar /velocity.jar

COPY ./template-files/* /

RUN apt-get update && apt-get install -y wget git openjdk-17-jre perl

RUN wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 &&\
chmod a+x /usr/local/bin/yq

# RUN wget -P / https://api.papermc.io/v2/projects/velocity/versions/3.2.0-SNAPSHOT/builds/294/downloads/velocity-3.2.0-SNAPSHOT-294.jar

CMD [ "/bin/bash", "-c", "/entrypoint.sh" ]
13 changes: 13 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

echo "JVM_ARGS: ${JVM_ARGS}"

# Inject hostnames of backed server instances
#perl -i -pe 's/(paper1\s*=\s*")[^"]*(")/\1$ENV{"PAPER1_HOST"}\2/' /data/velocity.toml
#perl -i -pe 's/(paper2\s*=\s*")[^"]*(")/\1$ENV{"PAPER2_HOST"}\2/' /data/velocity.toml

# Inject velocity secret
echo "$VELOCITY_SECRET" > /forwarding.secret

# Run the server
java $JVM_ARGS -XX:+UseG1GC -XX:G1HeapRegionSize=4M -XX:+UnlockExperimentalVMOptions -XX:+ParallelRefProcEnabled -XX:+AlwaysPreTouch -XX:MaxInlineLevel=15 -jar /velocity*.jar
Original file line number Diff line number Diff line change
Expand Up @@ -861,13 +861,10 @@ private Optional<RegisteredServer> getNextServerToTry(@Nullable RegisteredServer
}

private Optional<RegisteredServer> getPrivateForwardedServer() {
String[] splitHostname = getVirtualHost().get().getHostName().split("\\.", 2);
String hostname = splitHostname[0] + ".private." + splitHostname[1];

logger.debug("forward-private-host enabled, forwarding to: " + hostname + ":25565");
String hostname = getVirtualHost().get().getHostName();

return Optional.of(new VelocityRegisteredServer(
server, new ServerInfo("forward-private-backend", new InetSocketAddress(hostname, 25565))));
server, new ServerInfo(hostname, new InetSocketAddress(hostname, 25565))));
}

private static boolean hasSameName(RegisteredServer server, String name) {
Expand Down

0 comments on commit d8ea389

Please sign in to comment.