summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Dockerfile9
-rw-r--r--Makefile12
-rw-r--r--cmd/generate/main.go44
-rw-r--r--cmd/home/main.go (renamed from main.go)9
-rw-r--r--embed.go7
-rw-r--r--proxy/Dockerfile16
-rw-r--r--proxy/fly.toml22
-rw-r--r--proxy/nginx.conf14
-rwxr-xr-xproxy/start.sh6
-rw-r--r--public/index.html43
-rw-r--r--public/posts.html59
-rw-r--r--public/static/V1-ServerMono-Regular.woff2bin0 -> 19628 bytes
-rw-r--r--templates/index.html44
-rw-r--r--templates/layouts/default.html48
-rw-r--r--templates/layouts/header.html8
-rw-r--r--templates/posts.html4
16 files changed, 332 insertions, 13 deletions
diff --git a/Dockerfile b/Dockerfile
index 7b372e0..672c4e9 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM golang:1.22 as builder
+FROM golang:1.22
WORKDIR /usr/src/app
@@ -6,11 +6,10 @@ COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY . .
-
-RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o /bin/site .
+RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /usr/local/bin/app ./...
FROM scratch
-COPY --from=builder /bin/site /app
-ENTRYPOINT ["/app"]
+COPY --from=0 /usr/local/bin/app /app
+CMD ["/app"]
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d791247
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,12 @@
+.PHONY: fly
+
+fly:
+ cd proxy && fly deploy
+
+.PHONY: content
+content:
+ go run ./cmd/generate
+
+.PHONY: serve
+serve: content
+ go run ./cmd/home
diff --git a/cmd/generate/main.go b/cmd/generate/main.go
new file mode 100644
index 0000000..a739fea
--- /dev/null
+++ b/cmd/generate/main.go
@@ -0,0 +1,44 @@
+package main
+
+import (
+ "fmt"
+ "log"
+ "os"
+ "path/filepath"
+ "text/template"
+)
+
+func Run() error {
+ t, err := template.ParseGlob("./templates/layouts/*.html")
+ // t, err := template.ParseFiles("index.html", "header.html")
+ if err != nil {
+ return fmt.Errorf("Failed to parse layouts: %v", err)
+ }
+
+ for _, page := range []string{"index.html", "posts.html"} {
+ file, err := os.Create(filepath.Join("public", page))
+ if err != nil {
+ return fmt.Errorf("Failed to create file: %v", err)
+ }
+
+ defer file.Close()
+
+ foo, err := t.ParseFiles("./templates/" + page)
+ if err != nil {
+ return fmt.Errorf("Parse template file: %v", err)
+ }
+
+ err = foo.ExecuteTemplate(file, "index.html", nil)
+ if err != nil {
+ return fmt.Errorf("Failed to generate file: %v", err)
+ }
+ }
+
+ return nil
+
+}
+func main() {
+ if err := Run(); err != nil {
+ log.Fatal(err)
+ }
+}
diff --git a/main.go b/cmd/home/main.go
index d594cd1..f284c30 100644
--- a/main.go
+++ b/cmd/home/main.go
@@ -1,18 +1,15 @@
package main
import (
- "embed"
"io/fs"
"log"
"net/http"
"time"
+ "git.sr.ht/~a73x/home"
"go.uber.org/zap"
)
-//go:embed public/index.html
-var content embed.FS
-
func main() {
logger, _ := zap.NewProduction()
loggingMiddleware := func(next http.Handler) http.Handler {
@@ -30,12 +27,12 @@ func main() {
mux := http.NewServeMux()
- staticFs, err := fs.Sub(content, "public")
+ staticFs, err := fs.Sub(home.Content, "public")
if err != nil {
log.Fatal(err)
}
- mux.Handle("/", http.FileServer(http.FS(staticFs)))
+ mux.Handle("GET /", http.FileServer(http.FS(staticFs)))
server := http.Server{
Addr: ":8080",
diff --git a/embed.go b/embed.go
new file mode 100644
index 0000000..182ede2
--- /dev/null
+++ b/embed.go
@@ -0,0 +1,7 @@
+package home
+
+import "embed"
+
+//go:embed public/static/*.woff2
+//go:embed public/*.html
+var Content embed.FS
diff --git a/proxy/Dockerfile b/proxy/Dockerfile
new file mode 100644
index 0000000..012092d
--- /dev/null
+++ b/proxy/Dockerfile
@@ -0,0 +1,16 @@
+FROM nginx:1.27.0-alpine
+
+RUN apk update && apk add ca-certificates iptables ip6tables && rm -rf /var/cache/apk/*
+
+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
+
+WORKDIR /app/
+
+COPY nginx.conf /etc/nginx/conf.d/nginx.conf
+COPY /start.sh /app/start.sh
+
+RUN chmod +x /app/start.sh
+
+CMD ["/app/start.sh"]
diff --git a/proxy/fly.toml b/proxy/fly.toml
new file mode 100644
index 0000000..97bf7b5
--- /dev/null
+++ b/proxy/fly.toml
@@ -0,0 +1,22 @@
+# fly.toml app configuration file generated for home-divine-bush-1861 on 2024-08-11T17:34:11+01:00
+#
+# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
+#
+
+app = 'home-divine-bush-1861'
+primary_region = 'lhr'
+
+[build]
+
+[http_service]
+ internal_port = 8080
+ force_https = true
+ auto_stop_machines = 'stop'
+ auto_start_machines = true
+ min_machines_running = 0
+ processes = ['app']
+
+[[vm]]
+ memory = '1gb'
+ cpu_kind = 'shared'
+ cpus = 1
diff --git a/proxy/nginx.conf b/proxy/nginx.conf
new file mode 100644
index 0000000..4095372
--- /dev/null
+++ b/proxy/nginx.conf
@@ -0,0 +1,14 @@
+server {
+ listen 8080;
+ listen [::]:8080;
+
+ server_name a73x.sh;
+
+
+ location / {
+ proxy_ssl_session_reuse off;
+ proxy_ssl_server_name on;
+ proxy_pass https://home.folk-amberjack.ts.net/;
+ proxy_set_header X-Forwarded-Host $http_host;
+ }
+}
diff --git a/proxy/start.sh b/proxy/start.sh
new file mode 100755
index 0000000..c2c73d6
--- /dev/null
+++ b/proxy/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=fly-app
+
+nginx -g "daemon off;"
diff --git a/public/index.html b/public/index.html
index 3a00176..61413a8 100644
--- a/public/index.html
+++ b/public/index.html
@@ -1,3 +1,4 @@
+
<!DOCTYPE html>
<html lang="en">
@@ -5,14 +6,50 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Home for a73x" />
<meta name="author" content="a73x" />
- <meta name="color-scheme" content="dark light" />
<meta name="viewport"
content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width" />
<title>a73x</title>
+ <style>
+ @font-face {
+ font-family: 'Mono';
+ src: url('./static/V1-ServerMono-Regular.woff2') format('woff2');
+ font-weight: normal;
+ font-style: normal;
+ }
+
+ body {
+ font-family: "Mono";
+ }
+
+ code {
+ font-family: "Mono";
+ color: crimson;
+ background-color: #f1f1f1;
+ padding: 2px;
+ }
+
+ nav ul {
+ display: flex;
+ list-style: none;
+ }
+
+ nav ul li {
+ margin-right: 20px;
+ }
+ </style>
</head>
<body>
- <h1>a73x</h1>
+ <!-- templates/header.html -->
+<h1>a73x</h1>
+<nav>
+ <ul>
+ <li><a href="/">Home</a></li>
+ <li><a href="/posts">Posts</a></li>
+ </ul>
+</nav>
+
+
<ul>
<li>backend cloud software engineer</li>
<li>lang: go</li>
@@ -58,3 +95,5 @@
</body>
</html>
+
+
diff --git a/public/posts.html b/public/posts.html
new file mode 100644
index 0000000..b63f4da
--- /dev/null
+++ b/public/posts.html
@@ -0,0 +1,59 @@
+
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <meta name="description" content="Home for a73x" />
+ <meta name="author" content="a73x" />
+ <meta name="viewport"
+ content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width" />
+ <title>a73x</title>
+ <style>
+ @font-face {
+ font-family: 'Mono';
+ src: url('./static/V1-ServerMono-Regular.woff2') format('woff2');
+ font-weight: normal;
+ font-style: normal;
+ }
+
+ body {
+ font-family: "Mono";
+ }
+
+ code {
+ font-family: "Mono";
+ color: crimson;
+ background-color: #f1f1f1;
+ padding: 2px;
+ }
+
+ nav ul {
+ display: flex;
+ list-style: none;
+ }
+
+ nav ul li {
+ margin-right: 20px;
+ }
+ </style>
+</head>
+
+<body>
+ <!-- templates/header.html -->
+<h1>a73x</h1>
+<nav>
+ <ul>
+ <li><a href="/">Home</a></li>
+ <li><a href="/posts">Posts</a></li>
+ </ul>
+</nav>
+
+
+<h1>Posts</h1>
+
+</body>
+
+</html>
+
+
diff --git a/public/static/V1-ServerMono-Regular.woff2 b/public/static/V1-ServerMono-Regular.woff2
new file mode 100644
index 0000000..6f2c020
--- /dev/null
+++ b/public/static/V1-ServerMono-Regular.woff2
Binary files differ
diff --git a/templates/index.html b/templates/index.html
new file mode 100644
index 0000000..ee1a64c
--- /dev/null
+++ b/templates/index.html
@@ -0,0 +1,44 @@
+{{template "base" .}}
+{{define "content"}}
+ <ul>
+ <li>backend cloud software engineer</li>
+ <li>lang: go</li>
+ <li>infra: kubernetes</li>
+ </ul>
+ <h2>daily learnings</h2>
+ <h3>#go</h3>
+ <ul>
+ <li>layout packages by what they do, not by their abstract type</li>
+ <li>use channels sparingly. write synchronous methods and allow the caller to make it async</li>
+ <li><code>append</code> modifies the underlying slice, you'll only make this mistake once</li>
+ <li>define interfaces where you use them</li>
+ <li><code>make([]int, 5)</code> has a length and capacity of 5. <code>([]int, 0,5)</code> has a length
+ of 0 and capacity of 5.
+ <br />
+ <code>append()</code> will only do what you want with the latter
+ </li>
+ <li>don't use <code>init()</code></li>
+ <li>TFBO (test, fix, benchmark, optimise)</li>
+ </ul>
+ <h3>#git</h3>
+ <ul>
+ <li><code>git commit --fixup=&lt;COMMITSH&gt;</code>
+ <br />
+ <code>git rebase origin/main --autosquash</code>
+ </li>
+ </ul>
+
+ <h2>Books</h2>
+ <ul>
+ <li><a href=https://www.oreilly.com/library/view/designing-data-intensive-applications/9781491903063 />Designing
+ Data Intensive Applications</a></li>
+ <li><a href=https://www.oreilly.com/library/view/database-internals/9781492040330 />Database Internals
+ </a>
+ </li>
+ <li>
+ <a href=https://www.oreilly.com/library/view/efficient-go/9781098105709 /> Efficient Go</a>
+
+ </li>
+
+ </ul>
+{{end}}
diff --git a/templates/layouts/default.html b/templates/layouts/default.html
new file mode 100644
index 0000000..cfb0c17
--- /dev/null
+++ b/templates/layouts/default.html
@@ -0,0 +1,48 @@
+{{define "base"}}
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <meta name="description" content="Home for a73x" />
+ <meta name="author" content="a73x" />
+ <meta name="viewport"
+ content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width" />
+ <title>a73x</title>
+ <style>
+ @font-face {
+ font-family: 'Mono';
+ src: url('./static/V1-ServerMono-Regular.woff2') format('woff2');
+ font-weight: normal;
+ font-style: normal;
+ }
+
+ body {
+ font-family: "Mono";
+ }
+
+ code {
+ font-family: "Mono";
+ color: crimson;
+ background-color: #f1f1f1;
+ padding: 2px;
+ }
+
+ nav ul {
+ display: flex;
+ list-style: none;
+ }
+
+ nav ul li {
+ margin-right: 20px;
+ }
+ </style>
+</head>
+
+<body>
+ {{ template "header.html" . }}
+ {{ template "content" . }}
+</body>
+
+</html>
+{{end}}
diff --git a/templates/layouts/header.html b/templates/layouts/header.html
new file mode 100644
index 0000000..be02def
--- /dev/null
+++ b/templates/layouts/header.html
@@ -0,0 +1,8 @@
+<!-- templates/header.html -->
+<h1>a73x</h1>
+<nav>
+ <ul>
+ <li><a href="/">Home</a></li>
+ <li><a href="/posts">Posts</a></li>
+ </ul>
+</nav>
diff --git a/templates/posts.html b/templates/posts.html
new file mode 100644
index 0000000..75d3801
--- /dev/null
+++ b/templates/posts.html
@@ -0,0 +1,4 @@
+{{template "base" .}}
+{{define "content"}}
+<h1>Posts</h1>
+{{end}}