Makefile 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. APP := miniflux
  2. DOCKER_IMAGE := miniflux/miniflux
  3. VERSION := $(shell git describe --tags --exact-match 2>/dev/null)
  4. DOCKER_TAG := $(or $(VERSION),dev)
  5. LD_FLAGS := "-s -w -X 'miniflux.app/v2/internal/version.Version=$(VERSION)'"
  6. DB_URL := postgres://postgres:postgres@localhost/miniflux_test?sslmode=disable
  7. DOCKER_PLATFORM := amd64
  8. export PGPASSWORD := postgres
  9. .PHONY: \
  10. miniflux \
  11. miniflux-no-pie \
  12. linux-amd64 \
  13. linux-arm64 \
  14. linux-armv7 \
  15. linux-armv6 \
  16. linux-armv5 \
  17. linux-riscv64 \
  18. darwin-amd64 \
  19. darwin-arm64 \
  20. freebsd-amd64 \
  21. freebsd-arm64 \
  22. openbsd-amd64 \
  23. build \
  24. run \
  25. clean \
  26. add-string \
  27. test \
  28. lint \
  29. integration-test \
  30. clean-integration-test \
  31. docker-image \
  32. docker-image-distroless \
  33. docker-images \
  34. rpm \
  35. debian \
  36. debian-packages
  37. miniflux:
  38. @ go build -buildmode=pie -ldflags=$(LD_FLAGS) -o $(APP)
  39. miniflux-no-pie:
  40. @ go build -ldflags=$(LD_FLAGS) -o $(APP)
  41. linux-amd64:
  42. @ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@
  43. @ sha256sum $(APP)-$@ > $(APP)-$@.sha256
  44. linux-arm64:
  45. @ CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@
  46. @ sha256sum $(APP)-$@ > $(APP)-$@.sha256
  47. linux-armv7:
  48. @ CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@
  49. @ sha256sum $(APP)-$@ > $(APP)-$@.sha256
  50. linux-armv6:
  51. @ CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@
  52. @ sha256sum $(APP)-$@ > $(APP)-$@.sha256
  53. linux-armv5:
  54. @ CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@
  55. @ sha256sum $(APP)-$@ > $(APP)-$@.sha256
  56. linux-riscv64:
  57. @ CGO_ENABLED=0 GOOS=linux GOARCH=riscv64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@
  58. @ sha256sum $(APP)-$@ > $(APP)-$@.sha256
  59. darwin-amd64:
  60. @ CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@
  61. @ sha256sum $(APP)-$@ > $(APP)-$@.sha256
  62. darwin-arm64:
  63. @ CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@
  64. @ sha256sum $(APP)-$@ > $(APP)-$@.sha256
  65. freebsd-amd64:
  66. @ CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@
  67. @ sha256sum $(APP)-$@ > $(APP)-$@.sha256
  68. freebsd-arm64:
  69. @ CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@
  70. @ sha256sum $(APP)-$@ > $(APP)-$@.sha256
  71. openbsd-amd64:
  72. @ CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@
  73. @ sha256sum $(APP)-$@ > $(APP)-$@.sha256
  74. build: linux-amd64 linux-arm64 linux-armv7 linux-armv6 linux-armv5 linux-riscv64 darwin-amd64 darwin-arm64 freebsd-amd64 freebsd-arm64 openbsd-amd64
  75. run: miniflux
  76. @ LOG_DATE_TIME=1 LOG_LEVEL=debug RUN_MIGRATIONS=1 CREATE_ADMIN=1 ADMIN_USERNAME=admin ADMIN_PASSWORD=test123 ./$(APP)
  77. clean:
  78. @ rm -f $(APP)-* $(APP) $(APP)*.rpm $(APP)*.deb
  79. add-string:
  80. $(if $(KEY),,$(error KEY is required, e.g. make add-string KEY=page.example.title VAL="Example"))
  81. $(if $(VAL),,$(error VAL is required, e.g. make add-string KEY=page.example.title VAL="Example"))
  82. cd internal/locale/translations && \
  83. for file in *.json; do \
  84. jq --indent 4 --arg key "$(KEY)" --arg val "$(VAL)" \
  85. '. + {($$key): $$val} | to_entries | sort_by(.key) | from_entries' "$$file" > tmp && \
  86. mv tmp "$$file"; \
  87. done
  88. test:
  89. go test -cover -race -count=1 ./...
  90. lint:
  91. go vet ./...
  92. gofmt -d -e .
  93. golangci-lint run
  94. integration-test: miniflux
  95. psql -U postgres -c 'drop database if exists miniflux_test;'
  96. psql -U postgres -c 'create database miniflux_test;'
  97. DATABASE_URL=$(DB_URL) ./$(APP) -migrate
  98. TEST_DATABASE_URL=$(DB_URL) go test -v -count=1 ./internal/storage
  99. TEST_DATABASE_URL=$(DB_URL) go test -v -count=1 ./internal/api
  100. clean-integration-test:
  101. @ psql -U postgres -c 'drop database if exists miniflux_test;'
  102. docker-image:
  103. docker build --pull -t $(DOCKER_IMAGE):$(DOCKER_TAG) -f packaging/docker/alpine/Dockerfile .
  104. docker-image-distroless:
  105. docker build --pull -t $(DOCKER_IMAGE):$(DOCKER_TAG)-distroless -f packaging/docker/distroless/Dockerfile .
  106. docker-images:
  107. $(if $(VERSION),,$(error VERSION is required to push images, e.g. make docker-images VERSION=2.3.0))
  108. docker buildx build \
  109. --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/riscv64 \
  110. --file packaging/docker/alpine/Dockerfile \
  111. --tag $(DOCKER_IMAGE):$(VERSION) \
  112. --push .
  113. rpm: clean
  114. @ docker build \
  115. -t miniflux-rpm-builder \
  116. -f packaging/rpm/Dockerfile \
  117. .
  118. @ docker run --rm \
  119. -v $(CURDIR):/root/rpmbuild/RPMS/x86_64 miniflux-rpm-builder \
  120. rpmbuild -bb --define "_miniflux_version $(VERSION)" /root/rpmbuild/SPECS/miniflux.spec
  121. debian:
  122. @ docker buildx build --load \
  123. --platform linux/$(DOCKER_PLATFORM) \
  124. -t miniflux-deb-builder \
  125. -f packaging/debian/Dockerfile \
  126. .
  127. @ docker run --rm --platform linux/$(DOCKER_PLATFORM) \
  128. -v $(CURDIR):/pkg miniflux-deb-builder
  129. debian-packages: clean
  130. $(MAKE) debian DOCKER_PLATFORM=amd64
  131. $(MAKE) debian DOCKER_PLATFORM=arm64
  132. $(MAKE) debian DOCKER_PLATFORM=arm/v7
  133. $(MAKE) debian DOCKER_PLATFORM=riscv64