Derive the Docker tag from the crate version when building on the main branch and fall back to the short commit SHA on any other branch. Update the run, clean, shell and push targets to use the same tag instead of the implicit latest tag.
74 lines
2.3 KiB
Makefile
74 lines
2.3 KiB
Makefile
# Makefile for building and running the POP3 to IMAP Importer
|
|
|
|
# Variables
|
|
IMAGE_NAME = pop-imap-importer
|
|
DOCKER_PLATFORM = linux/amd64
|
|
VERSION = $(shell grep -m1 '^version' Cargo.toml | cut -d'"' -f2)
|
|
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
|
|
GIT_SHA = $(shell git rev-parse --short HEAD)
|
|
|
|
# Docker tag: version number on main branch, short commit SHA otherwise
|
|
ifeq ($(GIT_BRANCH),main)
|
|
DOCKER_TAG = $(VERSION)
|
|
else
|
|
DOCKER_TAG = $(GIT_SHA)
|
|
endif
|
|
|
|
# Default target
|
|
.PHONY: help
|
|
help: ## Show this help message
|
|
@echo "Usage: make [target]"
|
|
@echo ""
|
|
@echo "Targets:"
|
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
|
|
|
# Local build targets
|
|
.PHONY: build-local
|
|
build-local: ## Build both binaries locally (release mode)
|
|
cargo build --release
|
|
|
|
.PHONY: pop-to-imap
|
|
pop-to-imap: ## Run the POP3 to IMAP migration tool
|
|
cargo run --release --bin pop-to-imap
|
|
|
|
.PHONY: normalize-imap
|
|
normalize-imap: ## Run the IMAP normalization tool
|
|
cargo run --release --bin normalize-imap
|
|
|
|
.PHONY: normalize-dry-run
|
|
normalize-dry-run: ## Run the IMAP normalization tool in dry-run mode
|
|
cargo run --release --bin normalize-imap -- --dry-run
|
|
|
|
.PHONY: test
|
|
test: ## Run all tests
|
|
cargo test
|
|
|
|
# Docker targets
|
|
|
|
.PHONY: build
|
|
build: ## Build the Docker image for linux/amd64 platform (tagged with version on main, commit SHA otherwise)
|
|
docker build --platform=$(DOCKER_PLATFORM) -t $(IMAGE_NAME):$(DOCKER_TAG) .
|
|
|
|
.PHONY: run
|
|
run: ## Run the Docker container
|
|
docker run --platform=$(DOCKER_PLATFORM) --rm -it $(IMAGE_NAME):$(DOCKER_TAG)
|
|
|
|
.PHONY: run-with-env
|
|
run-with-env: ## Run the Docker container with a custom .env file
|
|
docker run --platform=$(DOCKER_PLATFORM) --rm -it -v $(PWD)/.env:/app/.env $(IMAGE_NAME):$(DOCKER_TAG)
|
|
|
|
.PHONY: clean
|
|
clean: ## Remove the Docker image
|
|
docker rmi $(IMAGE_NAME):$(DOCKER_TAG)
|
|
|
|
.PHONY: push
|
|
push: ## Push the Docker image to a registry (requires REPOSITORY variable)
|
|
ifndef REPOSITORY
|
|
$(error REPOSITORY is not set. Please set it with: make push REPOSITORY=your-repo/image-name)
|
|
endif
|
|
docker tag $(IMAGE_NAME):$(DOCKER_TAG) $(REPOSITORY):$(DOCKER_TAG)
|
|
docker push $(REPOSITORY):$(DOCKER_TAG)
|
|
|
|
.PHONY: shell
|
|
shell: ## Run a shell in the Docker container
|
|
docker run --platform=$(DOCKER_PLATFORM) --rm -it $(IMAGE_NAME):$(DOCKER_TAG) sh
|