# Variáveis
IMAGE_NAME = decoda-app
VERSION = $(shell grep 'ARG APP_VERSION=' Dockerfile | cut -d'=' -f2)

.PHONY: build run stop clean

# Build da imagem docker
build:
	@echo "Construindo imagem $(IMAGE_NAME):$(VERSION)..."
	docker build --build-arg APP_VERSION=$(VERSION) -t $(IMAGE_NAME):$(VERSION) .
	docker tag $(IMAGE_NAME):$(VERSION) $(IMAGE_NAME):latest

# Executar o container
run:
	@echo "Iniciando container $(IMAGE_NAME):$(VERSION) na porta 8080..."
	docker run -d --name $(IMAGE_NAME) -p 8080:80 $(IMAGE_NAME):$(VERSION)
	@echo "Aplicação disponível em http://localhost:8080"

# Parar e remover o container
stop:
	@echo "Parando container..."
	docker stop $(IMAGE_NAME) || true
	docker rm $(IMAGE_NAME) || true

# Ver logs
logs:
	docker logs -f $(IMAGE_NAME)

# Limpar imagens antigas
clean:
	@echo "Removendo imagem $(IMAGE_NAME):$(VERSION)..."
	docker rmi $(IMAGE_NAME):$(VERSION) $(IMAGE_NAME):latest || true
