From 255e73b2e08c78ac27c536d1c6b98e977504c813 Mon Sep 17 00:00:00 2001 From: Dzianis Andreyenka Date: Wed, 23 Aug 2023 19:38:27 +0200 Subject: [PATCH 1/4] Add multistage build Signed-off-by: Dzianis Andreyenka --- Dockerfile | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 23234a2e..c74726fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,15 @@ -FROM ubuntu:22.04 -RUN apt-get update -RUN apt-get install -y curl apt-transport-https -RUN apt-get clean +FROM golang:1.21-bullseye AS builder +RUN apt-get update && apt-get install +ADD . /signatory +WORKDIR /signatory +RUN make -COPY ./signatory /bin -COPY ./signatory-cli /bin - -ENTRYPOINT ["/bin/signatory"] +FROM debian:buster-slim +WORKDIR /signatory +RUN apt update -y \ + && apt install -y curl apt-transport-https\ + && rm -rf /var/lib/apt/lists/* +COPY --from=builder /signatory/signatory /usr/bin/signatory +COPY --from=builder /signatory/signatory-cli /usr/bin/signatory-cli +ENTRYPOINT ["/usr/bin/signatory"] From 942cb13d7f6a7e17d97565ce7967c56a13728d5a Mon Sep 17 00:00:00 2001 From: Dzianis Andreyenka Date: Wed, 23 Aug 2023 19:53:05 +0200 Subject: [PATCH 2/4] Make service config available by default Signed-off-by: Dzianis Andreyenka --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index c74726fd..22b6d350 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,9 @@ WORKDIR /signatory RUN apt update -y \ && apt install -y curl apt-transport-https\ && rm -rf /var/lib/apt/lists/* +COPY --from=builder /signatory/signatory.yaml /signatory/signatory.yaml COPY --from=builder /signatory/signatory /usr/bin/signatory COPY --from=builder /signatory/signatory-cli /usr/bin/signatory-cli ENTRYPOINT ["/usr/bin/signatory"] +CMD [ "-c", "/signatory/signatory.yaml" ] From 21b03c24ed9f240c7423baaea8d2f532bff4a379 Mon Sep 17 00:00:00 2001 From: Dzianis Andreyenka Date: Wed, 23 Aug 2023 20:08:05 +0200 Subject: [PATCH 3/4] Add .dockerignore file Signed-off-by: Dzianis Andreyenka --- .dockerignore | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..2c81041a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Repo config +.git + +# IDE configs +.vscode +.idea + +# Environment variables +.env + +# App exec +signatory +signatory-cli + +# Other +website +grafana +integration_test +prometheus From 1bf7d0c40058b90e13ca33d05b145c5b3c914797 Mon Sep 17 00:00:00 2001 From: Dzianis Andreyenka Date: Fri, 1 Sep 2023 10:08:51 +0200 Subject: [PATCH 4/4] Do separate dockerfiles for goreleaser and multistage build Signed-off-by: Dzianis Andreyenka --- .dockerignore | 4 ---- .goreleaser.yml | 6 +++--- Makefile | 2 +- goreleaser.dockerfile | 9 +++++++++ 4 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 goreleaser.dockerfile diff --git a/.dockerignore b/.dockerignore index 2c81041a..224bbecd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -14,10 +14,6 @@ # Environment variables .env -# App exec -signatory -signatory-cli - # Other website grafana diff --git a/.goreleaser.yml b/.goreleaser.yml index fafee98b..2371e35a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -243,7 +243,7 @@ dockers: - image_templates: - '{{ if .IsSnapshot }}ghcr.io/{{ end }}ecadlabs/signatory:{{ if .IsSnapshot }}{{ .FullCommit }}{{ else }}{{ .Tag }}{{ end }}-amd64' - '{{ if not .IsSnapshot }}ecadlabs/signatory:latest-amd64{{ end }}' - dockerfile: Dockerfile + dockerfile: goreleaser.dockerfile use: buildx build_flag_templates: - "--pull" @@ -256,7 +256,7 @@ dockers: - image_templates: - '{{ if .IsSnapshot }}ghcr.io/{{ end }}ecadlabs/signatory:{{ if .IsSnapshot }}{{ .FullCommit }}{{ else }}{{ .Tag }}{{ end }}-arm64' - '{{ if not .IsSnapshot }}ecadlabs/signatory:latest-arm64{{ end }}' - dockerfile: Dockerfile + dockerfile: goreleaser.dockerfile use: buildx build_flag_templates: - "--pull" @@ -270,7 +270,7 @@ dockers: - image_templates: - '{{ if .IsSnapshot }}ghcr.io/{{ end }}ecadlabs/signatory:{{ if .IsSnapshot }}{{ .FullCommit }}{{ else }}{{ .Tag }}{{ end }}-armv7' - '{{ if not .IsSnapshot }}ecadlabs/signatory:latest-armv7{{ end }}' - dockerfile: Dockerfile + dockerfile: goreleaser.dockerfile use: buildx build_flag_templates: - "--pull" diff --git a/Makefile b/Makefile index db9ff86a..e90d8992 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ signatory-cli: .PHONY: container container: signatory signatory-cli - docker build -t ecadlabs/signatory:$(CONTAINER_TAG) . + docker build -t ecadlabs/signatory:$(CONTAINER_TAG) -f goreleaser.dockerfile . clean: rm signatory signatory-cli diff --git a/goreleaser.dockerfile b/goreleaser.dockerfile new file mode 100644 index 00000000..d7709c73 --- /dev/null +++ b/goreleaser.dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:22.04 +RUN apt-get update +RUN apt-get install -y curl apt-transport-https +RUN apt-get clean + +COPY ./signatory /bin +COPY ./signatory-cli /bin + +ENTRYPOINT ["/bin/signatory"] \ No newline at end of file