Răsfoiți Sursa

IMG-37: improve OSS .devcontainer (#1460)

* OSS .devcontainer with all the tools

* .air.toml

* BASE_IMAGE arg

* Go with unzip test-images

* Removed unused commit
Victor Sokolov 2 luni în urmă
părinte
comite
01439f43b0

+ 63 - 0
.air.toml

@@ -0,0 +1,63 @@
+root = "."
+testdata_dir = "testdata"
+tmp_dir = "tmp"
+
+[build]
+  args_bin = []
+  bin = "./tmp/main"
+  cmd = "go build -o ./tmp/main ."
+  delay = 1000
+  exclude_dir = ["assets", "tmp", "vendor", "testdata"]
+  exclude_file = []
+  exclude_regex = ["_test.go"]
+  exclude_unchanged = false
+  follow_symlink = false
+  full_bin = ""
+  include_dir = []
+  include_ext = ["go", "tpl", "tmpl", "html"]
+  include_file = [
+    "vips/vips.c",
+    "vips/vips.h",
+    "vips/source.c",
+    "vips/source.h",
+    "vips/icoload.c",
+    "vips/icosave.c",
+    "vips/ico.h",
+    "vips/bmpload.c",
+    "vips/bmpload.h",
+    "vips/bmp.h"
+  ]
+  kill_delay = "4s"
+  log = "build-errors.log"
+  poll = false
+  poll_interval = 0
+  post_cmd = []
+  pre_cmd = []
+  rerun = false
+  rerun_delay = 500
+  send_interrupt = true
+  stop_on_error = true
+
+[color]
+  app = ""
+  build = "yellow"
+  main = "magenta"
+  runner = "green"
+  watcher = "cyan"
+
+[log]
+  main_only = false
+  silent = false
+  time = false
+
+[misc]
+  clean_on_exit = false
+
+[proxy]
+  app_port = 0
+  enabled = false
+  proxy_port = 0
+
+[screen]
+  clear_on_rebuild = false
+  keep_scroll = true

+ 62 - 0
.devcontainer/Dockerfile

@@ -0,0 +1,62 @@
+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 unzip
+
+# Install air
+RUN go install github.com/air-verse/air@latest
+
+# Install lefthook
+RUN go install github.com/evilmartians/lefthook@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

+ 0 - 0
.devcontainer/images/.gitkeep


+ 28 - 0
.devcontainer/oss/README.md

@@ -0,0 +1,28 @@
+# .devcontainer setup for local development of `imgproxy`
+
+All `imgproxy` dependencies are included in the `imgproxy-base` container image. Using this image for development is recommended.
+
+If you want to develop locally without using Docker, please install: `vips`, `clang-format`,`lychee` and `lefthook`.
+
+On MacOS:
+
+```sh
+brew install vips clang-format lychee lefthook
+```
+
+Then, run:
+```sh
+lefthook install
+```
+
+# Start the devcontainer
+
+You can use [`air`](https://github.com/air-verse/air) for hot-reloading during development. Simply run: `air`.
+
+Port `8080` is forwared to the host.
+
+# Test images
+
+[test images repo](https://github.com/imgproxy/test-images.git) will be automatically cloned or pulled to `.devcontainer/images` folder before the container starts.
+
+[Try it](http://localhost:8080/insecure/rs:fit:300:200/plain/local:///kitten.jpg@png). -->

+ 33 - 0
.devcontainer/oss/devcontainer.json

@@ -0,0 +1,33 @@
+{
+    "build": {
+        "dockerfile": "../Dockerfile"
+    },
+    "name": "imgproxy OSS",
+    "forwardPorts": [
+        8080
+    ],
+    "containerEnv": {
+        "IMGPROXY_LOCAL_FILESYSTEM_ROOT": "/images",
+        "IMGPROXY_ENABLE_VIDEO_THUMBNAILS": "true",
+        "IMGPROXY_MAX_ANIMATION_FRAMES": "999",
+        "IMGPROXY_VIPS_LEAK_CHECK": "true",
+        "IMGPROXY_LOG_MEM_STATS": "true",
+        "IMGPROXY_DEVELOPMENT_ERRORS_MODE": "true"
+    },
+    "mounts": [
+        {
+            "source": "${localWorkspaceFolder}/.devcontainer/images",
+            "target": "/images",
+            "type": "bind"
+        }
+    ],
+    "customizations": {
+        "vscode": {
+            "extensions": [
+                "golang.go"
+            ]
+        }
+    },
+    "initializeCommand": "mkdir -p ${localWorkspaceFolder}/.devcontainer/images/ && curl -O -L https://github.com/imgproxy/test-images/archive/refs/heads/main.zip && unzip main.zip -d ${localWorkspaceFolder}/.devcontainer/images/ && rm main.zip && mv ${localWorkspaceFolder}/.devcontainer/images/test-images-main/* ${localWorkspaceFolder}/.devcontainer/images/ && rmdir ${localWorkspaceFolder}/.devcontainer/images/test-images-main",
+    "postCreateCommand": "lefthook install"
+}

+ 1 - 1
.gitignore

@@ -8,5 +8,5 @@ tmp/
 docker-base
 docs/sitemap.txt
 .env
-.devcontainer/*
+.devcontainer/images/*
 k6/*.json