diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 271bf44..ae153f9 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -45,9 +45,23 @@ jobs: - platform: linux/amd64 runner: ubuntu-latest arch: amd64 + flavor: default + dockerfile: Dockerfile - platform: linux/arm64 runner: ubuntu-24.04-arm arch: arm64 + flavor: default + dockerfile: Dockerfile + - platform: linux/amd64 + runner: ubuntu-latest + arch: amd64 + flavor: alpine + dockerfile: Dockerfile.alpine + - platform: linux/arm64 + runner: ubuntu-24.04-arm + arch: arm64 + flavor: alpine + dockerfile: Dockerfile.alpine runs-on: ${{ matrix.runner }} steps: - name: Checkout @@ -68,10 +82,11 @@ jobs: uses: docker/build-push-action@v6 with: context: . + file: ${{ matrix.dockerfile }} platforms: ${{ matrix.platform }} outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true - cache-from: type=gha,scope=dev-${{ matrix.arch }} - cache-to: type=gha,mode=max,scope=dev-${{ matrix.arch }} + cache-from: type=gha,scope=dev-${{ matrix.flavor }}-${{ matrix.arch }} + cache-to: type=gha,mode=max,scope=dev-${{ matrix.flavor }}-${{ matrix.arch }} - name: Export digest run: | @@ -82,7 +97,7 @@ jobs: - name: Upload digest uses: actions/upload-artifact@v4 with: - name: digests-dev-${{ matrix.arch }} + name: digests-dev-${{ matrix.flavor }}-${{ matrix.arch }} path: /tmp/digests/* if-no-files-found: error retention-days: 1 @@ -96,7 +111,7 @@ jobs: uses: actions/download-artifact@v4 with: path: /tmp/digests - pattern: digests-dev-* + pattern: digests-dev-default-* merge-multiple: true - name: Set up Docker Buildx @@ -117,6 +132,36 @@ jobs: docker buildx imagetools create $(printf -- '-t %s ' "${tags[@]}") \ $(printf '${{ env.IMAGE }}@sha256:%s ' *) + merge-dev-alpine: + if: github.ref == 'refs/heads/main' + needs: build-dev + runs-on: ubuntu-latest + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-dev-alpine-* + merge-multiple: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create dev Alpine multi-arch manifest + working-directory: /tmp/digests + run: | + SHORT_SHA="${GITHUB_SHA::7}" + tags=("${{ env.IMAGE }}:dev-alpine" "${{ env.IMAGE }}:dev-${SHORT_SHA}-alpine") + docker buildx imagetools create $(printf -- '-t %s ' "${tags[@]}") \ + $(printf '${{ env.IMAGE }}@sha256:%s ' *) + build-release: needs: read-version if: github.ref == 'refs/heads/release' @@ -127,9 +172,23 @@ jobs: - platform: linux/amd64 runner: ubuntu-latest arch: amd64 + flavor: default + dockerfile: Dockerfile - platform: linux/arm64 runner: ubuntu-24.04-arm arch: arm64 + flavor: default + dockerfile: Dockerfile + - platform: linux/amd64 + runner: ubuntu-latest + arch: amd64 + flavor: alpine + dockerfile: Dockerfile.alpine + - platform: linux/arm64 + runner: ubuntu-24.04-arm + arch: arm64 + flavor: alpine + dockerfile: Dockerfile.alpine runs-on: ${{ matrix.runner }} steps: - name: Checkout @@ -150,10 +209,11 @@ jobs: uses: docker/build-push-action@v6 with: context: . + file: ${{ matrix.dockerfile }} platforms: ${{ matrix.platform }} outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true - cache-from: type=gha,scope=release-${{ matrix.arch }} - cache-to: type=gha,mode=max,scope=release-${{ matrix.arch }} + cache-from: type=gha,scope=release-${{ matrix.flavor }}-${{ matrix.arch }} + cache-to: type=gha,mode=max,scope=release-${{ matrix.flavor }}-${{ matrix.arch }} - name: Export digest run: | @@ -164,7 +224,7 @@ jobs: - name: Upload digest uses: actions/upload-artifact@v4 with: - name: digests-release-${{ matrix.arch }} + name: digests-release-${{ matrix.flavor }}-${{ matrix.arch }} path: /tmp/digests/* if-no-files-found: error retention-days: 1 @@ -178,7 +238,7 @@ jobs: uses: actions/download-artifact@v4 with: path: /tmp/digests - pattern: digests-release-* + pattern: digests-release-default-* merge-multiple: true - name: Set up Docker Buildx @@ -199,3 +259,34 @@ jobs: tags=("${{ env.IMAGE }}:latest" "${{ env.IMAGE }}:${VERSION}" "${{ env.IMAGE }}:${MAJOR_MINOR}") docker buildx imagetools create $(printf -- '-t %s ' "${tags[@]}") \ $(printf '${{ env.IMAGE }}@sha256:%s ' *) + + merge-release-alpine: + needs: [read-version, build-release] + if: github.ref == 'refs/heads/release' + runs-on: ubuntu-latest + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-release-alpine-* + merge-multiple: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create release Alpine multi-arch manifest + working-directory: /tmp/digests + run: | + VERSION="${{ needs.read-version.outputs.version }}" + MAJOR_MINOR="${VERSION%.*}" + tags=("${{ env.IMAGE }}:alpine" "${{ env.IMAGE }}:latest-alpine" "${{ env.IMAGE }}:${VERSION}-alpine" "${{ env.IMAGE }}:${MAJOR_MINOR}-alpine") + docker buildx imagetools create $(printf -- '-t %s ' "${tags[@]}") \ + $(printf '${{ env.IMAGE }}@sha256:%s ' *) diff --git a/Dockerfile b/Dockerfile index 3ce7806..086fd46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.14-alpine3.23 AS builder +FROM python:3.11-slim-bookworm AS builder COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ @@ -8,25 +8,27 @@ WORKDIR /app RUN --mount=type=cache,target=/root/.cache/uv \ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ - uv sync --all-extras --no-install-project --no-dev + uv sync --extra all --no-install-project --no-dev COPY pyproject.toml LICENSE README.md ./ COPY src/ ./src/ RUN --mount=type=cache,target=/root/.cache/uv \ - uv sync --all-extras --no-dev + uv sync --extra all --no-dev -FROM python:3.14-alpine3.23 +FROM python:3.11-slim-bookworm LABEL org.opencontainers.image.description="CLI tool for syncing content to Open WebUI Knowledge Bases" \ org.opencontainers.image.source="https://github.com/open-webui/oikb" \ org.opencontainers.image.vendor="Open WebUI Inc." \ org.opencontainers.image.licenses="MIT" ENV PYTHONUNBUFFERED=1 -RUN apk add --no-cache ca-certificates \ - && addgroup -g 1000 appuser \ - && adduser -D -u 1000 -G appuser appuser +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates \ + && rm -rf /var/lib/apt/lists/* \ + && groupadd --gid 1000 appuser \ + && useradd --uid 1000 --gid appuser --create-home --shell /usr/sbin/nologin appuser COPY --from=builder --chown=appuser:appuser /app /app diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 0000000..f53b4f9 --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,44 @@ +FROM python:3.11-alpine3.23 AS builder + +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ + +ENV UV_LINK_MODE=copy +ENV LD_LIBRARY_PATH=/usr/lib/llvm21/lib + +WORKDIR /app + +RUN apk add --no-cache build-base clang21-libclang pkgconf + +RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --extra all --no-install-project --no-dev + +COPY pyproject.toml LICENSE README.md ./ +COPY src/ ./src/ + +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --extra all --no-dev + + +FROM python:3.11-alpine3.23 +LABEL org.opencontainers.image.description="CLI tool for syncing content to Open WebUI Knowledge Bases" \ + org.opencontainers.image.source="https://github.com/open-webui/oikb" \ + org.opencontainers.image.vendor="Open WebUI Inc." \ + org.opencontainers.image.licenses="MIT" +ENV PYTHONUNBUFFERED=1 + +RUN apk add --no-cache ca-certificates libstdc++ \ + && addgroup -g 1000 appuser \ + && adduser -D -u 1000 -G appuser appuser + +COPY --from=builder --chown=appuser:appuser /app /app + +WORKDIR /app + +USER appuser + +ENV PATH="/app/.venv/bin:$PATH" + +EXPOSE 8080 + +ENTRYPOINT ["oikb"]