about summary refs log tree commit diff
path: root/tools
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2021-08-12 13:53:33 -0700
committerFranck Cuny <franck@fcuny.net>2021-08-12 15:46:24 -0700
commitaa80df2b26c7455007d3db96f01bfde66c6779df (patch)
tree00cc4724a8362d0edad8de1f13be408f1df17ba6 /tools
parentconfig: replace homelab with tools (diff)
downloadworld-aa80df2b26c7455007d3db96f01bfde66c6779df.tar.gz
build: deploy to fly
Don't deploy to Google App anymore, but use fly.io instead.

Add steps to the Makefile to build a docker image, and to deploy the
application to fly.io.
Diffstat (limited to '')
-rw-r--r--tools/govanity/Dockerfile13
-rw-r--r--tools/govanity/Makefile31
-rw-r--r--tools/govanity/README.md5
-rw-r--r--tools/govanity/README.org11
-rw-r--r--tools/govanity/app.yaml6
-rw-r--r--tools/govanity/fly.toml34
6 files changed, 83 insertions, 17 deletions
diff --git a/tools/govanity/Dockerfile b/tools/govanity/Dockerfile
new file mode 100644
index 0000000..caca19a
--- /dev/null
+++ b/tools/govanity/Dockerfile
@@ -0,0 +1,13 @@
+FROM golang:1.16-alpine
+
+WORKDIR /src
+
+ADD go.mod /src
+ADD go.sum /src
+RUN go mod download
+
+ADD . /src
+
+RUN go build -o app .
+
+ENTRYPOINT ["/src/app"]
diff --git a/tools/govanity/Makefile b/tools/govanity/Makefile
index e9ffe64..a826abe 100644
--- a/tools/govanity/Makefile
+++ b/tools/govanity/Makefile
@@ -1,9 +1,28 @@
-.PHONY: deploy
+DOCKER := docker
+DOCKER_BUILD_ARGS :=
+DOCKER_IMAGE := fcuny/golang.fcuny.net
+DOCKER_IMAGE_REF := $(shell git rev-parse HEAD)
+DOCKERFILE := Dockerfile
+PROJECT_DIR := $(realpath $(CURDIR))
+
+.PHONY: deploy docker-build docker-run
+
+server:
+	@echo "Running server ..."
+	go run .
+
 deploy:
-	gcloud -q app deploy --project=fcuny-govanity
+	@echo "Deploying to fly ..."
+	flyctl deploy --build-arg IMAGE_REF=$(DOCKER_IMAGE_REF)
 
-.PHONY: console
-	gcloud -q app open-console --project=fcuny-govanity
+docker-build:
+	@echo "Building Docker image ..."
+	$(DOCKER) build $(DOCKER_BUILD_ARGS) \
+		--tag "${DOCKER_IMAGE}:${DOCKER_IMAGE_REF}" \
+	  --build-arg IMAGE_REF=$(DOCKER_IMAGE_REF) \
+		--file "$(DOCKERFILE)" \
+		"$(PROJECT_DIR)"
 
-.PHONY: all
-all: deploy
+docker-run: docker-build
+	@echo "Running Docker image ..."
+	$(DOCKER) run -ti --rm -p 8080:8080 $(DOCKER_IMAGE):$(DOCKER_IMAGE_REF)
diff --git a/tools/govanity/README.md b/tools/govanity/README.md
deleted file mode 100644
index 0c1f061..0000000
--- a/tools/govanity/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-A service to manage vanity URLs for go packages.
-
-## Deployment
-
-To update the application with the most recent code, run `make all`.
diff --git a/tools/govanity/README.org b/tools/govanity/README.org
new file mode 100644
index 0000000..e2da852
--- /dev/null
+++ b/tools/govanity/README.org
@@ -0,0 +1,11 @@
+A service to manage vanity URLs for go packages.
+
+It makes it possible to install tools like this:
+#+begin_src sh
+GOPRIVATE=1 go install -v golang.fcuny.net/tools/cmd/music-organizer@latest
+#+end_src
+
+* Deployment
+To update the application with the most recent code, run =make deploy=.
+* Configuration
+Add repositories to the [[file+sys:vanity.yaml][configuration file]].
diff --git a/tools/govanity/app.yaml b/tools/govanity/app.yaml
deleted file mode 100644
index 40f1c9f..0000000
--- a/tools/govanity/app.yaml
+++ /dev/null
@@ -1,6 +0,0 @@
-runtime: go
-api_version: go1
-
-handlers:
-  - url: /.*
-    script: _go_app
diff --git a/tools/govanity/fly.toml b/tools/govanity/fly.toml
new file mode 100644
index 0000000..286cd1e
--- /dev/null
+++ b/tools/govanity/fly.toml
@@ -0,0 +1,34 @@
+app = "golang-fcuny-net"
+
+kill_signal = "SIGINT"
+kill_timeout = 5
+
+[env]
+
+[experimental]
+  allowed_public_ports = []
+  auto_rollback = true
+
+[[services]]
+  internal_port = 8080
+  protocol = "tcp"
+  script_checks = []
+
+  [services.concurrency]
+    hard_limit = 25
+    soft_limit = 20
+    type = "connections"
+
+  [[services.ports]]
+    handlers = ["http"]
+    port = 80
+
+  [[services.ports]]
+    handlers = ["tls", "http"]
+    port = 443
+
+  [[services.tcp_checks]]
+    grace_period = "1s"
+    interval = "15s"
+    restart_limit = 6
+    timeout = "2s"