From 9fa434922aa9c5844c615759d8c6e5172068bc2a Mon Sep 17 00:00:00 2001 From: Rahman Yusuf Date: Thu, 6 Jun 2024 22:23:35 +0700 Subject: [PATCH] Make main docker image as minimal as possible to prevent big size image --- .github/workflows/build.yml | 38 +++++++++++++++++++++++++++++++--- .github/workflows/build_pr.yml | 16 +++++++++++++- Dockerfile | 16 +------------- Dockerfile.optional | 28 +++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 19 deletions(-) create mode 100644 Dockerfile.optional diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 91f36d0e..4e437e7d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,10 @@ on: env: TEST_TAG: mansuf/mangadex-downloader:test + TEST_OPTIONAL_TAG: mansuf/mangadex-downloader:test-optional LATEST_TAG: mansuf/mangadex-downloader:latest + LATEST_OPTIONAL_TAG: mansuf/mangadex-downloader:latest-optional + jobs: docker: @@ -36,13 +39,25 @@ jobs: context: . load: true tags: ${{ env.TEST_TAG }} + + - name: Build and export to Docker (with optional dependencies) + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile.optional + load: true + tags: ${{ env.TEST_OPTIONAL_TAG }} - - name: Test + - name: Test docker image run: | docker run --rm ${{ env.TEST_TAG }} + - name: Test + run: | + docker run --rm ${{ env.TEST_OPTIONAL_TAG }} + - name: Update Docker Hub description - if: startsWith(github.ref, 'refs/tags/') && github.repository == 'mansuf/mangadex-downloader' + # if: startsWith(github.ref, 'refs/tags/') && github.repository == 'mansuf/mangadex-downloader' uses: peter-evans/dockerhub-description@v4 with: username: ${{ secrets.DOCKER_USERNAME }} @@ -51,7 +66,7 @@ jobs: short-description: ${{ github.event.repository.description }} - name: Build and push - if: startsWith(github.ref, 'refs/tags/') && github.repository == 'mansuf/mangadex-downloader' + # if: startsWith(github.ref, 'refs/tags/') && github.repository == 'mansuf/mangadex-downloader' uses: docker/build-push-action@v5 with: context: . @@ -63,6 +78,23 @@ jobs: tags: | ${{ env.LATEST_TAG }} mansuf/mangadex-downloader:${{ github.ref_name }} + mansuf/mangadex-downloader:v2.10.3 + + - name: Build and push (with optional dependencies) + # if: startsWith(github.ref, 'refs/tags/') && github.repository == 'mansuf/mangadex-downloader' + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile.optional + platforms: | + linux/amd64 + linux/arm64 + linux/arm/v7 + push: true + tags: | + ${{ env.LATEST_OPTIONAL_TAG }} + mansuf/mangadex-downloader:${{ github.ref_name }}-optional + mansuf/mangadex-downloader:v2.10.3-optional windows-build: name: Build app & docs (Windows) diff --git a/.github/workflows/build_pr.yml b/.github/workflows/build_pr.yml index 196b5c48..3b83137d 100644 --- a/.github/workflows/build_pr.yml +++ b/.github/workflows/build_pr.yml @@ -9,7 +9,9 @@ on: env: TEST_TAG: mansuf/mangadex-downloader:test + TEST_OPTIONAL_TAG: mansuf/mangadex-downloader:test-optional LATEST_TAG: mansuf/mangadex-downloader:latest + LATEST_OPTIONAL_TAG: mansuf/mangadex-downloader:latest-optional jobs: docker: @@ -31,10 +33,22 @@ jobs: context: . load: true tags: ${{ env.TEST_TAG }} + + - name: Build and export to Docker (with optional dependencies) + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile.optional + load: true + tags: ${{ env.TEST_OPTIONAL_TAG }} + - name: Test docker image + run: | + docker run --rm ${{ env.TEST_TAG }} + - name: Test run: | - docker run --rm ${{ env.TEST_TAG }} + docker run --rm ${{ env.TEST_OPTIONAL_TAG }} windows-build: name: Build app & docs (Windows) diff --git a/Dockerfile b/Dockerfile index 71e77a60..db5a4226 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,23 +3,9 @@ FROM python:3.11 COPY . /app WORKDIR /app -# Setup rust -RUN apt update && apt install wget -ENV RUSTUP_HOME=/usr/local/rustup \ - CARGO_HOME=/usr/local/cargo \ - PATH=/usr/local/cargo/bin:$PATH \ - RUST_VERSION=1.78.0 -RUN wget https://sh.rustup.rs -O rustup.sh -RUN chmod +x ./rustup.sh -RUN ./rustup.sh -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION -RUN chmod -R a+w $RUSTUP_HOME $CARGO_HOME; -RUN rustup --version; -RUN cargo --version; -RUN rustc --version; - # Install mangadex-downloader RUN pip install --upgrade pip -RUN pip install .[optional] +RUN pip install . WORKDIR /downloads diff --git a/Dockerfile.optional b/Dockerfile.optional new file mode 100644 index 00000000..71e77a60 --- /dev/null +++ b/Dockerfile.optional @@ -0,0 +1,28 @@ +FROM python:3.11 + +COPY . /app +WORKDIR /app + +# Setup rust +RUN apt update && apt install wget +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH \ + RUST_VERSION=1.78.0 +RUN wget https://sh.rustup.rs -O rustup.sh +RUN chmod +x ./rustup.sh +RUN ./rustup.sh -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION +RUN chmod -R a+w $RUSTUP_HOME $CARGO_HOME; +RUN rustup --version; +RUN cargo --version; +RUN rustc --version; + +# Install mangadex-downloader +RUN pip install --upgrade pip +RUN pip install .[optional] + +WORKDIR /downloads + +ENTRYPOINT [ "mangadex-downloader" ] + +CMD [ "--help" ] \ No newline at end of file