-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
145 lines (116 loc) · 5.48 KB
/
Makefile
File metadata and controls
145 lines (116 loc) · 5.48 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# ndc-loader Makefile
STAGING_HOST ?= 192.168.1.145
STAGING_USER ?= $(USER)
STAGING_DIR ?= /opt/rx-dag
REGISTRY ?= dockerhub.calebdunn.tech/finish06/rx-dag
.PHONY: build test lint docs deploy-staging staging-logs staging-status staging-restart release
# ── Development ──────────────────────────────────────────────
VERSION ?= dev
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo unknown)
BUILD_TIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w \
-X main.version=$(VERSION) \
-X main.gitCommit=$(GIT_COMMIT) \
-X main.gitBranch=$(GIT_BRANCH) \
-X main.buildTime=$(BUILD_TIME)
build:
CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o ndc-loader ./cmd/ndc-loader
test:
go test -race -cover ./internal/...
test-integration:
DATABASE_URL="postgres://ndc:ndc@localhost:5435/ndc?sslmode=disable" \
go test -tags=integration -race ./tests/integration/...
test-e2e:
DATABASE_URL="postgres://ndc:ndc@localhost:5435/ndc?sslmode=disable" \
go test -tags=e2e -v -timeout=10m ./tests/e2e/...
lint:
golangci-lint run ./...
vet:
go vet ./...
docs:
swag init -g cmd/ndc-loader/main.go -o docs/swagger
# ── Docker ───────────────────────────────────────────────────
docker-build:
docker build -t $(REGISTRY):local .
docker-up:
docker compose up -d
docker-down:
docker compose down
# ── Staging Deploy (192.168.1.145) ───────────────────────────
deploy-staging: ## Deploy to staging1
@echo "==> Deploying ndc-loader to staging ($(STAGING_HOST))..."
@echo "1. Syncing config files..."
ssh $(STAGING_USER)@$(STAGING_HOST) "mkdir -p $(STAGING_DIR)"
scp docker-compose.staging.yml $(STAGING_USER)@$(STAGING_HOST):$(STAGING_DIR)/docker-compose.yml
scp datasets.yaml $(STAGING_USER)@$(STAGING_HOST):$(STAGING_DIR)/datasets.yaml
@echo "2. Syncing .env (if not exists on remote)..."
ssh $(STAGING_USER)@$(STAGING_HOST) "test -f $(STAGING_DIR)/.env || echo 'NEEDS_ENV=true'"
@echo " NOTE: If first deploy, copy .env.staging to staging and edit passwords:"
@echo " scp .env.staging $(STAGING_USER)@$(STAGING_HOST):$(STAGING_DIR)/.env"
@echo "3. Pulling latest image and restarting..."
ssh $(STAGING_USER)@$(STAGING_HOST) "\
cd $(STAGING_DIR) && \
docker pull $(REGISTRY):beta && \
docker compose pull && \
docker compose up -d --force-recreate ndc-loader"
@echo "4. Waiting for health check..."
@sleep 5
@ssh $(STAGING_USER)@$(STAGING_HOST) "curl -sf http://localhost:8081/health" && \
echo "==> Staging deploy OK" || \
echo "==> WARNING: Health check failed"
deploy-staging-first: ## First-time staging setup (creates .env, starts everything)
@echo "==> First-time staging setup on $(STAGING_HOST)..."
ssh $(STAGING_USER)@$(STAGING_HOST) "mkdir -p $(STAGING_DIR)"
scp docker-compose.staging.yml $(STAGING_USER)@$(STAGING_HOST):$(STAGING_DIR)/docker-compose.yml
scp datasets.yaml $(STAGING_USER)@$(STAGING_HOST):$(STAGING_DIR)/datasets.yaml
scp .env.staging $(STAGING_USER)@$(STAGING_HOST):$(STAGING_DIR)/.env
@echo "IMPORTANT: SSH into staging and edit $(STAGING_DIR)/.env with real passwords!"
@echo "Then run: make staging-start"
staging-start: ## Start all services on staging
ssh $(STAGING_USER)@$(STAGING_HOST) "\
cd $(STAGING_DIR) && \
docker compose pull && \
docker compose up -d"
staging-stop: ## Stop all services on staging
ssh $(STAGING_USER)@$(STAGING_HOST) "\
cd $(STAGING_DIR) && \
docker compose down"
staging-restart: ## Restart ndc-loader on staging (keeps postgres)
ssh $(STAGING_USER)@$(STAGING_HOST) "\
cd $(STAGING_DIR) && \
docker compose pull ndc-loader && \
docker compose up -d --force-recreate ndc-loader"
staging-logs: ## Tail staging logs
ssh $(STAGING_USER)@$(STAGING_HOST) "\
cd $(STAGING_DIR) && \
docker compose logs -f --tail=50 ndc-loader"
staging-status: ## Check staging health
@echo "==> Staging status ($(STAGING_HOST)):"
@ssh $(STAGING_USER)@$(STAGING_HOST) "\
cd $(STAGING_DIR) && \
docker compose ps && \
echo '---' && \
curl -sf http://localhost:8081/health | python3 -m json.tool"
staging-load: ## Trigger data load on staging
@echo "==> Triggering FDA data load on staging..."
ssh $(STAGING_USER)@$(STAGING_HOST) "\
curl -X POST http://localhost:8081/api/admin/load \
-H 'Content-Type: application/json' \
-H 'X-API-Key: \$$(grep API_KEYS $(STAGING_DIR)/.env | cut -d= -f2)' \
-d '{}'"
staging-psql: ## Open psql on staging postgres
ssh -t $(STAGING_USER)@$(STAGING_HOST) "\
cd $(STAGING_DIR) && \
docker compose exec ndc-loader-postgres psql -U ndc -d ndc"
# ── Release ───────────────────────────────────────────────────
release: ## Tag and push a release (usage: make release VERSION=0.2.0)
@test -n "$(VERSION)" || (echo "Usage: make release VERSION=x.y.z" && exit 1)
@echo "==> Tagging v$(VERSION)..."
git tag -a v$(VERSION) -m "v$(VERSION)"
git push origin v$(VERSION)
@echo "==> Release v$(VERSION) tagged and pushed."
@echo " CI will build, publish images, and create GitHub Release."
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'