diff --git a/.github/workflows/build-package.yml b/.github/workflows/build-package.yml index 37710766a..b3224d7a9 100644 --- a/.github/workflows/build-package.yml +++ b/.github/workflows/build-package.yml @@ -11,12 +11,18 @@ on: type: string jobs: - build-frontend: - name: Build frontend + build-package: + name: Build frontend and wheel runs-on: ubuntu-latest steps: - - name: Checkout 🛎 + - name: Install Task + uses: arduino/setup-task@v2 + with: + version: 3.x + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Check out repository uses: actions/checkout@v6 with: ref: ${{ inputs.ref || github.sha }} @@ -40,30 +46,6 @@ jobs: run: pnpm generate working-directory: "frontend" - - name: Archive built frontend - uses: actions/upload-artifact@v6 - with: - name: frontend-dist - path: frontend/dist - retention-days: 5 - - build-package: - name: Build Python package - needs: build-frontend - runs-on: ubuntu-latest - - steps: - - name: Install Task - uses: arduino/setup-task@v2 - with: - version: 3.x - repo-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Check out repository - uses: actions/checkout@v6 - with: - ref: ${{ inputs.ref || github.sha }} - - name: Set up python uses: actions/setup-python@v6 with: @@ -72,17 +54,16 @@ jobs: - name: Install uv run: pip install uv - - name: Retrieve built frontend - uses: actions/download-artifact@v6 - with: - name: frontend-dist - path: mealie/frontend + - name: Copy the frontend into the package + run: | + rm -rf mealie/frontend + cp -a frontend/dist mealie/frontend - name: Override __init__.py run: | echo "__version__ = \"${{ inputs.tag }}\"" > ./mealie/__init__.py - - name: Build package and requirements.txt + - name: Build package and requirements files env: SKIP_PACKAGE_DEPS: true run: | diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 6b28377d5..824eedec1 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -19,6 +19,15 @@ jobs: node-version: 24 cache: "pnpm" cache-dependency-path: "**/pnpm-lock.yaml" + - name: Install dependencies + run: pnpm install + # This install takes about 50 seconds and needs nothing the image build + # produces, so the two run at the same time. + - name: Start Playwright browser install + run: | + rm -f /tmp/playwright-install.status + nohup bash -c 'pnpm playwright install --with-deps; echo $? > /tmp/playwright-install.status' \ + > /tmp/playwright-install.log 2>&1 & - name: Set up Docker Buildx uses: docker/setup-buildx-action@v4 - name: Retrieve Python package @@ -39,12 +48,24 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max - name: Deploy E2E Test Environment - run: docker compose up -d + run: | + docker compose up -d --wait + # The mock OIDC server has no shell, so compose cannot health check it. + for _ in $(seq 1 60); do + curl -fsS http://localhost:8080/default/.well-known/openid-configuration > /dev/null && exit 0 + sleep 1 + done + echo "the mock OIDC server did not answer" + exit 1 working-directory: ./tests/e2e/docker - - name: Install dependencies - run: pnpm install - - name: Install Playwright Browsers - run: pnpm playwright install --with-deps + - name: Finish Playwright browser install + run: | + for _ in $(seq 1 300); do + [ -f /tmp/playwright-install.status ] && break + sleep 1 + done + cat /tmp/playwright-install.log + exit "$(cat /tmp/playwright-install.status 2>/dev/null || echo 1)" - name: Check test environment run: docker ps - name: Run Playwright tests diff --git a/.github/workflows/partial-trivy-container-scanning.yml b/.github/workflows/partial-trivy-container-scanning.yml index 197b1755a..c335cfa92 100644 --- a/.github/workflows/partial-trivy-container-scanning.yml +++ b/.github/workflows/partial-trivy-container-scanning.yml @@ -13,9 +13,17 @@ jobs: - name: Checkout code uses: actions/checkout@v6 + - name: Retrieve Python package + uses: actions/download-artifact@v6 + with: + name: backend-dist + path: dist + + # Scan the wheel that the release uses, and not a second copy that this + # job builds. - name: Build Dockerfile run: | - docker build -t mealie --file=./docker/Dockerfile . + docker build -t mealie --file=./docker/Dockerfile --build-context packages=dist . - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@master diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index ba2c48de4..ea15bdf99 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -32,6 +32,7 @@ jobs: container-scanning: name: "Trivy Container Scanning" if: github.event_name == 'pull_request' + needs: build-package uses: ./.github/workflows/partial-trivy-container-scanning.yml code-ql: diff --git a/.github/workflows/test-backend.yml b/.github/workflows/test-backend.yml index 1e062ff04..a595e1220 100644 --- a/.github/workflows/test-backend.yml +++ b/.github/workflows/test-backend.yml @@ -32,11 +32,12 @@ jobs: POSTGRES_USER: mealie POSTGRES_PASSWORD: mealie POSTGRES_DB: mealie - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + options: --health-cmd pg_isready --health-interval 2s --health-timeout 5s --health-retries 15 ports: - 5432:5432 ldap: image: rroemhild/test-openldap + options: --health-interval 2s --health-timeout 5s --health-retries 15 ports: - 10389:10389 - 10636:10636 diff --git a/Taskfile.yml b/Taskfile.yml index 4e8548cf3..95c72018d 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -156,7 +156,8 @@ tasks: internal: true cmds: - uv export --no-editable --no-emit-project --extra pgsql --format - requirements-txt --output-file dist/requirements.txt + requirements-txt --output-file dist/dependencies.txt + - cp dist/dependencies.txt dist/requirements.txt # Include mealie in the requirements, hashing the package that was just built to ensure it's the one installed - echo "mealie[pgsql]=={{.MEALIE_VERSION}} \\" >> dist/requirements.txt - pip hash dist/mealie-{{.MEALIE_VERSION}}-py3-none-any.whl | tail -n1 | @@ -174,6 +175,7 @@ tasks: - dist/mealie-*.whl - dist/mealie-*.tar.gz generates: + - dist/dependencies.txt - dist/requirements.txt py:package:deps-parallel: diff --git a/docker/Dockerfile b/docker/Dockerfile index 50a0cb769..f1e0d81f8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -65,10 +65,11 @@ COPY --from=frontend-builder /frontend/dist ./mealie/frontend # Build the source and binary package RUN uv build --out-dir dist -# Create the requirements file, which is used to install the built package and -# its pinned dependencies later. mealie is included to ensure the built one is -# what's installed. -RUN uv export --no-editable --no-emit-project --extra pgsql --format requirements-txt --output-file dist/requirements.txt \ +# dependencies.txt changes only when uv.lock does, so the venv build can cache +# the install. requirements.txt adds the wheel that was just built, so an +# install from it gets that exact one. +RUN uv export --no-editable --no-emit-project --extra pgsql --format requirements-txt --output-file dist/dependencies.txt \ + && cp dist/dependencies.txt dist/requirements.txt \ && MEALIE_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") \ && echo "mealie[pgsql]==${MEALIE_VERSION} \\" >> dist/requirements.txt \ && pip hash dist/mealie-${MEALIE_VERSION}-py3-none-any.whl | tail -n1 | tr -d '\n' >> dist/requirements.txt \ @@ -102,10 +103,15 @@ RUN python3 -m venv --upgrade-deps $VENV_PATH # Install the wheel and all dependencies into the venv FROM venv-builder-base AS venv-builder +# Cache key is dependencies.txt, so a mealie-only commit reuses this layer. +COPY --from=packages dependencies.txt /dist/dependencies.txt +RUN . $VENV_PATH/bin/activate \ + && pip install --require-hashes -r /dist/dependencies.txt + # Copy built package (wheel) and its dependency requirements COPY --from=packages * /dist/ -# Install the wheel with exact versions of dependencies into the venv +# The dependencies are already in place, so pip only installs mealie itself. RUN . $VENV_PATH/bin/activate \ && pip install --require-hashes -r /dist/requirements.txt --find-links /dist diff --git a/docs/docs/contributors/developers-guide/building-packages.md b/docs/docs/contributors/developers-guide/building-packages.md index 757094696..ae0e94fe9 100644 --- a/docs/docs/contributors/developers-guide/building-packages.md +++ b/docs/docs/contributors/developers-guide/building-packages.md @@ -13,7 +13,8 @@ popd rm -r mealie/frontend cp -a frontend/dist mealie/frontend uv build --out-dir dist -uv export --no-editable --no-emit-project --extra pgsql --format requirements-txt --output-file dist/requirements.txt +uv export --no-editable --no-emit-project --extra pgsql --format requirements-txt --output-file dist/dependencies.txt +cp dist/dependencies.txt dist/requirements.txt MEALIE_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])") echo "mealie[pgsql]==${MEALIE_VERSION} \\" >> dist/requirements.txt pip hash dist/mealie-${MEALIE_VERSION}-py3-none-any.whl | tail -n1 | tr -d '\n' >> dist/requirements.txt @@ -21,6 +22,8 @@ echo " \\" >> dist/requirements.txt pip hash dist/mealie-${MEALIE_VERSION}.tar.gz | tail -n1 >> dist/requirements.txt ``` +This writes two files. `dist/dependencies.txt` pins the dependencies alone, and `dist/requirements.txt` adds the package that was just built. The Docker image installs from both, so that a change to mealie's own code does not rebuild the dependencies. + The Python package can be installed with all of its dependencies pinned to the versions tested by the developers with: ```sh pip3 install -r dist/requirements.txt --find-links dist diff --git a/tests/e2e/docker/docker-compose.yml b/tests/e2e/docker/docker-compose.yml index eacc1e40b..351ebce98 100644 --- a/tests/e2e/docker/docker-compose.yml +++ b/tests/e2e/docker/docker-compose.yml @@ -9,6 +9,11 @@ services: ldap: image: rroemhild/test-openldap + # shorten the image's default 30s health check interval + healthcheck: + interval: 2s + timeout: 5s + retries: 15 ports: - 10389:10389 @@ -22,6 +27,12 @@ services: additional_contexts: packages: ../../../dist restart: always + # shorten the image's default 30s health check interval + healthcheck: + interval: 2s + timeout: 5s + retries: 60 + start_period: 5s volumes: - mealie-data:/app/data/ network_mode: host