getzola / zola

A fast static site generator in a single binary with everything built-in. https://www.getzola.org
https://www.getzola.org
MIT License
13.48k stars 943 forks source link

Feature request: build a non distroless docker image #2361

Open ogarcia opened 10 months ago

ogarcia commented 10 months ago

Having a distroless image is interesting for people who simply want to run zola directly, but if you want to use zola on a CI/CD system you need the image to contain a shell.

I think you could make two variants of the image, by default a distroless one and then another one based on Debian (to give an example).

You would have to modify the Dockerfile to make the from a variable:

Dockerfile ```Dockerfile ARG DISTRO=gcr.io/distroless/cc FROM rust:slim AS builder RUN apt-get update -y && \ apt-get install -y make g++ libssl-dev && \ rustup target add x86_64-unknown-linux-gnu WORKDIR /app COPY . . RUN cargo build --release --target x86_64-unknown-linux-gnu FROM ${DISTRO} COPY --from=builder /app/target/x86_64-unknown-linux-gnu/release/zola /bin/zola ENTRYPOINT [ "/bin/zola" ] ```

And add these two additional steps in the CI:

CI steps ```yaml - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} flavor: latest=false tags: | type=ref,enable=true,priority=600,prefix=debian-,suffix=,event=tag - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: build-args: | DISTRO=debian:stable context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} ```
Keats commented 10 months ago

Isn't it easier to download the binary from the releases in CI?

ogarcia commented 10 months ago

Isn't it easier to download the binary from the releases in CI?

That is what I am currently doing. But if an official image with shell is available you can use the image cache to store it and therefore only download it once.

LouDou commented 8 months ago

I agree with this suggestion; doing downloads in CI containers is unnecessary boilerplate IMO, it would be nice to use a prebuilt CI image with shell included.

EDIT: reference to gitlab not supporting shell-less CI images: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/26501

stellarpower commented 1 day ago

What I have done is introduce the base image as a build stage and then copy the files from that image into my own - AFAIK just /bin/zola is enough and so far it is running in my downstream image. Also somehow only recently was introduced to the ADD instruction, which avoids the need for downloding curl or wget. And there is also buildah.

I see arguments on both sides. And I guess then there would be the question of what distro to use. Or just go with alpine - but then musl or glibc? IME these things don't usually have easy solutions, even though it's a totally valid and sensible question. That said adding an extra tagged flavour at least wouldn't harm the existing setup and people can choose.