feat: use DOCKER_IMAGE from .env in Makefile

- Update Makefile to read DOCKER_IMAGE from .env file with proper precedence
- Environment variables override .env file values
- Fallback to 'meds-app:latest' if not defined anywhere
- Add new Docker targets: docker-run, docker-push, docker-config
- Improve help output with environment variable documentation
- Update APP_NAME_CONFIGURATION.md to show Makefile usage examples

Variable precedence:
1. Environment variable (highest)
2. .env file (medium)
3. Default fallback (lowest)
This commit is contained in:
William Valentin
2025-09-08 21:43:02 -07:00
parent 36dcdbd459
commit 518752ab6e
2 changed files with 41 additions and 5 deletions

View File

@@ -1,5 +1,15 @@
# Makefile for Medication Reminder App
# Check if DOCKER_IMAGE is set in environment, otherwise use .env or default
ifndef DOCKER_IMAGE
# Include environment variables from .env file if it exists
-include .env
# Set default if still not defined
DOCKER_IMAGE ?= meds-app:latest
endif
export
.PHONY: help install clean dev build test docker-build docker-clean
# Default target
@@ -8,6 +18,12 @@
##@ General
help: ## Display available commands
@echo "Medication Reminder App - Make Commands"
@echo ""
@echo "Environment Variables:"
@echo " DOCKER_IMAGE Docker image name (default: meds-app:latest)"
@echo " Can be set in .env file or environment"
@echo ""
@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " %-20s %s\n", $$1, $$2 } /^##@/ { printf "\n%s\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
install: ## Install dependencies
@@ -41,16 +57,30 @@ test-watch: ## Run unit tests in watch mode
##@ Docker
docker-build: ## Build Docker image for multiple architectures
@echo "Building multi-platform Docker image..."
@echo "Building multi-platform Docker image: $(DOCKER_IMAGE)"
@docker buildx build --platform linux/amd64,linux/arm64 \
--build-arg NODE_ENV=production \
-t meds-app:latest .
-t $(DOCKER_IMAGE) .
docker-build-local: ## Build Docker image for local platform only
@echo "Building local Docker image..."
@echo "Building local Docker image: $(DOCKER_IMAGE)"
@docker buildx build --platform linux/amd64 \
--build-arg NODE_ENV=production \
-t meds-app:latest --load .
-t $(DOCKER_IMAGE) --load .
docker-run: ## Run Docker container from built image
@echo "Running Docker container: $(DOCKER_IMAGE)"
@docker run --rm -p 8080:80 $(DOCKER_IMAGE)
docker-push: ## Push Docker image to registry
@echo "Pushing Docker image: $(DOCKER_IMAGE)"
@docker push $(DOCKER_IMAGE)
docker-config: ## Show current Docker configuration
@echo "Current Docker configuration:"
@echo " DOCKER_IMAGE: $(DOCKER_IMAGE)"
@echo " Available images:"
@docker images | grep -E "(REPOSITORY|$(shell echo $(DOCKER_IMAGE) | cut -d: -f1))" || true
docker-clean: ## Clean Docker resources
@echo "Cleaning Docker resources..."

View File

@@ -25,7 +25,10 @@ make deploy
export APP_NAME="DevMeds"
bun run dev
# For Docker build
# For Docker build with Makefile
DOCKER_IMAGE="myregistry.com/myapp:v1.0" make docker-build
# For Docker build with manual command
APP_NAME="CustomApp" docker build -t myapp .
```
@@ -34,12 +37,15 @@ APP_NAME="CustomApp" docker build -t myapp .
```bash
# .env
APP_NAME=MyCustomApp
DOCKER_IMAGE=myregistry.com/mycustomapp:dev
# .env.production
APP_NAME=ProductionApp
DOCKER_IMAGE=myregistry.com/productionapp:latest
# .env.staging
APP_NAME=StagingApp
DOCKER_IMAGE=myregistry.com/stagingapp:staging
```
## Where APP_NAME is Used