From e35763baba0ad09bdf79020fbfb0208ac49f17a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Placzy=C5=84ski?= Date: Fri, 23 Feb 2024 09:52:10 +0100 Subject: [PATCH] [#246] Optimize backend base image build process This commit optimizes the build process for the backend base Docker image in the `scripts/govtool/Makefile`. It introduces conditional logic to build or push the base image only if it doesn't already exist in the repository, significantly reducing unnecessary builds and pushes, thereby saving time and resources. Key changes include: - The `build-backend` target now depends on `build-backend-base`, ensuring the base image is available before building the backend image. However, the base image will only be built if it is not already present, as checked by `docker manifest inspect`. - Similarly, `push-backend-base` incorporates a condition to push the base image only if it is not already available in the repository, using `docker manifest inspect` to verify its existence. This logic prevents redundant builds and uploads of the base image when no changes have occurred to the `vva-be.cabal` file, making the CI/CD pipeline more efficient. By building the base image only when necessary, we align with best practices for Docker image management and optimize our deployment workflow. --- scripts/govtool/Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/govtool/Makefile b/scripts/govtool/Makefile index a9a5e758b..7fdb0983b 100644 --- a/scripts/govtool/Makefile +++ b/scripts/govtool/Makefile @@ -65,7 +65,7 @@ upload-config: prepare-config rsync -av -e 'ssh -o StrictHostKeyChecking=no' config/target/. $(ssh_url):config .PHONY: build-backend -build-backend: +build-backend: build-backend-base @:$(call check_defined, cardano_network) @:$(call check_defined, env) $(docker) build --build-arg BASE_IMAGE_TAG=$(base_backend_image_tag) --tag "$(repo_url)/backend:$(tag)" ../../govtool/backend @@ -74,11 +74,12 @@ build-backend: build-backend-base: @:$(call check_defined, cardano_network) @:$(call check_defined, env) + docker manifest inspect "$(repo_url)/backend-base:$(base_backend_image_tag)" || \ $(docker) build --file ../../govtool/backend/Dockerfile.base --tag "$(repo_url)/backend-base:$(base_backend_image_tag)" ../../govtool/backend - @echo "New backend-base image: $(repo_url)/backend-base:$(base_backend_image_tag)" + @echo "Using backend-base image: $(repo_url)/backend-base:$(base_backend_image_tag)" .PHONY: push-backend -push-backend: docker-login +push-backend: docker-login push-backend-base @:$(call check_defined, cardano_network) @:$(call check_defined, env) $(docker) push $(repo_url)/backend:$(tag) @@ -87,6 +88,7 @@ push-backend: docker-login push-backend-base: docker-login @:$(call check_defined, cardano_network) @:$(call check_defined, env) + docker manifest inspect "$(repo_url)/backend-base:$(base_backend_image_tag)" || \ $(docker) push $(repo_url)/backend-base:$(base_backend_image_tag) .PHONY: build-frontend