Skip to content

Commit

Permalink
[#246] Optimize backend base image build process
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
placek authored and MSzalowski committed Feb 23, 2024
1 parent 14f11c0 commit e35763b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions scripts/govtool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit e35763b

Please sign in to comment.