From 6fdc4fb90f910469c5568871e16d6437f5a9f395 Mon Sep 17 00:00:00 2001 From: Jhonny0007 Date: Tue, 16 Jul 2024 10:48:29 +0200 Subject: [PATCH] feature/local dockerfile build (#305) --- .github/workflows/docker.yml | 3 +- docker/Dockerfile | 74 +++++++++++++++++++----------------- docker/README.md | 6 +-- docker/docker-compose.yml | 3 +- 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0b71377ff..37275733a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -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 diff --git a/docker/Dockerfile b/docker/Dockerfile index c5ae1ed63..ffcbc2f8b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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" \ @@ -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 @@ -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 && \ diff --git a/docker/README.md b/docker/README.md index dd9add3bf..253a456c4 100644 --- a/docker/README.md +++ b/docker/README.md @@ -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 ``` diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 6e5a88370..b5177b4b5 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -2,7 +2,8 @@ services: nzbget: build: - context: . + context: ../ + dockerfile: docker/Dockerfile args: NZBGET_RELEASE: develop MAKE_JOBS: 4