Skip to content

Commit 64e5c8d

Browse files
committed
refactor backend into its own folder, add tilt and k8s things for local dev
1 parent 2b056f0 commit 64e5c8d

24 files changed

+532
-26
lines changed

Dockerfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

Dockerfile-dev

Lines changed: 0 additions & 10 deletions
This file was deleted.

backend/.air.toml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
root = "."
2+
testdata_dir = "testdata"
3+
tmp_dir = "/tmp"
4+
5+
[build]
6+
args_bin = []
7+
bin = "/tmp/main"
8+
cmd = "go build -o /tmp/main ."
9+
delay = 1000
10+
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
11+
exclude_file = []
12+
exclude_regex = ["_test.go"]
13+
exclude_unchanged = false
14+
follow_symlink = false
15+
full_bin = ""
16+
include_dir = []
17+
include_ext = ["go", "tpl", "tmpl", "html"]
18+
include_file = []
19+
kill_delay = "0s"
20+
log = "/tmp/build-errors.log"
21+
poll = false
22+
poll_interval = 0
23+
post_cmd = []
24+
pre_cmd = []
25+
rerun = false
26+
rerun_delay = 500
27+
send_interrupt = false
28+
stop_on_error = false
29+
30+
[color]
31+
app = ""
32+
build = "yellow"
33+
main = "magenta"
34+
runner = "green"
35+
watcher = "cyan"
36+
37+
[log]
38+
main_only = false
39+
silent = false
40+
time = false
41+
42+
[misc]
43+
clean_on_exit = false
44+
45+
[proxy]
46+
app_port = 0
47+
enabled = false
48+
proxy_port = 0
49+
50+
[screen]
51+
clear_on_rebuild = false
52+
keep_scroll = true

backend/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM golang:1.24.3-alpine3.22 AS builder
2+
3+
WORKDIR /app
4+
5+
# Copy go mod files first
6+
COPY go.mod go.sum ./
7+
RUN go mod download
8+
9+
# Copy only backend source files
10+
COPY . .
11+
12+
# Build the binary
13+
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
14+
15+
# Final stage
16+
FROM alpine:3.19
17+
RUN apk --no-cache add ca-certificates
18+
WORKDIR /app
19+
COPY --from=builder /app/main .
20+
EXPOSE 8080
21+
CMD ["./main"]

backend/Dockerfile-dev

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM golang:1.24.3-alpine3.22
2+
3+
WORKDIR /app
4+
5+
# Install Air for hot reloading
6+
RUN go install github.com/air-verse/air@latest
7+
8+
# Copy go mod files first for better caching
9+
COPY go.mod go.sum ./
10+
RUN go mod download
11+
12+
# Copy all source code including .air.toml
13+
COPY . .
14+
15+
# Set Go build cache to writable locations
16+
ENV GOCACHE=/tmp/go-cache
17+
ENV GOMODCACHE=/tmp/go-mod-cache
18+
19+
# Create cache directories
20+
RUN mkdir -p /tmp/go-cache /tmp/go-mod-cache
21+
22+
EXPOSE 8080
23+
24+
CMD ["air", "-c", ".air.toml"]
File renamed without changes.
File renamed without changes.

db/rss.go renamed to backend/db/rss.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func CreateRSSTable() error {
5151
return err
5252
}
5353

54-
// Create table without foreign key constraint first
54+
// Create table with categoryID column
5555
query := `
5656
CREATE TABLE IF NOT EXISTS rss (
5757
id SERIAL PRIMARY KEY,
@@ -61,10 +61,16 @@ func CreateRSSTable() error {
6161
description TEXT,
6262
feedSize INT,
6363
sync INT,
64+
categoryID INT,
6465
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
6566
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
6667
67-
CONSTRAINT unique_rss_url UNIQUE (url)
68+
CONSTRAINT unique_rss_url UNIQUE (url),
69+
CONSTRAINT fk_rss_category
70+
FOREIGN KEY (categoryID)
71+
REFERENCES category(id)
72+
ON DELETE SET NULL
73+
ON UPDATE CASCADE
6874
)`
6975
_, err := DB.Exec(context.Background(), query)
7076
if err != nil {
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)