- commit
- e65a196
- parent
- 8d3fd1e
- author
- Antonio Mika
- date
- 2022-07-31 16:34:43 +0000 UTC
Simplified build system and speed up builds
12 files changed,
+95,
-194
+15,
-0
1@@ -0,0 +1,15 @@
2+*.log
3+*.swp
4+.env
5+.envrc
6+build/*
7+!build/.gitkeep
8+ssh_data/*
9+!ssh_data/.gitkeep
10+caddy_data/*
11+!caddy_data/.gitkeep
12+caddy_config/*
13+!caddy_config/.gitkeep
14+.env.prod
15+*.bak
16+Dockerfile*
R prose/Caddyfile =>
Caddyfile
+4,
-4
1@@ -6,10 +6,10 @@
2 }
3 }
4
5-*.prose.sh, prose.sh {
6+*.{$APP_DOMAIN}, {$APP_DOMAIN} {
7 reverse_proxy web:3000
8- tls hello@prose.sh {
9- dns cloudflare {env.CF_API_TOKEN}
10+ tls hello@{$APP_DOMAIN} {
11+ dns cloudflare {$CF_API_TOKEN}
12 }
13 encode zstd gzip
14
15@@ -37,7 +37,7 @@
16
17 :443 {
18 reverse_proxy web:3000
19- tls hello@prose.sh {
20+ tls hello@{$APP_DOMAIN} {
21 on_demand
22 }
23 encode zstd gzip
+61,
-0
1@@ -0,0 +1,61 @@
2+FROM --platform=$BUILDPLATFORM golang:1.18-alpine as builder-deps
3+LABEL maintainer="Pico Maintainers <hello@pico.sh>"
4+
5+ENV CGO_ENABLED 0
6+
7+WORKDIR /app
8+
9+RUN apk add --no-cache git
10+
11+COPY go.* ./
12+
13+RUN go mod download
14+
15+FROM builder-deps as builder
16+
17+COPY . .
18+
19+ARG APP=lists
20+ARG TARGETOS=linux
21+ARG TARGETARCH=amd64
22+
23+ENV GOOS=${TARGETOS} GOARCH=${TARGETARCH}
24+
25+RUN go build -o /go/bin/${APP}-ssh -ldflags="-s -w" ./cmd/${APP}/ssh
26+RUN go build -o /go/bin/${APP}-web -ldflags="-s -w" ./cmd/${APP}/web
27+RUN [[ "${APP}" == "lists" ]] && go build -o /go/bin/${APP}-gemini -ldflags="-s -w" ./cmd/${APP}/gemini || true
28+
29+FROM scratch as release-ssh
30+
31+WORKDIR /app
32+
33+ARG APP=lists
34+
35+COPY --from=builder /go/bin/${APP}-ssh ./ssh
36+
37+ENTRYPOINT ["/app/ssh"]
38+
39+FROM scratch as release-web
40+
41+WORKDIR /app
42+
43+ARG APP=lists
44+
45+COPY --from=builder /go/bin/${APP}-web ./web
46+COPY --from=builder /app/${APP}/html ./${APP}/html
47+COPY --from=builder /app/${APP}/public ./${APP}/public
48+
49+ENTRYPOINT ["/app/web"]
50+
51+FROM scratch as release-gemini
52+
53+WORKDIR /app
54+
55+ARG APP=lists
56+
57+ENV LISTS_SUBDOMAINS=0
58+
59+COPY --from=builder /go/bin/${APP}-gemini ./gemini
60+COPY --from=builder /app/lists/gmi ./${APP}/gmi
61+
62+ENTRYPOINT ["/app/gemini"]
+0,
-29
1@@ -1,29 +0,0 @@
2-FROM golang:1.18.1-alpine3.15 AS builder
3-
4-RUN apk add --no-cache git
5-
6-WORKDIR /app
7-COPY . ./
8-
9-RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ./build/ssh ./cmd/lists/ssh
10-RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ./build/web ./cmd/lists/web
11-RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ./build/gemini ./cmd/lists/gemini
12-
13-FROM alpine:3.15 AS ssh
14-WORKDIR /app
15-COPY --from=0 /app/build/ssh ./
16-CMD ["./ssh"]
17-
18-FROM alpine:3.15 AS web
19-WORKDIR /app
20-COPY --from=0 /app/build/web ./
21-COPY --from=0 /app/html ./html
22-COPY --from=0 /app/public ./public
23-CMD ["./web"]
24-
25-FROM alpine:3.15 AS gemini
26-WORKDIR /app
27-COPY --from=0 /app/build/gemini ./
28-COPY --from=0 /app/gmi ./gmi
29-ENV LISTS_SUBDOMAINS=0
30-CMD ["./gemini"]
+0,
-8
1@@ -1,8 +0,0 @@
2-FROM caddy:builder-alpine AS builder
3-
4-RUN xcaddy build \
5- --with github.com/caddy-dns/cloudflare
6-
7-FROM caddy:alpine
8-
9-COPY --from=builder /usr/bin/caddy /usr/bin/caddy
+0,
-21
1@@ -1,21 +0,0 @@
2-DOCKER_TAG?=$(shell git log --format="%H" -n 1)
3-
4-bp-setup:
5- docker buildx ls | grep pico || docker buildx create --name pico
6- docker buildx use pico
7-.PHONY: bp-setup
8-
9-bp-ssh: bp-setup
10- docker buildx build --push --platform linux/amd64,linux/arm64 -t neurosnap/lists-ssh:$(DOCKER_TAG) --target ssh -f Dockerifle ..
11-.PHONY: bp-ssh
12-
13-bp-web: bp-setup
14- docker buildx build --push --platform linux/amd64,linux/arm64 -t neurosnap/lists-web:$(DOCKER_TAG) --target web -f Dockerfile ..
15-.PHONY: bp-web
16-
17-bp-gemini: bp-setup
18- docker buildx build --push --platform linux/amd64,linux/arm64 -t neurosnap/lists-gemini:$(DOCKER_TAG) --target gemini -f Dockerfile ..
19-.PHONY: bp-gemini
20-
21-bp: bp-ssh bp-web bp-gemini
22-.PHONY: bp
M
makefile
+15,
-29
1@@ -4,10 +4,12 @@ PGUSER?="postgres"
2 PORT?="5432"
3 DB_CONTAINER?=pico-services_db_1
4 DOCKER_TAG?=$(shell git log --format="%H" -n 1)
5+DOCKER_PLATFORM?=linux/amd64,linux/arm64
6+DOCKER_BUILDX_BUILD?=docker buildx build --push --platform $(DOCKER_PLATFORM)
7
8-test:
9+lint:
10 docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:latest golangci-lint run -E goimports -E godot
11-.PHONY: test
12+.PHONY: lint
13
14 bp-setup:
15 docker buildx ls | grep pico || docker buildx create --name pico
16@@ -15,39 +17,23 @@ bp-setup:
17 .PHONY: bp-setup
18
19 bp-caddy: bp-setup
20- docker buildx build --push --platform linux/amd64,linux/arm64 -t neurosnap/cloudflare-caddy:$(DOCKER_TAG) -f Dockerfile.caddy .
21+ $(DOCKER_BUILDX_BUILD) -t neurosnap/cloudflare-caddy:$(DOCKER_TAG) -f Dockerfile.caddy .
22 .PHONY: bp-caddy
23
24-bp-prose:
25- $(MAKE) -C prose bp
26-.PHONY: bp-prose
27-
28-bp-pastes:
29- $(MAKE) -C pastes bp
30-.PHONY: bp-pastes
31-
32-bp-lists:
33- $(MAKE) -C lists bp
34-.PHONY: bp-lists
35+bp-%: bp-setup
36+ $(DOCKER_BUILDX_BUILD) --build-arg "APP=$*" -t "neurosnap/$*-ssh:$(DOCKER_TAG)" --target release-ssh .
37+ $(DOCKER_BUILDX_BUILD) --build-arg "APP=$*" -t "neurosnap/$*-web:$(DOCKER_TAG)" --target release-web .
38+ [[ "$*" == "lists" ]] && $(DOCKER_BUILDX_BUILD) --build-arg "APP=$*" -t "neurosnap/$*-gemini:$(DOCKER_TAG)" --target release-gemini . || true
39+.PHONY: bp-%
40
41 bp-all: bp-prose bp-lists bp-pastes
42 .PHONY: bp-all
43
44-build-prose:
45- go build -o build/prose-web ./cmd/prose/web
46- go build -o build/prose-ssh ./cmd/prose/ssh
47-.PHONY: build-prose
48-
49-build-lists:
50- go build -o build/lists-web ./cmd/lists/web
51- go build -o build/lists-ssh ./cmd/lists/ssh
52- go build -o build/lists-gemini ./cmd/lists/gemini
53-.PHONY: build-lists
54-
55-build-pastes:
56- go build -o build/pastes-web ./cmd/pastes/web
57- go build -o build/pastes-ssh ./cmd/pastes/ssh
58-.PHONY: build-pastes
59+build-%:
60+ go build -o "build/$*-web" "./cmd/$*/web"
61+ go build -o "build/$*-ssh" "./cmd/$*/ssh"
62+ [[ "$*" == "lists" ]] && go build -o "build/$*-gemini" "./cmd/$*/gemini" || true
63+.PHONY: build-%
64
65 build: build-prose build-lists build-pastes
66 .PHONY: build
+0,
-27
1@@ -1,27 +0,0 @@
2-*.pastes.sh, pastes.sh {
3- reverse_proxy web:3000
4- tls hello@pastes.sh
5- tls {
6- dns cloudflare {env.CF_API_TOKEN}
7- }
8- encode zstd gzip
9-
10- header {
11- # disable FLoC tracking
12- Permissions-Policy interest-cohort=()
13-
14- # enable HSTS
15- Strict-Transport-Security max-age=31536000;
16-
17- # disable clients from sniffing the media type
18- X-Content-Type-Options nosniff
19-
20- # clickjacking protection
21- X-Frame-Options DENY
22-
23- # keep referrer data off of HTTP connections
24- Referrer-Policy no-referrer-when-downgrade
25-
26- X-XSS-Protection "1; mode=block"
27- }
28-}
+0,
-21
1@@ -1,21 +0,0 @@
2-FROM golang:1.18.1-alpine3.15 AS builder
3-
4-RUN apk add --no-cache git
5-
6-WORKDIR /app
7-COPY . ./
8-
9-RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ./build/ssh ./cmd/pastes/ssh
10-RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ./build/web ./cmd/pastes/web
11-
12-FROM alpine:3.15 AS ssh
13-WORKDIR /app
14-COPY --from=0 /app/build/ssh ./
15-CMD ["./ssh"]
16-
17-FROM alpine:3.15 AS web
18-WORKDIR /app
19-COPY --from=0 /app/build/web ./
20-COPY --from=0 /app/html ./html
21-COPY --from=0 /app/public ./public
22-CMD ["./web"]
+0,
-17
1@@ -1,17 +0,0 @@
2-DOCKER_TAG?=$(shell git log --format="%H" -n 1)
3-
4-bp-setup:
5- docker buildx ls | grep pico || docker buildx create --name pico
6- docker buildx use pico
7-.PHONY: bp-setup
8-
9-bp-ssh: bp-setup
10- docker buildx build --push --platform linux/amd64,linux/arm64 -t neurosnap/pastes-ssh:$(DOCKER_TAG) --target ssh -f Dockerfile ..
11-.PHONY: bp-ssh
12-
13-bp-web: bp-setup
14- docker buildx build --push --platform linux/amd64,linux/arm64 -t neurosnap/pastes-web:$(DOCKER_TAG) --target web -f Dockerfile ..
15-.PHONY: bp-web
16-
17-bp: bp-ssh bp-web
18-.PHONY: bp
+0,
-21
1@@ -1,21 +0,0 @@
2-FROM golang:1.18.1-alpine3.15 AS builder
3-
4-RUN apk add --no-cache git
5-
6-WORKDIR /app
7-COPY . ./
8-
9-RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ./build/ssh ./cmd/prose/ssh
10-RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ./build/web ./cmd/prose/web
11-
12-FROM alpine:3.15 AS ssh
13-WORKDIR /app
14-COPY --from=0 /app/build/ssh ./
15-CMD ["./ssh"]
16-
17-FROM alpine:3.15 AS web
18-WORKDIR /app
19-COPY --from=0 /app/build/web ./
20-COPY --from=0 /app/html ./html
21-COPY --from=0 /app/public ./public
22-CMD ["./web"]
+0,
-17
1@@ -1,17 +0,0 @@
2-DOCKER_TAG?=$(shell git log --format="%H" -n 1)
3-
4-bp-setup:
5- docker buildx ls | grep pico || docker buildx create --name pico
6- docker buildx use pico
7-.PHONY: bp-setup
8-
9-bp-ssh: bp-setup
10- docker buildx build --push --platform linux/amd64,linux/arm64 -t neurosnap/prose-ssh:$(DOCKER_TAG) --target ssh -f Dockerfile ..
11-.PHONY: bp-ssh
12-
13-bp-web: bp-setup
14- docker buildx build --push --platform linux/amd64,linux/arm64 -t neurosnap/prose-web:$(DOCKER_TAG) --target web -f Dockerfile ..
15-.PHONY: bp-web
16-
17-bp: bp-ssh bp-web
18-.PHONY: bp