Skip to content

Commit 264344b

Browse files
committed
feat: docker, --force, move bsdiff libs, env vars for java home
fix: a bunch of issues with extracting jars
1 parent a666514 commit 264344b

8 files changed

+208
-50
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
config.toml
2+
target
3+
run
4+
.git
5+
.idea

Cargo.lock

+86-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ log = "0.4.22"
1818
env_logger = "0.11.5"
1919
tracing-subscriber = "0.3.18"
2020
chrono = "0.4.38"
21-
bsdiff = "0.2.0"
2221
zip = "2.2.0"
23-
bzip2 = { version = "0.4", features = [] }
2422
toml = "0.8.19"
2523
sha1 = "0.10.6"
2624
hex = "0.4.3"
2725
clap = { version = "4.5.21", features = ["derive"] }
26+
qbsdiff = "1.4.2"
27+
bzip2 = "0.4.4"

Dockerfile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM rust:bookworm
2+
3+
# avoid any prompts
4+
ARG DEBIAN_FRONTEND=noninteractive
5+
6+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
7+
8+
RUN apt-get update && apt-get install -y --no-install-recommends \
9+
wget \
10+
curl \
11+
gnupg \
12+
lsb-release \
13+
ca-certificates \
14+
unzip \
15+
build-essential \
16+
libssl-dev \
17+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
18+
19+
# temurin 8
20+
RUN wget -qO- 'https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u432-b06/OpenJDK8U-jdk_x64_linux_hotspot_8u432b06.tar.gz' | tar -xz -C /opt/
21+
# temurin 16
22+
RUN wget -qO- 'https://github.com/adoptium/temurin16-binaries/releases/download/jdk-16.0.2%2B7/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz' | tar -xz -C /opt/
23+
# temurin 17
24+
RUN wget -qO- 'https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.13%2B11/OpenJDK17U-jdk_x64_linux_hotspot_17.0.13_11.tar.gz' | tar -xz -C /opt/
25+
# temurin 21
26+
RUN wget -qO- 'https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.5%2B11/OpenJDK21U-jdk_x64_linux_hotspot_21.0.5_11.tar.gz' | tar -xz -C /opt/
27+
28+
ENV JAVA_HOME_8=/opt/jdk8u432-b06
29+
ENV JAVA_HOME_16=/opt/jdk-16.0.2+7
30+
ENV JAVA_HOME_17=/opt/jdk-17.0.13+11
31+
ENV JAVA_HOME_21=/opt/jdk-21.0.5+11
32+
33+
WORKDIR /app
34+
35+
COPY . .
36+
37+
RUN cargo install --path .
38+
39+
CMD ["bin_patch_gen", "-v", "1.21.3"]

docker-compose.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
gen:
3+
container_name: sploon-bin-patch-gen
4+
build: .
5+
volumes:
6+
- ./config.toml:/app/config.toml
7+
- /tmp/bpg:/tmp/bin-patch-gen
8+
mem_limit: 2G

src/build_tools.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use regex::Regex;
99
use crate::util::dir;
1010

1111
/// The URL of the latest BuildTools JAR build from SpigotMC's Jenkins.
12-
pub const VANILLA_JAR_REGEX: &str = r"minecraft_server.(1\.\d{1,2}(?:\.\d{1,2})?)\.jar";
12+
pub const VANILLA_JAR_REGEX: &str = r"(minecraft_)?server.(1\.\d{1,2}(?:\.\d{1,2})?)\.jar";
1313
const BUILDTOOLS_URL: &str = "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar";
1414
const SPIGOT_JAR_REGEX: &str = r"spigot-(1\.\d{1,2}(?:\.\d{1,2})?)\.jar";
1515

src/lib.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use crate::util::dir;
2-
use bzip2::write::BzEncoder;
3-
use bzip2::Compression;
42
use futures_util::StreamExt;
3+
use qbsdiff::Bsdiff;
54
use reqwest::IntoUrl;
65
use scraper::Html;
76
use std::fmt::Display;
87
use std::fs::File;
9-
use std::io::{Read, Write};
8+
use std::io::{Cursor, Read, Write};
109
use std::path::Path;
1110
use std::{fs, io};
1211

@@ -89,7 +88,7 @@ pub async fn fetch_url<U: IntoUrl>(url: U) -> Reqwsult<Html> {
8988
pub fn write_patch<P, P1>(vanilla_jar: P, spigot_jar: P, out: P1) -> io::Result<()>
9089
where
9190
P: AsRef<Path>,
92-
P1: AsRef<Path>
91+
P1: AsRef<Path>,
9392
{
9493
let mut vanilla = File::open(vanilla_jar)?;
9594
let mut vanilla_bytes = Vec::new();
@@ -100,14 +99,12 @@ where
10099
spigot.read_to_end(&mut spigot_bytes)?;
101100

102101
let mut diff = Vec::new();
103-
bsdiff::diff(&vanilla_bytes, &spigot_bytes, &mut diff)?;
104102

105-
let mut encoder = BzEncoder::new(Vec::new(), Compression::best());
106-
encoder.write_all(&diff)?;
103+
Bsdiff::new(&vanilla_bytes, &spigot_bytes)
104+
.compression_level(9)
105+
.compare(Cursor::new(&mut diff))?;
107106

108-
let compressed = encoder.finish()?;
109-
110-
fs::write(out, compressed)
107+
fs::write(out, diff)
111108
}
112109

113110
pub struct MinecraftVersion(u8, u8, u8);
@@ -129,15 +126,15 @@ impl MinecraftVersion {
129126

130127
pub fn get_java_version(&self) -> u8 {
131128
if self.1 < 17 {
132-
return 8
129+
return 8;
133130
}
134131

135132
if self.1 == 17 {
136-
return 16
133+
return 16;
137134
}
138135

139136
if self.1 < 20 && self.2 < 5 {
140-
return 17
137+
return 17;
141138
}
142139

143140
21

0 commit comments

Comments
 (0)