From ad057c12c0b8ab50030424376859d3aa9f1331d9 Mon Sep 17 00:00:00 2001
From: Philipp Heckel <pheckel@datto.com>
Date: Sat, 20 Nov 2021 20:18:40 -0500
Subject: [PATCH] Statically linking go-sqlite3

---
 .goreleaser.yml |  9 +++++++++
 Makefile        |  3 ++-
 README.md       | 14 +++++++++++++-
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/.goreleaser.yml b/.goreleaser.yml
index 4fe37f8..1972a6f 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -7,6 +7,9 @@ builds:
     binary: ntfy
     env:
       - CGO_ENABLED=1 # required for go-sqlite3
+    tags: [sqlite_omit_load_extension]
+    ldflags:
+      - "-linkmode=external -extldflags=-static -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}"
     goos: [linux]
     goarch: [amd64]
   -
@@ -15,6 +18,9 @@ builds:
     env:
       - CGO_ENABLED=1 # required for go-sqlite3
       - CC=arm-linux-gnueabi-gcc # apt install gcc-arm-linux-gnueabi
+    tags: [sqlite_omit_load_extension]
+    ldflags:
+      - "-linkmode=external -extldflags=-static -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}"
     goos: [linux]
     goarch: [arm]
     goarm:
@@ -26,6 +32,9 @@ builds:
     env:
       - CGO_ENABLED=1 # required for go-sqlite3
       - CC=aarch64-linux-gnu-gcc # apt install gcc-aarch64-linux-gnu
+    tags: [sqlite_omit_load_extension]
+    ldflags:
+      - "-linkmode=external -extldflags=-static -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}"
     goos: [linux]
     goarch: [arm64]
 nfpms:
diff --git a/Makefile b/Makefile
index 6d7b029..855eba0 100644
--- a/Makefile
+++ b/Makefile
@@ -103,8 +103,9 @@ build-simple: clean
 	export CGO_ENABLED=1
 	$(GO) build \
 		-o dist/ntfy_linux_amd64/ntfy \
+		-tags sqlite_omit_load_extension \
 		-ldflags \
-		"-s -w -X main.version=$(VERSION) -X main.commit=$(shell git rev-parse --short HEAD) -X main.date=$(shell date +%s)"
+		"-linkmode=external -extldflags=-static -s -w -X main.version=$(VERSION) -X main.commit=$(shell git rev-parse --short HEAD) -X main.date=$(shell date +%s)"
 
 clean: .PHONY
 	rm -rf dist build
diff --git a/README.md b/README.md
index 743d8d3..796bc3a 100644
--- a/README.md
+++ b/README.md
@@ -146,8 +146,19 @@ rpm -ivh https://github.com/binwiederhier/ntfy/releases/download/v1.4.5/ntfy_1.4
 ```
 
 **Docker:**
+Without cache:
+```
+docker run -p 80:80 -it binwiederhier/ntfy
+```
+
+With cache:
 ```bash
-docker run --rm -it binwiederhier/ntfy
+docker run \
+  -v /var/cache/ntfy:/var/cache/ntfy \
+  -p 80:80 \
+  -it \
+  binwiederhier/ntfy \
+    --cache-file /var/cache/ntfy/cache.db
 ```
 
 **Go:**
@@ -200,3 +211,4 @@ Third party libraries and resources:
 * [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) (MIT) is used to provide the persistent message cache
 * [Firebase Admin SDK](https://github.com/firebase/firebase-admin-go) (Apache 2.0) is used to send FCM messages
 * [Lightbox with vanilla JS](https://yossiabramov.com/blog/vanilla-js-lightbox) 
+* [Statically linking go-sqlite3](https://www.arp242.net/static-go.html)
-- 
GitLab