Skip to content

Commit

Permalink
feature/local dockerfile build (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhonny0007 authored Jul 16, 2024
1 parent 412d9e5 commit 6fdc4fb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v5
with:
context: docker
context: .
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
provenance: false
push: true
Expand Down
74 changes: 40 additions & 34 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,54 @@ ARG UNRAR7_NATIVE=false
ARG MAKE_JOBS=1
ARG TARGETPLATFORM

#install build packages
RUN \
echo "**** install build packages ****" && \
apk add g++ gcc git libxml2-dev libxslt-dev make ncurses-dev openssl-dev boost-dev curl cmake && \
apk add g++ gcc git libxml2-dev libxslt-dev make ncurses-dev openssl-dev boost-dev curl cmake

#install archive packages
RUN \
echo "**** install unrar7 from source ****" && \
mkdir /tmp/unrar7 && \
curl -o /tmp/unrar7.tar.gz -L "https://www.rarlab.com/rar/unrarsrc-${UNRAR7_VERSION}.tar.gz" && \
tar xf /tmp/unrar7.tar.gz -C /tmp/unrar7 --strip-components=1 && \
cd /tmp/unrar7 && \
if [ "${UNRAR7_NATIVE}" != "true" ] && [ "${TARGETPLATFORM}" == "linux/amd64" ]; \
then sed -i "s|CXXFLAGS=-march=native|CXXFLAGS=-march=x86-64-v2|" makefile; fi && \
if [ "${UNRAR7_NATIVE}" != "true" ] && [ "${TARGETPLATFORM}" == "linux/arm64" ]; \
then sed -i "s|CXXFLAGS=-march=native|CXXFLAGS=-march=armv8-a+crypto+crc|" makefile; fi && \
if [ "${UNRAR7_NATIVE}" != "true" ] && [ "${TARGETPLATFORM}" == "linux/arm/v7" ]; \
then sed -i "s|CXXFLAGS=-march=native|CXXFLAGS=-march=armv7-a|" makefile; fi && \
make -j ${MAKE_JOBS} && \
install -v -m755 unrar /usr/bin/unrar7 && \
echo "**** install unrar6 from source ****" && \
mkdir /tmp/unrar6 && \
curl -o /tmp/unrar6.tar.gz -L "https://www.rarlab.com/rar/unrarsrc-${UNRAR6_VERSION}.tar.gz" && \
tar xf /tmp/unrar6.tar.gz -C /tmp/unrar6 --strip-components=1 && \
cd /tmp/unrar6 && \
make -j ${MAKE_JOBS} && \
install -v -m755 unrar /usr/bin/

#build nzbget
ADD ./ nzbget
RUN \
echo "**** build nzbget ****" && \
mkdir -p /app/nzbget && \
git clone https://github.com/nzbgetcom/nzbget.git nzbget && \
cd nzbget/ && \
git checkout ${NZBGET_RELEASE} && \
mkdir -p build && \
cd build && \
mkdir -p /nzbget/build && \
cd /nzbget/build && \
cmake .. -DCMAKE_INSTALL_PREFIX=/app/nzbget && \
cmake --build . -j ${MAKE_JOBS} && \
cmake --install . && \
mv /app/nzbget/bin/nzbget /app/nzbget/ && \
rm -rf /app/nzbget/bin/ && \
rm -rf /app/nzbget/etc/ && \
mv /app/nzbget/share/nzbget/webui /app/nzbget/ && \
cp /app/nzbget/share/nzbget/nzbget.conf /app/nzbget/webui/nzbget.conf.template && \
cp /nzbget/pubkey.pem /app/nzbget/pubkey.pem && \
curl -o /app/nzbget/cacert.pem -L "https://curl.se/ca/cacert.pem"

#change default configvalues
RUN \
sed -i \
-e "s|^MainDir=.*|MainDir=/downloads|g" \
-e "s|^ScriptDir=.*|ScriptDir=$\{MainDir\}/scripts|g" \
Expand All @@ -38,33 +70,7 @@ RUN \
-e "s|^InterDir=.*|InterDir=$\{MainDir\}/intermediate|g" \
-e "s|^LogFile=.*|LogFile=$\{MainDir\}/nzbget.log|g" \
-e "s|^AuthorizedIP=.*|AuthorizedIP=127.0.0.1|g" \
/app/nzbget/share/nzbget/nzbget.conf && \
mv /app/nzbget/share/nzbget/webui /app/nzbget/ && \
cp /app/nzbget/share/nzbget/nzbget.conf /app/nzbget/webui/nzbget.conf.template && \
ln -s /usr/bin/7z /app/nzbget/7za && \
ln -s /usr/bin/unrar /app/nzbget/unrar && \
cp /nzbget/pubkey.pem /app/nzbget/pubkey.pem && \
curl -o /app/nzbget/cacert.pem -L "https://curl.se/ca/cacert.pem" && \
echo "**** install unrar7 from source ****" && \
mkdir /tmp/unrar7 && \
curl -o /tmp/unrar7.tar.gz -L "https://www.rarlab.com/rar/unrarsrc-${UNRAR7_VERSION}.tar.gz" && \
tar xf /tmp/unrar7.tar.gz -C /tmp/unrar7 --strip-components=1 && \
cd /tmp/unrar7 && \
if [ "${UNRAR7_NATIVE}" != "true" ] && [ "${TARGETPLATFORM}" == "linux/amd64" ]; \
then sed -i "s|CXXFLAGS=-march=native|CXXFLAGS=-march=x86-64-v2|" makefile; fi && \
if [ "${UNRAR7_NATIVE}" != "true" ] && [ "${TARGETPLATFORM}" == "linux/arm64" ]; \
then sed -i "s|CXXFLAGS=-march=native|CXXFLAGS=-march=armv8-a+crypto+crc|" makefile; fi && \
if [ "${UNRAR7_NATIVE}" != "true" ] && [ "${TARGETPLATFORM}" == "linux/arm/v7" ]; \
then sed -i "s|CXXFLAGS=-march=native|CXXFLAGS=-march=armv7-a|" makefile; fi && \
make -j ${MAKE_JOBS} && \
install -v -m755 unrar /usr/bin/unrar7 && \
echo "**** install unrar6 from source ****" && \
mkdir /tmp/unrar6 && \
curl -o /tmp/unrar6.tar.gz -L "https://www.rarlab.com/rar/unrarsrc-${UNRAR6_VERSION}.tar.gz" && \
tar xf /tmp/unrar6.tar.gz -C /tmp/unrar6 --strip-components=1 && \
cd /tmp/unrar6 && \
make -j ${MAKE_JOBS} && \
install -v -m755 unrar /usr/bin/
/app/nzbget/share/nzbget/nzbget.conf

# runtime stage
FROM alpine:3.19.1
Expand All @@ -85,7 +91,7 @@ RUN \
COPY --from=build /usr/bin/unrar /usr/bin/unrar
COPY --from=build /usr/bin/unrar7 /usr/bin/unrar7
COPY --from=build /app/nzbget/ /app/nzbget/
ADD entrypoint.sh /entrypoint.sh
ADD docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh && \
echo "**** create non-root user ****" && \
adduser -G users -D -u 1000 -h /config -s /bin/sh user && \
Expand Down
6 changes: 3 additions & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ uid=1000(user) gid=1000(users) groups=1000(users)

# Building locally

For development purposes can be used Dockerfile or docker-compose file from official repository (`docker` folder):
For development purposes the Docker Image can be build using the locally cloned repository (`docker` folder):

```
git clone https://github.com/nzbgetcom/nzbget.git
cd docker
docker compose up
docker compose -f docker/docker-compose.yml up --build
-or-
cd docker
docker build . -t nzbget-local
```

Expand Down
3 changes: 2 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
services:
nzbget:
build:
context: .
context: ../
dockerfile: docker/Dockerfile
args:
NZBGET_RELEASE: develop
MAKE_JOBS: 4
Expand Down

0 comments on commit 6fdc4fb

Please sign in to comment.