Skip to content

Commit

Permalink
[#246] Make backend base image version dependent on cabal file
Browse files Browse the repository at this point in the history
This commit introduces a significant enhancement to the Docker build
process for the backend by making the base image versioning dependent on
the `vva-be.cabal` file. This change ensures that the base Docker image
is closely tied to the project's Haskell dependencies, as specified in
the cabal file.

- In `govtool/backend/Dockerfile`, an `ARG BASE_IMAGE_TAG` is
  introduced, allowing for dynamic specification of the base image tag
  during the build process. This facilitates using different versions of
  the base image as dependencies evolve.
- The `scripts/govtool/Makefile` is updated to calculate the
  `base_backend_image_tag` by hashing the `vva-be.cabal` file. This hash
  becomes the tag for the base image, ensuring that any changes in the
  cabal file result in a new base image version. This mechanism automates
  the versioning process, ensuring that the backend is always built
  against the correct set of pre-compiled dependencies.

By linking the base image version directly to the cabal file's hash,
this approach guarantees that any changes in dependencies are
automatically accounted for, thereby streamlining the build process and
enhancing consistency across builds.
  • Loading branch information
placek committed Feb 23, 2024
1 parent 55c2921 commit 76f9995
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion govtool/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM 733019650473.dkr.ecr.eu-west-1.amazonaws.com/backend-base:39906fb
ARG BASE_IMAGE_TAG
FROM 733019650473.dkr.ecr.eu-west-1.amazonaws.com/backend-base:$BASE_IMAGE_TAG
WORKDIR /src
COPY . .
RUN cabal build
Expand Down
9 changes: 5 additions & 4 deletions scripts/govtool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ docker_user := ubuntu
ssh_url := $(docker_user)@$(docker_host)
docker_compose_file := docker-compose.$(env).yml
compose_stack_name := govtool-$(env)-$(cardano_network)
base_backend_image_tag := $(shell git hash-object ../../govtool/backend/vva-be.cabal)

# helper function for checking undefined variables
check_defined = \
Expand Down Expand Up @@ -67,14 +68,14 @@ upload-config: prepare-config
build-backend:
@:$(call check_defined, cardano_network)
@:$(call check_defined, env)
$(docker) build --tag "$(repo_url)/backend:$(tag)" ../../govtool/backend
$(docker) build --build-arg BASE_IMAGE_TAG=$(base_backend_image_tag) --tag "$(repo_url)/backend:$(tag)" ../../govtool/backend

.PHONY: build-backend-base
build-backend-base:
@:$(call check_defined, cardano_network)
@:$(call check_defined, env)
$(docker) build --file ../../govtool/backend/Dockerfile.base --tag "$(repo_url)/backend-base:$(commit)" ../../govtool/backend
@echo "New backend-base image: $(repo_url)/backend-base:$(commit)"
$(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)"

.PHONY: push-backend
push-backend: docker-login
Expand All @@ -86,7 +87,7 @@ push-backend: docker-login
push-backend-base: docker-login
@:$(call check_defined, cardano_network)
@:$(call check_defined, env)
$(docker) push $(repo_url)/backend-base:$(commit)
$(docker) push $(repo_url)/backend-base:$(base_backend_image_tag)

.PHONY: build-frontend
build-frontend:
Expand Down

0 comments on commit 76f9995

Please sign in to comment.