Explorar o código

IMG-43: run hooks in the docker, switch to v4-dev image (#1554)

* Use v4-dev docker image

* Updated devcontainer
Victor Sokolov hai 4 meses
pai
achega
f7b9dc8f56

+ 0 - 65
.devcontainer/Dockerfile

@@ -1,65 +0,0 @@
-ARG BASE_IMAGE=ghcr.io/imgproxy/imgproxy-base:latest
-
-# Git build stage
-FROM ${BASE_IMAGE} AS build
-
-ARG LYCHEE_VERSION="0.19.1"
-ARG GIT_VERSION="2.49.1"
-
-# lsb-release and gnupg are needed for the LLVM repository
-# TCL and gettext are needed for git
-RUN apt-get install -y lsb-release tcl gettext autoconf libz-dev libcurl4-openssl-dev
-
-# Install updated git
-RUN curl -O https://www.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.gz && \
-  tar -zxf git-${GIT_VERSION}.tar.gz && \
-  cd git-${GIT_VERSION} && \
-  make configure && \
-  ./configure prefix=/usr/git && \
-  make all && \
-  make install && \
-  rm -rf git-${GIT_VERSION}
-
-# Get lychee binary
-RUN curl -L "https://github.com/lycheeverse/lychee/releases/download/lychee-v${LYCHEE_VERSION}/lychee-$(uname -m)-unknown-linux-gnu.tar.gz" | \
-  tar -zxf -
-
-# Development container
-FROM ${BASE_IMAGE}
-
-ENV GOPATH=$HOME/go
-ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin
-
-# gnupg is requiered for clang-format
-RUN apt-get install -y gnupg lsb-release ssh
-
-# Install air
-RUN go install github.com/air-verse/air@latest
-
-# Install lefthook
-RUN go install github.com/evilmartians/lefthook@latest
-
-# Install gotestsum
-RUN go install gotest.tools/gotestsum@latest
-
-# Install golangci-lint
-RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.1.6
-
-# Copy git from the git build stage
-COPY --from=build /usr/git /usr
-
-# Add the LLVM GPG key
-RUN curl https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor -o /usr/share/keyrings/llvm.gpg
-
-# Add the LLVM 20 APT repo
-RUN echo "deb [signed-by=/usr/share/keyrings/llvm.gpg] https://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-20 main" \
-  | tee /etc/apt/sources.list.d/llvm.list
-
-# Install clang-format-20
-RUN apt-get -y update && apt-get -y install clang-format-20
-
-# Use clang-format-20 as the default clang-format
-RUN ln -sf /usr/bin/clang-format-20 /usr/local/bin/clang-format
-
-# Copy the lychee binary from the git build stage
-COPY --from=build /app/lychee /usr/bin

+ 21 - 6
.devcontainer/oss/devcontainer.json

@@ -1,10 +1,8 @@
 {
 {
-    "build": {
-        "dockerfile": "../Dockerfile"
-    },
+    "image": "ghcr.io/imgproxy/imgproxy-base:v4-dev",
     "name": "imgproxy OSS",
     "name": "imgproxy OSS",
     "forwardPorts": [
     "forwardPorts": [
-        8080
+        8081
     ],
     ],
     "containerEnv": {
     "containerEnv": {
         "IMGPROXY_LOCAL_FILESYSTEM_ROOT": "/images",
         "IMGPROXY_LOCAL_FILESYSTEM_ROOT": "/images",
@@ -19,14 +17,31 @@
             "source": "${localWorkspaceFolder}/testdata/test-images",
             "source": "${localWorkspaceFolder}/testdata/test-images",
             "target": "/images",
             "target": "/images",
             "type": "bind"
             "type": "bind"
+        },
+        {
+            "source": "${localWorkspaceFolder}/.tmp/_dev-root/.cache",
+            "target": "/root/.cache",
+            "type": "bind"
+        },
+        {
+            "source": "${localWorkspaceFolder}/.tmp/_dev-root/go/pkg/mod",
+            "target": "/root/go/pkg/mod",
+            "type": "bind"
+        },
+        {
+            "source": "${localWorkspaceFolder}/.tmp/_dev-root/.bash_history",
+            "target": "/root/.bash_history",
+            "type": "bind"
         }
         }
     ],
     ],
     "customizations": {
     "customizations": {
         "vscode": {
         "vscode": {
             "extensions": [
             "extensions": [
-                "golang.go"
+                "golang.go",
+                "ms-vscode.cpptools"
             ]
             ]
         }
         }
     },
     },
-    "postCreateCommand": "lefthook install"
+    "postCreateCommand": "lefthook install",
+    "initializeCommand": "mkdir -p ${localWorkspaceFolder}/.tmp/_dev-root/.cache ${localWorkspaceFolder}/.tmp/_dev-root/go/pkg/mod && touch ${localWorkspaceFolder}/.tmp/_dev-root/.bash_history",
 }
 }

+ 0 - 8
.lefthook/pre-commit/lint

@@ -1,8 +0,0 @@
-#!/bin/sh
-
-if ! git diff --staged --name-only | grep -qE ".*\.go$|\.golangci\.yml$"; then
-  echo "Nothing to lint"
-  exit 0;
-fi
-
-make lint

+ 0 - 3
.lefthook/pre-push/test

@@ -1,3 +0,0 @@
-#!/bin/sh
-
-make test

+ 52 - 4
Makefile

@@ -2,16 +2,20 @@
 
 
 BINARY := ./imgproxy
 BINARY := ./imgproxy
 
 
+MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
 GOCMD := go
 GOCMD := go
 GOBUILD := $(GOCMD) build
 GOBUILD := $(GOCMD) build
 GOCLEAN := $(GOCMD) clean
 GOCLEAN := $(GOCMD) clean
 GOTEST := $(GOCMD) test
 GOTEST := $(GOCMD) test
 GOFMT := gofmt
 GOFMT := gofmt
 GOLINT := golangci-lint
 GOLINT := golangci-lint
+CLANG_FORMAT := clang-format
 GOTESTSUM := gotestsum
 GOTESTSUM := gotestsum
 SRCDIR := ./cli
 SRCDIR := ./cli
 RCFILE := ./.imgproxyrc
 RCFILE := ./.imgproxyrc
 BREW_PREFIX :=
 BREW_PREFIX :=
+DEVROOT_TMP_DIR ?= $(MAKEFILE_DIR).tmp/_dev-root
+BASE_IMAGE ?= ghcr.io/imgproxy/imgproxy-base:v4-dev
 
 
 # Common environment setup for CGO builds
 # Common environment setup for CGO builds
 ifneq ($(shell which brew),)
 ifneq ($(shell which brew),)
@@ -43,6 +47,23 @@ ifeq (build-and-run,$(firstword $(MAKECMDGOALS)))
 	RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
 	RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
 endif
 endif
 
 
+# Wrapper action to run commands in Docker
+.PHONY: _run-in-docker
+_run-in-docker:
+ifdef IMGPROXY_IN_BASE_CONTAINER
+	@$(MAKE) $(DOCKERCMD)
+else
+	@mkdir -p ${DEVROOT_TMP_DIR}/.cache ${DEVROOT_TMP_DIR}/go/pkg/mod
+	@docker run --init --rm -it \
+		-v "$(MAKEFILE_DIR):/workspaces/imgproxy" \
+		-v "${DEVROOT_TMP_DIR}/.cache:/root/.cache" \
+		-v "${DEVROOT_TMP_DIR}/go/pkg/mod:/root/go/pkg/mod" \
+		-w /workspaces/imgproxy \
+		-e IMGPROXY_IN_BASE_CONTAINER=1 \
+		$(BASE_IMAGE) \
+		bash -c "make $(DOCKERCMD)"
+endif
+
 # Default target
 # Default target
 .PHONY: all
 .PHONY: all
 all: build
 all: build
@@ -84,8 +105,10 @@ build-and-run: build run
 #
 #
 # Usage:
 # Usage:
 #	make test -- -run FooTest
 #	make test -- -run FooTest
-.PHONY: test
-test:
+.PHONY: test _test
+test: DOCKERCMD := _test
+test: _run-in-docker
+_test:
 ifneq ($(shell which $(GOTESTSUM)),)
 ifneq ($(shell which $(GOTESTSUM)),)
 	@$(GOTESTSUM) ./...
 	@$(GOTESTSUM) ./...
 else
 else
@@ -98,10 +121,23 @@ fmt:
 	@$(GOFMT) -s -w .
 	@$(GOFMT) -s -w .
 
 
 # Lint code (requires golangci-lint installed)
 # Lint code (requires golangci-lint installed)
-.PHONY: lint
-lint:
+.PHONY: lint-go _lint-go
+lint-go: DOCKERCMD := _lint-go
+lint-go: _run-in-docker
+_lint-go:
 	@$(GOLINT) run
 	@$(GOLINT) run
 
 
+# Lint C code (requires clang-format installed)
+.PHONE: lint-clang _lint-clang
+ling-clang: DOCKERCMD := _lint-clang
+ling-clang: _run-in-docker
+_lint-clang:
+	 @find . -not -path "./.tmp/*" -not -path "./.git/*" \( -iname "*.h" -o -iname "*.c" -o -iname "*.cpp" \) | xargs $(CLANG_FORMAT) --dry-run --Werror
+
+# Run all linters
+.PHONY: lint
+lint: lint-go ling-clang
+
 # Upgrade direct Go dependencies
 # Upgrade direct Go dependencies
 .PHONY: upgrade
 .PHONY: upgrade
 upgrade:
 upgrade:
@@ -109,6 +145,18 @@ upgrade:
 	@$(GOCMD) get $$($(GOCMD) list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all)
 	@$(GOCMD) get $$($(GOCMD) list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all)
 	@$(GOCMD) mod tidy
 	@$(GOCMD) mod tidy
 
 
+# Run lychee
+.PHONY: lychee _lychee
+lychee: DOCKERCMD := _lychee
+lychee: _run-in-docker
+_lychee:
+	lychee docs README.md CHANGELOG.md --exclude localhost --exclude twitter.com --exclude x.com --exclude-path docs/index.html
+
+.PHONY: devcontainer
+devcontainer:
+	devcontainer exec --workspace-folder $(MAKEFILE_DIR) --config .devcontainer/oss/devcontainer.json bash
+
+
 # Make any unknown target do nothing to avoid "up to date" messages
 # Make any unknown target do nothing to avoid "up to date" messages
 .PHONY: FORCE
 .PHONY: FORCE
 %: FORCE
 %: FORCE

+ 1 - 1
docker/Dockerfile

@@ -1,4 +1,4 @@
-ARG BASE_IMAGE_VERSION="v3.14.0"
+ARG BASE_IMAGE_VERSION="v4-dev"
 
 
 FROM ghcr.io/imgproxy/imgproxy-base:${BASE_IMAGE_VERSION} AS build
 FROM ghcr.io/imgproxy/imgproxy-base:${BASE_IMAGE_VERSION} AS build
 
 

+ 9 - 9
lefthook.yml

@@ -1,17 +1,17 @@
 pre-commit:
 pre-commit:
-  scripts:
-    lint:
-      tags: lint
   commands:
   commands:
+    lint-go:
+      tags: lint
+      run: make lint-go
     lint-clang:
     lint-clang:
       tags: lint
       tags: lint
-      run: command -v clang-format && find . -not -path "./.tmp/*" -not -path "./.git/*" \( -iname "*.h" -o -iname "*.c" -o -iname "*.cpp" \) | xargs clang-format --dry-run --Werror
+      run: make lint-clang
 
 
 pre-push:
 pre-push:
-  scripts:
+  commands:
     test:
     test:
       tags: test
       tags: test
-  commands:
-    check-links:
-      tags: docs
-      run: command -v lychee && lychee docs README.md CHANGELOG.md --exclude localhost --exclude twitter.com --exclude x.com --exclude-path docs/index.html
+      run: make test
+    lychee:
+      tags: test
+      run: make lychee

+ 2 - 1
vips/bmpload.c

@@ -580,8 +580,9 @@ vips_foreign_load_bmp_rle_generate_strip(VipsRect *r, VipsRegion *out_region, Vi
             bmp->dy = dy;                    // We do not care if Y pos is outside of the impage, it's a separate check
             bmp->dy = dy;                    // We do not care if Y pos is outside of the impage, it's a separate check
 
 
             break; // we need to skip lines, so we exit the loop
             break; // we need to skip lines, so we exit the loop
-          } // Movement by X might not lead to EOL, so we continue
+          }
           else {
           else {
+            // Movement by X might not lead to EOL, so we continue
             bmp->dy = dy;              // 0
             bmp->dy = dy;              // 0
             x = MIN(x + dx, r->width); // Move to the desired pixel
             x = MIN(x + dx, r->width); // Move to the desired pixel
           }
           }