From 2ba0223adcd1bafd2f860a8b21652fb552f2f7f4 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Fri, 23 May 2025 22:22:12 +0200 Subject: [PATCH 1/5] feat: switch default container image from Ubuntu to Alpine --- .github/workflows/lint_and_test.yml | 8 ++--- .gitignore | 2 +- .goreleaser.yaml | 11 +++++-- Dockerfile | 19 +++++------- Dockerfile.alpine | 26 ---------------- Dockerfile.ubuntu | 29 ++++++++++++++++++ Makefile | 4 +-- README.md | 4 +-- internal/cmd/testdata/Dockerfile.golden.dot | 34 ++++++++++----------- 9 files changed, 71 insertions(+), 66 deletions(-) delete mode 100644 Dockerfile.alpine create mode 100644 Dockerfile.ubuntu diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml index bd8d5e3a..6d993e5d 100644 --- a/.github/workflows/lint_and_test.yml +++ b/.github/workflows/lint_and_test.yml @@ -129,10 +129,10 @@ jobs: ghcr.io/patrickhoefler/dockerfilegraph:latest \ --version - - name: Get the version on Alpine + - name: Get the version on Ubuntu run: | docker run \ - ghcr.io/patrickhoefler/dockerfilegraph:alpine \ + ghcr.io/patrickhoefler/dockerfilegraph:ubuntu \ --version - name: Run the Docker image with flags @@ -147,14 +147,14 @@ jobs: --output png \ --dpi 200 - - name: Run the Alpine-based Docker image with flags + - name: Run the Ubuntu-based Docker image with flags run: | cd examples/dockerfiles docker run \ --user "$(id -u):$(id -g)" \ --workdir /workspace \ --volume "$(pwd)":/workspace \ - ghcr.io/patrickhoefler/dockerfilegraph:alpine \ + ghcr.io/patrickhoefler/dockerfilegraph:ubuntu \ --legend \ --output png \ --dpi 200 diff --git a/.gitignore b/.gitignore index be235f58..438a98a9 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,6 @@ dockerfilegraph # dockerfilegraph Dockerfile.* -!/Dockerfile.alpine +!/Dockerfile.ubuntu !Dockerfile.golden.dot !examples/dockerfiles/Dockerfile.large diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 4362d5b0..d665ad27 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -23,15 +23,20 @@ dockers: - 'ghcr.io/patrickhoefler/dockerfilegraph:{{ .Major }}' - 'ghcr.io/patrickhoefler/dockerfilegraph:{{ .Major }}.{{ .Minor }}' - 'ghcr.io/patrickhoefler/dockerfilegraph:{{ .Major }}.{{ .Minor }}.{{ .Patch }}' - - - dockerfile: Dockerfile.alpine - image_templates: - 'ghcr.io/patrickhoefler/dockerfilegraph:alpine' - 'ghcr.io/patrickhoefler/dockerfilegraph:latest-alpine' - 'ghcr.io/patrickhoefler/dockerfilegraph:{{ .Major }}-alpine' - 'ghcr.io/patrickhoefler/dockerfilegraph:{{ .Major }}.{{ .Minor }}-alpine' - 'ghcr.io/patrickhoefler/dockerfilegraph:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-alpine' + - dockerfile: Dockerfile.ubuntu + image_templates: + - 'ghcr.io/patrickhoefler/dockerfilegraph:ubuntu' + - 'ghcr.io/patrickhoefler/dockerfilegraph:latest-ubuntu' + - 'ghcr.io/patrickhoefler/dockerfilegraph:{{ .Major }}-ubuntu' + - 'ghcr.io/patrickhoefler/dockerfilegraph:{{ .Major }}.{{ .Minor }}-ubuntu' + - 'ghcr.io/patrickhoefler/dockerfilegraph:{{ .Major }}.{{ .Minor }}.{{ .Patch }}-ubuntu' + brews: - repository: owner: patrickhoefler diff --git a/Dockerfile b/Dockerfile index fa2059c9..8745c0bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,20 @@ ### Release image -FROM ubuntu:oracular-20250225@sha256:aadf9a3f5eda81295050d13dabe851b26a67597e424a908f25a63f589dfed48f +FROM alpine:3.21.3@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff4511df3ef88c LABEL org.opencontainers.image.source="https://github.com/patrickhoefler/dockerfilegraph" -# renovate: datasource=repology depName=ubuntu_24_04/fonts-dejavu versioning=loose -ENV FONTS_DEJAVU_VERSION="2.37-8" +# renovate: datasource=repology depName=alpine_3_20/font-dejavu versioning=loose +ENV FONT_DEJAVU_VERSION="2.37-r5" -# renovate: datasource=repology depName=ubuntu_24_04/graphviz versioning=loose -ENV GRAPHVIZ_VERSION="2.42.4-2build2" +# renovate: datasource=repology depName=alpine_3_20/graphviz versioning=loose +ENV GRAPHVIZ_VERSION="12.2.0-r0" -RUN \ - apt-get update \ - && apt-get install -y --no-install-recommends \ - fonts-dejavu="${FONTS_DEJAVU_VERSION}" \ +RUN apk add --update --no-cache \ + font-dejavu="${FONT_DEJAVU_VERSION}" \ graphviz="${GRAPHVIZ_VERSION}" \ - && rm -rf /var/lib/apt/lists/* \ \ # Add a non-root user - && useradd app + && adduser -D app # Run as non-root user USER app diff --git a/Dockerfile.alpine b/Dockerfile.alpine deleted file mode 100644 index 8745c0bd..00000000 --- a/Dockerfile.alpine +++ /dev/null @@ -1,26 +0,0 @@ -### Release image -FROM alpine:3.21.3@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff4511df3ef88c - -LABEL org.opencontainers.image.source="https://github.com/patrickhoefler/dockerfilegraph" - -# renovate: datasource=repology depName=alpine_3_20/font-dejavu versioning=loose -ENV FONT_DEJAVU_VERSION="2.37-r5" - -# renovate: datasource=repology depName=alpine_3_20/graphviz versioning=loose -ENV GRAPHVIZ_VERSION="12.2.0-r0" - -RUN apk add --update --no-cache \ - font-dejavu="${FONT_DEJAVU_VERSION}" \ - graphviz="${GRAPHVIZ_VERSION}" \ - \ - # Add a non-root user - && adduser -D app - -# Run as non-root user -USER app - -# This only works after running `make build-linux` -# or when using goreleaser -COPY dockerfilegraph / - -ENTRYPOINT ["/dockerfilegraph"] diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu new file mode 100644 index 00000000..fa2059c9 --- /dev/null +++ b/Dockerfile.ubuntu @@ -0,0 +1,29 @@ +### Release image +FROM ubuntu:oracular-20250225@sha256:aadf9a3f5eda81295050d13dabe851b26a67597e424a908f25a63f589dfed48f + +LABEL org.opencontainers.image.source="https://github.com/patrickhoefler/dockerfilegraph" + +# renovate: datasource=repology depName=ubuntu_24_04/fonts-dejavu versioning=loose +ENV FONTS_DEJAVU_VERSION="2.37-8" + +# renovate: datasource=repology depName=ubuntu_24_04/graphviz versioning=loose +ENV GRAPHVIZ_VERSION="2.42.4-2build2" + +RUN \ + apt-get update \ + && apt-get install -y --no-install-recommends \ + fonts-dejavu="${FONTS_DEJAVU_VERSION}" \ + graphviz="${GRAPHVIZ_VERSION}" \ + && rm -rf /var/lib/apt/lists/* \ + \ + # Add a non-root user + && useradd app + +# Run as non-root user +USER app + +# This only works after running `make build-linux` +# or when using goreleaser +COPY dockerfilegraph / + +ENTRYPOINT ["/dockerfilegraph"] diff --git a/Makefile b/Makefile index 318dfed8..952bcec7 100644 --- a/Makefile +++ b/Makefile @@ -12,10 +12,10 @@ build: clean go build $(FLAGS) build-docker-image-alpine: build-linux - docker build -t dockerfilegraph:alpine -f Dockerfile.alpine . + docker build -t dockerfilegraph:alpine -f Dockerfile . build-docker-image-ubuntu: build-linux - docker build -t dockerfilegraph:ubuntu -f Dockerfile . + docker build -t dockerfilegraph:ubuntu -f Dockerfile.ubuntu . build-linux: clean GOOS=linux go build $(FLAGS) diff --git a/README.md b/README.md index 5c6312a7..755e0ff2 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Run `dockerfilegraph` in your project directory to generate a `Dockerfile.pdf` w ```shell docker run --rm --user "$(id -u):$(id -g)" \ -v "$(pwd)":/workspace -w /workspace \ - ghcr.io/patrickhoefler/dockerfilegraph:alpine + ghcr.io/patrickhoefler/dockerfilegraph ``` - **Ubuntu-based** (Graphviz 2.42): @@ -66,7 +66,7 @@ Run `dockerfilegraph` in your project directory to generate a `Dockerfile.pdf` w ```shell docker run --rm --user "$(id -u):$(id -g)" \ -v "$(pwd)":/workspace -w /workspace \ - ghcr.io/patrickhoefler/dockerfilegraph + ghcr.io/patrickhoefler/dockerfilegraph:ubuntu ``` #### Homebrew diff --git a/internal/cmd/testdata/Dockerfile.golden.dot b/internal/cmd/testdata/Dockerfile.golden.dot index 5ea2a1e7..72d7cc16 100644 --- a/internal/cmd/testdata/Dockerfile.golden.dot +++ b/internal/cmd/testdata/Dockerfile.golden.dot @@ -1,5 +1,5 @@ digraph G { - graph [bb="0,0,543,252", + graph [bb="0,0,541.25,252", compound=true, nodesep=1.00, rankdir=LR, @@ -10,63 +10,63 @@ digraph G { fontcolor=grey20, height=0.5, label="ubuntu:l...887c2c7ac", - pos="86,234", + pos="85.625,234", shape=box, style="dashed,rounded", - width=2.3056]; + width=2.2951]; stage_0 [height=0.5, label=ubuntu, - pos="285.5,234", + pos="284.25,234", shape=box, style=rounded, width=2]; - external_image_0 -> stage_0 [pos="e,213.41,234 169.04,234 180.32,234 191.9,234 203.17,234"]; + external_image_0 -> stage_0 [pos="e,212.06,234 168.59,234 179.19,234 190.05,234 200.66,234"]; stage_2 [fillcolor=grey90, height=0.5, label=release, - pos="471,126", + pos="469.25,126", shape=box, style="filled,rounded", width=2]; stage_0 -> stage_2 [arrowhead=empty, - pos="e,439.19,144.14 317.21,215.92 348.31,197.62 396.52,169.25 430.45,149.28", + pos="e,437.05,144.41 316.29,215.68 346.92,197.6 393.91,169.87 427.52,150.04", style=dashed]; external_image_1 [color=grey20, fontcolor=grey20, height=0.5, label="golang:1...b738433da", - pos="86,126", + pos="85.625,126", shape=box, style="dashed,rounded", - width=2.3889]; + width=2.3785]; stage_1 [height=0.5, label="build-tool-depend...", - pos="285.5,126", + pos="284.25,126", shape=box, style=rounded, - width=2.1528]; - external_image_1 -> stage_1 [pos="e,207.99,126 172.19,126 180.65,126 189.25,126 197.73,126"]; + width=2.1389]; + external_image_1 -> stage_1 [pos="e,206.99,126 171.72,126 179.6,126 187.6,126 195.5,126"]; stage_1 -> stage_2 [arrowhead=empty, - pos="e,398.82,126 363.26,126 371.64,126 380.19,126 388.62,126", + pos="e,396.78,126 361.53,126 369.37,126 377.37,126 385.28,126", style=dashed]; external_image_2 [color=grey20, fontcolor=grey20, height=0.5, label=buildcache, - pos="86,18", + pos="85.625,18", shape=box, style="dashed,rounded", width=2]; external_image_2 -> stage_1 [arrowhead=ediamond, - pos="e,251.34,107.86 120.06,36.077 153.1,54.144 204.09,82.03 240.53,101.96", + pos="e,249.73,107.59 119.98,36.321 152.61,54.241 202.51,81.651 238.55,101.45", style=dotted]; external_image_3 [color=grey20, fontcolor=grey20, height=0.5, label=scratch, - pos="285.5,18", + pos="284.25,18", shape=box, style="dashed,rounded", width=2]; - external_image_3 -> stage_2 [pos="e,439.19,107.86 317.21,36.077 348.31,54.378 396.52,82.753 430.45,102.72"]; + external_image_3 -> stage_2 [pos="e,437.05,107.59 316.29,36.321 346.92,54.396 393.91,82.126 427.52,101.96"]; } From d81d63760904ef03b87378497eab574a35ec49f5 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Fri, 23 May 2025 22:33:32 +0200 Subject: [PATCH 2/5] docs: clarify default Docker image in installation instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 755e0ff2..da06fb46 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Run `dockerfilegraph` in your project directory to generate a `Dockerfile.pdf` w #### Docker -- **Alpine-based** (Graphviz 12.2): +- **Alpine-based** (Graphviz 12.2) - **Default**: ```shell docker run --rm --user "$(id -u):$(id -g)" \ From 2e455c13e24f33b512d7efc86c5e987f5355ab59 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Fri, 23 May 2025 22:41:03 +0200 Subject: [PATCH 3/5] fix: disable CGO for Linux build in Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 952bcec7..dfc2d40e 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ build-docker-image-ubuntu: build-linux docker build -t dockerfilegraph:ubuntu -f Dockerfile.ubuntu . build-linux: clean - GOOS=linux go build $(FLAGS) + CGO_ENABLED=0 GOOS=linux go build $(FLAGS) clean: go clean From 5674968401cca791b7a67a9295afe98b8d331ac1 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Fri, 23 May 2025 22:48:25 +0200 Subject: [PATCH 4/5] fix: update datasource references for font-dejavu and graphviz to Alpine 3.21 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8745c0bd..abf03900 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,10 +3,10 @@ FROM alpine:3.21.3@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff45 LABEL org.opencontainers.image.source="https://github.com/patrickhoefler/dockerfilegraph" -# renovate: datasource=repology depName=alpine_3_20/font-dejavu versioning=loose +# renovate: datasource=repology depName=alpine_3_21/font-dejavu versioning=loose ENV FONT_DEJAVU_VERSION="2.37-r5" -# renovate: datasource=repology depName=alpine_3_20/graphviz versioning=loose +# renovate: datasource=repology depName=alpine_3_21/graphviz versioning=loose ENV GRAPHVIZ_VERSION="12.2.0-r0" RUN apk add --update --no-cache \ From a6fc2b0e096801d08609c2fe102e5d5f9091c068 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Fri, 23 May 2025 22:50:13 +0200 Subject: [PATCH 5/5] fix: update datasource references for fonts-dejavu and graphviz to Ubuntu 24.10 --- Dockerfile.ubuntu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu index fa2059c9..0c11e453 100644 --- a/Dockerfile.ubuntu +++ b/Dockerfile.ubuntu @@ -3,10 +3,10 @@ FROM ubuntu:oracular-20250225@sha256:aadf9a3f5eda81295050d13dabe851b26a67597e424 LABEL org.opencontainers.image.source="https://github.com/patrickhoefler/dockerfilegraph" -# renovate: datasource=repology depName=ubuntu_24_04/fonts-dejavu versioning=loose +# renovate: datasource=repology depName=ubuntu_24_10/fonts-dejavu versioning=loose ENV FONTS_DEJAVU_VERSION="2.37-8" -# renovate: datasource=repology depName=ubuntu_24_04/graphviz versioning=loose +# renovate: datasource=repology depName=ubuntu_24_10/graphviz versioning=loose ENV GRAPHVIZ_VERSION="2.42.4-2build2" RUN \