File size: 2,021 Bytes
3760017
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
SHELL := /bin/bash
.DEFAULT_GOAL := help

IMAGE ?= filebot
PORT  ?= 7860

# Hugging Face: set these in your shell, never in this file.
#   export HF_USER=your-hf-username
#   export HF_TOKEN=hf_xxx            (token with write access)
HF_SPACE ?= filebot

.PHONY: help install check start docker-build docker-run space-create space-push

help: ## Show this help
	@grep -E '^[a-z-]+:.*## ' $(MAKEFILE_LIST) | awk -F':.*## ' '{printf "  make %-14s %s\n", $$1, $$2}'

install: ## Install npm packages
	npm ci

check: ## Syntax-check the server code
	node --check server.js && node --check db.js

start: ## Run locally (reads .env)
	node server.js

docker-build: ## Build the Docker image
	docker build -t $(IMAGE) .

docker-run: ## Run the Docker image using .env
	docker run --rm --env-file .env -e PORT=$(PORT) -p $(PORT):$(PORT) $(IMAGE)

space-create: ## Create a PRIVATE Docker Space on Hugging Face
	@test -n "$(HF_TOKEN)" -a -n "$(HF_USER)" || (echo "Set HF_USER and HF_TOKEN first"; exit 1)
	@curl -sS -f -X POST https://huggingface.co/api/repos/create \
	  -H "Authorization: Bearer $(HF_TOKEN)" -H "Content-Type: application/json" \
	  -d '{"type":"space","name":"$(HF_SPACE)","sdk":"docker","private":true}' && echo
	@echo "Private Space ready: https://huggingface.co/spaces/$(HF_USER)/$(HF_SPACE)"

space-push: ## Push this project to the Space (secrets are NOT pushed)
	@test -n "$(HF_TOKEN)" -a -n "$(HF_USER)" || (echo "Set HF_USER and HF_TOKEN first"; exit 1)
	rm -rf build/space && mkdir -p build/space
	@tar --exclude=./node_modules --exclude=./.env --exclude=./.git --exclude=./build --exclude=./data -cf - . | tar -xf - -C build/space
	cd build/space && git init -q -b main && git add -A && git -c user.name=filebot -c user.email=filebot@localhost commit -qm "Deploy $$(date -u +%Y-%m-%dT%H:%M:%SZ)"
	@cd build/space && git push -f -q https://$(HF_USER):$(HF_TOKEN)@huggingface.co/spaces/$(HF_USER)/$(HF_SPACE) HEAD:main && echo "Pushed. Build logs: https://huggingface.co/spaces/$(HF_USER)/$(HF_SPACE)"