diff --git a/.github/workflows/main-docker.yml b/.github/workflows/main-docker.yml index 9a10ac7f..9c27663b 100644 --- a/.github/workflows/main-docker.yml +++ b/.github/workflows/main-docker.yml @@ -1,23 +1,21 @@ name: Container build on: - workflow_run: - workflows: ["Release Build"] - types: - - completed + pull_request: + push: + branches: + - "main" + workflow_dispatch: + env: REGISTRY_IMAGE: quay.io/redlib/redlib + PLATFORMS: "linux/amd64,linux/arm64" jobs: build: runs-on: ubuntu-latest strategy: fail-fast: false - matrix: - include: - - { platform: linux/amd64, target: x86_64-unknown-linux-musl} - - { platform: linux/arm64, target: aarch64-unknown-linux-musl} - - { platform: linux/arm/v7, target: armv7-unknown-linux-musleabihf} steps: - name: Checkout @@ -39,6 +37,7 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Login to Quay.io Container Registry + if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: quay.io @@ -46,77 +45,23 @@ jobs: password: ${{ secrets.QUAY_ROBOT_TOKEN }} - name: Build and push - id: build + if: github.event_name != 'pull_request' uses: docker/build-push-action@v5 with: context: . - platforms: ${{ matrix.platform }} + platforms: ${{ env.PLATFORMS }} labels: ${{ steps.meta.outputs.labels }} - outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + outputs: type=image,name=${{ env.REGISTRY_IMAGE }} file: Dockerfile - build-args: TARGET=${{ matrix.target }} - - - name: Export digest - run: | - mkdir -p /tmp/digests - digest="${{ steps.build.outputs.digest }}" - touch "/tmp/digests/${digest#sha256:}" - - - name: Upload digest - uses: actions/upload-artifact@v3 - with: - name: digests - path: /tmp/digests/* - if-no-files-found: error - retention-days: 1 - merge: - runs-on: ubuntu-latest - needs: - - build - steps: - - - name: Download digests - uses: actions/download-artifact@v3 - with: - name: digests - path: /tmp/digests - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY_IMAGE }} - tags: | - type=sha - type=raw,value=latest,enable={{is_default_branch}} + push: true - - name: Login to Quay.io Container Registry - uses: docker/login-action@v3 - with: - registry: quay.io - username: ${{ secrets.QUAY_USERNAME }} - password: ${{ secrets.QUAY_ROBOT_TOKEN }} - - - name: Create manifest list and push - working-directory: /tmp/digests - run: | - docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ - $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) - - - name: Push README to Quay.io - uses: christian-korneck/update-container-description-action@v1 - env: - DOCKER_APIKEY: ${{ secrets.APIKEY__QUAY_IO }} + name: Build and push (Pull Request) + if: github.event_name == 'pull_request' + uses: docker/build-push-action@v5 with: - destination_container_repo: quay.io/redlib/redlib - provider: quay - readme_file: 'README.md' - - - - name: Inspect image - run: | - docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} - + context: . + platforms: ${{ env.PLATFORMS }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }} + file: Dockerfile + push: false diff --git a/Dockerfile b/Dockerfile index 94125658..18689e14 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,19 @@ -FROM alpine:3.19 +FROM docker.io/library/rust:1.78-slim-bookworm AS builder -ARG TARGET +WORKDIR /app +COPY ./ ./ -RUN apk add --no-cache curl +# RUN cargo test --release +RUN cargo build --release -RUN curl -L https://github.com/redlib-org/redlib/releases/latest/download/redlib-${TARGET}.tar.gz | \ - tar xz -C /usr/local/bin/ +FROM docker.io/library/debian:bookworm-slim AS release -RUN adduser --home /nonexistent --no-create-home --disabled-password redlib +WORKDIR /app +# ca-certificates are not preinstalled in the base image +RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* +COPY --from=builder --chown=600 /app/target/release/redlib /app/ + +RUN useradd -M redlib USER redlib # Tell Docker to expose port 8080 @@ -16,5 +22,5 @@ EXPOSE 8080 # Run a healthcheck every minute to make sure redlib is functional HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider --q http://localhost:8080/settings || exit 1 -CMD ["redlib"] +CMD ["/app/redlib"]