-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
92 lines (73 loc) · 2.78 KB
/
Makefile
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
NAME = ionoreporter
VERSION = 3.1.7
GOOS = $(shell uname -s | tr '[:upper:]' '[:lower:]')
GOARCH = amd64
GO = GOOS=$(GOOS) GOARCH=$(GOARCH) go
GODOCKER = GOOS=linux GOARCH=amd64 go
MODULE = github.com/sa6mwa/ionoreporter
SRC = $(MODULE)/cmd/ionoreporter
BINDIR = bin
OUTPUT = $(BINDIR)/$(NAME)
OUTPUTDOCKERBIN = $(BINDIR)/$(NAME)-docker-bin
OUTDIR = output
DBFILE = ionize.db
DESTDIR = /usr/local/bin
SECRETENV = ~/.ionoreporter.config
DXUSER = 1001
DXGROUP = 1001
VOLUME = /storage/ionoreporter
DXENVFILE = /root/.ionoreporter.config
DXHOST = fqdn.to.dx.host
SSHOPTS =
#SSHOPTS = -oProxyJump=jumphost
.PHONY: all tesseract clean full-clean build dependencies docker dockerold docker-run docker-to-dxhost docker-deploy-to-dxhost docker-redeploy-to-dxhost run
all: clean build
clean:
rm -f $(OUTPUT)
test -d $(BINDIR) && rmdir $(BINDIR) || true
full-clean: clean
rm -rf $(OUTDIR)/
build: tesseract clean dependencies $(OUTPUT)
tesseract:
# Hint: You need tesseract-ocr and libtesseract-dev
# E.g: apt-get install tesseract-ocr libtesseract-dev
# Alpine: apk add tesseract-ocr tesseract-ocr-dev
dependencies:
$(GO) get -v -d ./...
$(BINDIR):
mkdir $(BINDIR)
$(OUTPUT): $(BINDIR)
$(GO) build -v -ldflags '-X main.version=$(VERSION)' -o $(OUTPUT) $(SRC)
$(OUTPUTDOCKERBIN): $(BINDIR)
$(GODOCKER) build -v -ldflags '-X main.version=$(VERSION)' -o $(OUTPUTDOCKERBIN) $(SRC)
go.mod:
go mod init $(MODULE)
go mod tidy
install: $(OUTPUT)
install $(OUTPUT) $(DESTDIR)
dockerold: $(OUTPUTDOCKERBIN)
docker build -t $(NAME):$(VERSION) --build-arg VERSION=$(VERSION) -f Dockerfile.old .
docker:
docker build -t $(NAME):$(VERSION) --build-arg VERSION=$(VERSION) -f Dockerfile .
docker-run: $(OUTDIR)
docker run -u $(shell id -u):$(shell id -g) -ti --rm \
-v ${PWD}/$(OUTDIR):/destination \
-e DBFILE=/destination/$(DBFILE) \
-e DISCORD=true -e DAILY=true -e FREQUENT=false \
--env-file $(SECRETENV) \
$(NAME):$(VERSION)
$(OUTDIR):
mkdir $(OUTDIR)
docker-to-dxhost:
docker save $(NAME):$(VERSION) | bzip2 | ssh $(SSHOPTS) $(DXHOST) 'bunzip2 > $(NAME).tar'
ssh $(SSHOPTS) $(DXHOST) 'sudo docker load -i $(NAME).tar'
docker-prune-dxhost:
ssh $(SSHOPTS) $(DXHOST) 'sudo docker image prune -f'
docker-run-on-dxhost:
ssh $(SSHOPTS) $(DXHOST) 'sudo docker run -d -u $(DXUSER):$(DXGROUP) --name $(NAME) --restart unless-stopped -v $(VOLUME):/destination -e DBFILE=/destination/$(DBFILE) -e DISCORD=true -e DAILY=true -e FREQUENT=false --env-file $(DXENVFILE) $(NAME):$(VERSION)'
docker-stop-on-dxhost:
ssh $(SSHOPTS) $(DXHOST) 'sudo docker stop $(NAME) && sudo docker container rm $(NAME)'
docker-deploy-to-dxhost: docker-to-dxhost docker-prune-dxhost docker-run-on-dxhost
docker-redeploy-to-dxhost: docker-stop-on-dxhost docker-deploy-to-dxhost
run: $(OUTPUT) $(OUTDIR)
DBFILE=$(OUTDIR)/$(DBFILE) $(OUTPUT)