Skip to content

Commit

Permalink
Build linux binary myself
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherp committed Jan 21, 2023
1 parent 70eed43 commit 5432242
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/buildNative.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ jobs:
cache: 'maven'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: "Install all with Maven"
- name: "Install all with Maven"

run: mvn --batch-mode clean install -DskipTests -T 1C
run: mvn --batch-mode clean install -pl !org.nzbhydra:linux-release,!org.nzbhydra:windows-release,!org.nzbhydra:generic-release -DskipTests -T 1C
- name: "Run unit tests"
run: mvn --batch-mode test -T 1C -pl !org.nzbhydra:tests,!org.nzbhydra.tests:system --fail-at-end

Expand Down
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/src/main/resources/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
changes:
- type: "feature"
text: "Include service scripts for windows and linux in generic release"
- type: "feature"
text: "The previously compiled binaries did not start on all linux distros. I switched to an older distro to compile the binary so it hopefully is also runnable on older distros."
final: true
- version: "v5.0.4"
date: "2023-01-22"
Expand Down
17 changes: 8 additions & 9 deletions misc/build-and-release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ if (-not $?) {
exit 1
}

Read-Host -Prompt "nzbhydra.exe didn't work before. Have you made sure it works?"

Write-Host "Generating changelog"
exec { mvn -q -B org.nzbhydra:github-release-plugin:3.0.0:generate-changelog }
if (-not $?) {
Expand Down Expand Up @@ -166,6 +164,12 @@ if (-not $?) {
exit 1
}

$genericVersion = java -jar releases/generic-release/include/core-$version-exec.jar -version
if ($genericVersion -ne $version) {
Write-Error "Generic version $version expected but is $genericVersion"
exit 1
}

Write-Host "Building windows executable"
try {
.\buildCore.cmd
Expand All @@ -181,13 +185,8 @@ if ($windowsVersion -ne $version) {
exit 1
}

$genericVersion = java -jar releases/generic-release/include/core-$version-exec.jar -version
if ($genericVersion -ne $version) {
Write-Error "Generic version $version expected but is $genericVersion"
exit 1
}

Read-Host -Prompt "Wait for build to finish on pipeline. Copy linux executable to include folder. Press enter to continue"
Write-Host "Building linux executable"
wsl -d Ubuntu -- sh -c ./misc/buildLinuxCore/buildLinuxCore.sh

$linuxVersion = wsl -d Ubuntu releases/linux-release/include/core -version
if ($linuxVersion -ne $version) {
Expand Down
4 changes: 4 additions & 0 deletions misc/buildLinuxCore/buildDockerImage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# Builds the docker image which is used to build the linux core executable

docker build -t hydrabuild .
7 changes: 7 additions & 0 deletions misc/buildLinuxCore/buildInContainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
#Is run in the docker image to actually build the linux executable

cd /nzbhydra2 || exit
mvn --batch-mode clean install -pl \!org.nzbhydra:linux-release,\!org.nzbhydra:windows-release,\!org.nzbhydra:generic-release -DskipTests -T 1C
mvn -pl org.nzbhydra:core -Pnative clean native:compile -DskipTests
/upx-4.0.1-amd64_linux/upx -3 core/target/core
18 changes: 18 additions & 0 deletions misc/buildLinuxCore/buildLinuxCore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Prepares and runs the docker container to build the core executable

if [[ ! -d "${PWD}/core" ]] ; then
echo "${PWD}/core not found "
return
fi

echo rsync -rvu --exclude "target" --exclude "bower_components" --exclude "node_modules" --exclude ".git" --exclude ".idea" --exclude "results" --exclude "*.db" --exclude "venv*" ${PWD}/ ~/nzbhydra2/

docker run -v ~/nzbhydra2/:/nzbhydra2:rw -v ~/.m2/repository:/root/.m2/repository:rw --rm hydrabuild:latest
if [[ ! -f ~/nzbhydra2/core/target/core ]] ; then
echo "core executable does not exist"
else
cp ~/nzbhydra2/core/target/core ${PWD}/core/target/
cp ~/nzbhydra2/core/target/core ${PWD}/releases/linux-release/include/
fi
31 changes: 31 additions & 0 deletions misc/buildLinuxCore/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# alpine doesn't work because we need libgc for the native image
FROM ubuntu:16.04
# See https://octopus.com/blog/using-ubuntu-docker-image
RUN echo 'APT::Install-Suggests "0";' >> /etc/apt/apt.conf.d/00-docker
RUN echo 'APT::Install-Recommends "0";' >> /etc/apt/apt.conf.d/00-docker
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y zip unzip wget curl libfreetype6 libfreetype6-dev build-essential ca-certificates
RUN wget -nv --no-check-certificate https://dlcdn.apache.org/maven/maven-3/3.8.7/binaries/apache-maven-3.8.7-bin.tar.gz -P /tmp

RUN tar xf /tmp/apache-maven-*.tar.gz -C /opt
RUN ln -s /opt/apache-maven-3.8.7 /opt/maven
ENV M2_HOME=/opt/maven
ENV MAVEN_HOME=/opt/maven
ENV PATH=${M2_HOME}/bin:${PATH}

RUN wget -nv --no-check-certificate https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.0/graalvm-ce-java17-linux-amd64-22.3.0.tar.gz
RUN tar xzf graalvm-ce-java17-linux-amd64-22.3.0.tar.gz -C /
ENV PATH=/graalvm-ce-java17-22.3.0/bin/:$PATH
ENV JAVA_HOME=/graalvm-ce-java17-22.3.0

RUN wget -nv --no-check-certificate https://github.com/upx/upx/releases/download/v4.0.1/upx-4.0.1-amd64_linux.tar.xz
RUN tar -xf upx-4.0.1-amd64_linux.tar.xz
ENV PATH=/tmp/upx-4.0.1-amd64_linux/:$PATH

ENV HYDRA_NATIVE_BUILD=true

COPY buildInContainer.sh /

ENTRYPOINT /buildInContainer.sh

# To debug docker run --rm -it --entrypoint bash hydrabuild
# or for a running container docker exec -it <container-name-or-id> bash
12 changes: 12 additions & 0 deletions misc/rsyncAndStartGraalvmDocker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

if [[ -f core ]] ; then
cd ..
fi
if [[ -f core ]] ; then
echo "core folder not found"
exit 1
fi

rsync -rvu --exclude "target" --exclude "bower_components" --exclude "node_modules" --exclude ".git" --exclude ".idea" --exclude "results" --exclude "*.db" --exclude "venv*" . ~/nzbhydra2/
docker run -v ~/.m2/repository:/root/.m2/repository:rw -v ~/nzbhydra2:/nzbhydra2 -it --rm vegardit/graalvm-maven:22.3.0-java17 bash
1 change: 0 additions & 1 deletion misc/rsyncToHome.sh

This file was deleted.

14 changes: 14 additions & 0 deletions nativeNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,17 @@ If anything fails you can always switch back to the old folder or docker image u



apt update
apt install -y zip unzip wget curl libfreetype6 libfreetype6-dev apt-get install build-essential
wget https://dlcdn.apache.org/maven/maven-3/3.8.7/binaries/apache-maven-3.8.7-bin.tar.gz -P /tmp
tar xf /tmp/apache-maven-*.tar.gz -C /opt
ln -s /opt/apache-maven-3.8.7 /opt/maven
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
curl -s "https://get.sdkman.io" | bash
source "/root/.sdkman/bin/sdkman-init.sh"
sdk install java 22.3.r17-grl
mvn --batch-mode clean install -DskipTests -T 1C
export HYDRA_NATIVE_BUILD=true
mvn -pl org.nzbhydra:core -Pnative clean native:compile -DskipTests

0 comments on commit 5432242

Please sign in to comment.