Skip to content

Commit cde3fc9

Browse files
committed
Compile images ahead of time.
1 parent 26759b3 commit cde3fc9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+14290
-10405
lines changed

.github/dependabot.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ updates:
1313
- package-ecosystem: github-actions
1414
directory: /
1515
schedule:
16-
interval: daily
16+
interval: daily
17+
18+
- package-ecosystem: npm
19+
directory: /
20+
schedule:
21+
interval: daily

.github/workflows/ci.yml

+46-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ name: CI
33
on: pull_request
44

55
jobs:
6-
build:
7-
name: Build and test
8-
6+
test-go:
7+
name: Build and test Go code
98
runs-on: ubuntu-latest
109

1110
steps:
@@ -18,8 +17,51 @@ jobs:
1817
- name: Install dependencies
1918
run: docker exec ci apk add gcc git imagemagick-dev make musl-dev pkgconfig vips-dev
2019

20+
- name: Mark the directory as safe when mounted into the container
21+
run: docker exec ci git config --global --add safe.directory /usr/src/app
22+
2123
- name: Build
22-
run: docker exec -w /usr/src/app ci make
24+
run: docker exec -w /usr/src/app ci make server img-out
25+
26+
- name: Build with ImageMagick7 support
27+
run: docker exec -w /usr/src/app ci make image-resizer GOTAGS='-tags magick'
2328

2429
- name: Run tests
2530
run: docker exec -w /usr/src/app ci go test ./...
31+
32+
lint-go:
33+
runs-on: ubuntu-latest
34+
name: Lint Go Code
35+
36+
steps:
37+
- name: Check out the repo
38+
uses: actions/checkout@v3
39+
40+
- name: Start the CI container
41+
run: docker run -d --name ci -v $PWD:/app golangci/golangci-lint:latest-alpine sleep infinity
42+
43+
- name: Install dependencies
44+
run: docker exec ci apk add gcc imagemagick-dev musl-dev pkgconfig vips-dev
45+
46+
- name: golangci-lint
47+
run: docker exec -w /app ci golangci-lint run -v --timeout 3m --build-tags magick --out-format=github-actions
48+
49+
# test-js:
50+
# name: Build and test Javascript code
51+
# runs-on: ubuntu-latest
52+
#
53+
# steps:
54+
# - name: Check out code into the Go module directory
55+
# uses: actions/checkout@v2
56+
#
57+
# - uses: actions/setup-node@v2
58+
# with:
59+
# node-version: '17'
60+
# cache: 'npm'
61+
#
62+
# - run: npm install
63+
#
64+
# - run: npm test
65+
#
66+
# - name: Build the webapp
67+
# run: make webapp

.gitignore

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@
44
# IDE
55
.idea/
66

7-
# compiled binary
8-
quba-fr
7+
# built files
8+
image-resizer
9+
server
10+
dist/
11+
img-out
12+
13+
# Node stuff
14+
node_modules

Dockerfile

+36-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
1-
FROM golang:1.18-alpine as builder
1+
FROM golang:1.18-alpine as go-builder
22

33
RUN ["apk", "add", "gcc", "git", "imagemagick-dev", "make", "musl-dev", "pkgconfig", "vips-dev"]
44

55
WORKDIR /usr/src/app
66

7-
COPY . .
7+
RUN ["mkdir", "/web-src"]
88

9-
RUN ["make"]
9+
COPY cmd/ cmd/
10+
COPY config/ config/
11+
COPY img-src/ img-src/
12+
COPY internal/ internal/
13+
COPY Makefile Makefile
14+
COPY go.mod go.mod
15+
COPY go.sum go.sum
16+
COPY pkg/ pkg/
1017

11-
FROM alpine
18+
RUN ["make", "server", "img-out"]
19+
20+
FROM node:17-alpine as node-builder
21+
22+
RUN ["apk", "add", "make"]
23+
24+
RUN ["mkdir", "/build"]
25+
WORKDIR /build
1226

13-
COPY --from=builder /usr/src/app/quba-fr /quba-fr
27+
RUN ["mkdir", "dist"]
28+
29+
COPY config/ config/
30+
COPY Makefile .
31+
COPY package.json .
32+
COPY package-lock.json .
33+
COPY tsconfig.json .
34+
COPY webpack.config.js .
35+
COPY web-src/ web-src/
36+
37+
RUN ["npm", "install", "."]
38+
RUN ["make", "webapp"]
39+
40+
FROM alpine
1441

15-
RUN ["apk", "add", "--no-cache", "imagemagick", "vips"]
42+
COPY --from=go-builder /usr/src/app/server /server
43+
COPY --from=go-builder /usr/src/app/img-out /img-out
44+
COPY --from=node-builder /build/dist /dist
1645

1746
EXPOSE 8080/tcp
1847

1948
LABEL org.opencontainers.image.source https://github.com/qbarrand/quba.fr
2049

21-
ENTRYPOINT ["/quba-fr"]
50+
ENTRYPOINT ["/server", "-img-out-dir", "img-out", "-webroot-dir", "dist"]

Makefile

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
all: quba-fr
1+
all: img-out server webapp
22

3-
quba-fr: $(shell find . -type f -name '*.go') go.mod go.sum
4-
go build -o $@
3+
image-resizer: $(shell find . -name '*.go' -type f) go.mod go.sum
4+
go build -o $@ $(GOTAGS) ./cmd/image-resizer
5+
6+
img-out: image-resizer $(wildcard img-src/*)
7+
mkdir -p $@
8+
./$< -img-out-dir $@ -img-in-dir img-src -processor vips
9+
10+
webapp:
11+
npx webpack --mode production
12+
13+
server: $(shell find . -name '*.go' -type f) go.mod go.sum
14+
go build -o $@ $(GOTAGS) ./cmd/server
515

616
clean:
7-
rm quba-fr
17+
rm -fr img-out
18+
rm -f aot-images
19+
rm -f server

cmd/image-resizer/imagick.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// +build magick
2+
3+
package main
4+
5+
import "github.com/qbarrand/quba.fr/internal/imgpro"
6+
7+
func init() {
8+
processorMap["magick"] = &imgpro.ImageMagickProcessor{}
9+
}

0 commit comments

Comments
 (0)