From 1a48a3eea998e51fd0f4151885c0f9c0143b5f45 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Wed, 4 Jun 2025 19:53:55 +0300 Subject: [PATCH] improve the build process --- .github/workflows/main.yml | 21 ++++++--------------- Dockerfile | 7 +++++-- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index df12f2a0..ef2964c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -45,7 +45,7 @@ on: env: DOCKERHUB_SLUG: arabcoders/ytptube GHCR_SLUG: ghcr.io/arabcoders/ytptube - PLATFORMS: linux/amd64 + PLATFORMS: linux/amd64,linux/arm64 PNPM_VERSION: 10 NODE_VERSION: 20 @@ -67,7 +67,7 @@ jobs: with: node-version: ${{ env.NODE_VERSION }} cache: pnpm - cache-dependency-path: 'ui/pnpm-lock.yaml' + cache-dependency-path: "ui/pnpm-lock.yaml" - name: Install frontend dependencies & Build working-directory: ui @@ -87,8 +87,8 @@ jobs: context: . platforms: linux/amd64 push: false - cache-from: type=gha, scope=pr_${{ github.workflow }} - cache-to: type=gha, scope=pr_${{ github.workflow }} + cache-from: type=gha, scope=${{ github.workflow }} + cache-to: type=gha, mode=max, scope=${{ github.workflow }} push-build: runs-on: ubuntu-latest @@ -110,7 +110,7 @@ jobs: with: node-version: ${{ env.NODE_VERSION }} cache: pnpm - cache-dependency-path: 'ui/pnpm-lock.yaml' + cache-dependency-path: "ui/pnpm-lock.yaml" - name: Install frontend dependencies & Build working-directory: ui @@ -132,15 +132,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Set Platforms Based on Branch - id: set_platforms - run: | - if [ "${GITHUB_REF}" == "refs/heads/${{ github.repository.default_branch }}" ]; then - echo "PLATFORMS=linux/amd64,linux/arm64" >> $GITHUB_ENV - else - echo "PLATFORMS=linux/amd64" >> $GITHUB_ENV - fi - - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -178,7 +169,7 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha, scope=${{ github.workflow }} - cache-to: type=gha, scope=${{ github.workflow }} + cache-to: type=gha, mode=max, scope=${{ github.workflow }} - name: Version tag uses: arabcoders/action-python-autotagger@master diff --git a/Dockerfile b/Dockerfile index 54f01d25..7fe41515 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,9 @@ +# syntax=docker/dockerfile:1.4 FROM node:lts-alpine AS node_builder WORKDIR /app COPY ui ./ -RUN if [ ! -f "/app/exported/index.html" ]; then pnpm install --production --prefer-offline --frozen-lockfile && pnpm run generate; else echo "Skipping UI build, already built."; fi +RUN if [ ! -f "/app/exported/index.html" ]; then npm install --production --prefer-offline --frozen-lockfile && npm run generate; else echo "Skipping UI build, already built."; fi FROM python:3.13-alpine AS python_builder @@ -10,6 +11,8 @@ ENV LANG=C.UTF-8 ENV LC_ALL=C.UTF-8 ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONFAULTHANDLER=1 +ENV PIP_NO_CACHE_DIR=off +ENV PIP_CACHE_DIR=/root/.cache/pip # Use sed to strip carriage-return characters from the entrypoint script (in case building on Windows) # Install dependencies @@ -19,7 +22,7 @@ WORKDIR /app ARG PIPENV_FLAGS="--deploy" COPY ./Pipfile* . -RUN PIPENV_VENV_IN_PROJECT=1 pipenv install ${PIPENV_FLAGS} +RUN --mount=type=cache,target=/root/.cache/pip PIPENV_VENV_IN_PROJECT=1 pipenv install ${PIPENV_FLAGS} FROM python:3.13-alpine