Skip to content

Commit 0b4876c

Browse files
authored
Merge pull request #2 from JonSchaeffer/better-build-support
Better build support
2 parents 2b056f0 + 818fa55 commit 0b4876c

File tree

29 files changed

+652
-54
lines changed

29 files changed

+652
-54
lines changed

.github/workflows/docker.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build and Push Docker Images
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: ${{ github.repository }}
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
strategy:
19+
matrix:
20+
component: [backend, frontend]
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Log in to Container Registry
27+
uses: docker/login-action@v3
28+
with:
29+
registry: ${{ env.REGISTRY }}
30+
username: ${{ github.actor }}
31+
password: ${{ github.token }}
32+
33+
- name: Extract metadata (tags, labels) for Docker
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-${{ matrix.component }}
38+
tags: |
39+
type=ref,event=branch
40+
type=ref,event=pr
41+
type=semver,pattern={{version}}
42+
type=semver,pattern={{major}}.{{minor}}
43+
type=semver,pattern={{major}}
44+
type=sha
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v3
48+
49+
- name: Build and push Docker image
50+
uses: docker/build-push-action@v5
51+
with:
52+
context: ./${{ matrix.component }}
53+
file: ./${{ matrix.component }}/Dockerfile
54+
push: ${{ github.event_name != 'pull_request' }}
55+
tags: ${{ steps.meta.outputs.tags }}
56+
labels: ${{ steps.meta.outputs.labels }}
57+
cache-from: type=gha
58+
cache-to: type=gha,mode=max
59+
platforms: linux/amd64

.github/workflows/main.yaml

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

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"]

backend/config/config.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package config
2+
3+
import (
4+
"os"
5+
)
6+
7+
type Config struct {
8+
DatabaseURL string
9+
FiveFiltersURL string
10+
Port string
11+
}
12+
13+
func Load() *Config {
14+
return &Config{
15+
DatabaseURL: getEnv("DATABASE_URL", "postgres://postgres:postgres@postgres:5432"),
16+
FiveFiltersURL: getEnv("FIVEFILTERS_URL", "http://fivefilters-service:8081"),
17+
Port: getEnv("PORT", "8080"),
18+
}
19+
}
20+
21+
func getEnv(key, fallback string) string {
22+
if value := os.Getenv(key); value != "" {
23+
return value
24+
}
25+
return fallback
26+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)