docker
change
commit 6c8879b63b30a30872ab69561da41819caad4c32
author Alpha Chen <alpha@kejadlen.dev>
date
parent a0bc3a05
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..ac3cebc
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,21 @@
+# https://tailscale.com/kb/1132/flydotio
+# https://github.com/docker/awesome-compose/blob/master/flask/app/Dockerfile
+
+FROM python:3.12-alpine
+RUN apk update && apk add ca-certificates iptables ip6tables && rm -rf /var/cache/apk/*
+
+WORKDIR /app
+
+COPY requirements.txt .
+RUN --mount=type=cache,target=/root/.cache/pip \
+    pip3 install -r requirements.txt
+
+COPY . /app
+
+# Copy Tailscale binaries from the tailscale image on Docker Hub.
+COPY --from=docker.io/tailscale/tailscale:stable /usr/local/bin/tailscaled /app/tailscaled
+COPY --from=docker.io/tailscale/tailscale:stable /usr/local/bin/tailscale /app/tailscale
+RUN mkdir -p /var/run/tailscale /var/cache/tailscale /var/lib/tailscale
+
+# Run on container startup.
+CMD ["/app/start.sh"]
diff --git a/Makefile b/Makefile
index 2cc0fdf..2d06854 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,15 @@ all: requirements.txt dev-requirements.txt
 dev:
 	fd ".*.(html|py)$$" | entr -r flask --app go_ji run
 
+.PHONY: docker
+docker:
+	docker build -t go-ji .
+	docker run \
+		--cap-add=NET_ADMIN \
+		--device=/dev/net/tun \
+		-e=TAILSCALE_AUTHKEY=$$TAILSCALE_AUTHKEY \
+		go-ji
+
 .PHONY: upgrade-deps
 upgrade-deps:
 	pip-compile --upgrade
diff --git a/start.sh b/start.sh
new file mode 100755
index 0000000..47981b7
--- /dev/null
+++ b/start.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+/app/tailscaled --state=/var/lib/tailscale/tailscaled.state --socket=/var/run/tailscale/tailscaled.sock &
+/app/tailscale up --authkey=${TAILSCALE_AUTHKEY} --hostname=go-ji
+
+gunicorn go_ji:app