Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
5f598ef
Update .gitignore
beetlebugorg Nov 9, 2024
55974b0
Update devcontainer dependencies
beetlebugorg Nov 9, 2024
d9e85f3
Replace use of ParseSizeGeometry
beetlebugorg Nov 9, 2024
eb4876b
Update devcontainer.json
beetlebugorg Nov 9, 2024
69ab918
Reorganize code
beetlebugorg Nov 9, 2024
90ba127
Remove dims_sizer endpoint
beetlebugorg Nov 10, 2024
31c35c0
Update version to 4.0.0alpha
beetlebugorg Nov 10, 2024
cadb2d8
Move curl init/cleanup to curl.c|h
beetlebugorg Nov 10, 2024
0a12237
Remove support for local filesystem
beetlebugorg Nov 10, 2024
f31555d
Remove legacy dims support
beetlebugorg Nov 10, 2024
f85945d
Partial refactor of handler logic
beetlebugorg Nov 10, 2024
7237a2c
Set PKG_CONFIG_PATH in devcontainer
beetlebugorg Nov 10, 2024
18b113c
Add cpptools extension to devcontainer
beetlebugorg Nov 10, 2024
a819f26
Set includePath for VS Code
beetlebugorg Nov 10, 2024
0256a7f
Set DIMS_SECRET to non-empty value
beetlebugorg Nov 10, 2024
bc32760
Set IntelliSense compiler
beetlebugorg Nov 10, 2024
4054541
Separate out dims3/dims4 request logic
beetlebugorg Nov 10, 2024
130ab82
Use Zig for build system rather than autoconf
beetlebugorg Nov 11, 2024
1b1f006
Experimental zig build
beetlebugorg Nov 11, 2024
f0d41b7
Remove examples/ directory
beetlebugorg Nov 11, 2024
76cfd9f
Rename license file
beetlebugorg Nov 12, 2024
90157c4
Fix build on macOS
beetlebugorg Nov 12, 2024
f95569e
Move Dockerfiles to the project root
beetlebugorg Nov 12, 2024
69ffb76
Convert main Dockerfile to Alpine
beetlebugorg Nov 12, 2024
c9462eb
Use Alpine packages
beetlebugorg Nov 13, 2024
77487fe
Add env file for local development
beetlebugorg Nov 13, 2024
8ddf3dc
Fix case when _keys is empty
beetlebugorg Nov 13, 2024
ba79ce0
Error handling clean, first pass
beetlebugorg Nov 13, 2024
74263f2
Update Dockerfile
beetlebugorg Nov 13, 2024
b72a0d0
Error handling clean, second pass
beetlebugorg Nov 13, 2024
2d8d884
Add build/debug configuration for vscode
beetlebugorg Nov 13, 2024
8a99a61
Build using c17 standard
beetlebugorg Nov 13, 2024
c75209b
Clean up curl functions
beetlebugorg Nov 13, 2024
b359ecd
Clean up dims_request_rec
beetlebugorg Nov 13, 2024
b06b0f7
Move init methods to initialize.c|h
beetlebugorg Nov 13, 2024
6cb82e2
Improve vscode devcontainer setup
beetlebugorg Nov 14, 2024
cb8b74f
Improve dims_request_parse logic
beetlebugorg Nov 14, 2024
c0d707b
Remove stats logic
beetlebugorg Nov 14, 2024
78562ee
Fix global strip operation
beetlebugorg Nov 14, 2024
6393b96
Preparse commands
beetlebugorg Nov 14, 2024
82748dd
Simplify handler.c
beetlebugorg Nov 14, 2024
b34b6ce
Name structs
beetlebugorg Nov 14, 2024
be91ef4
Remove config methods for encoded fetch
beetlebugorg Nov 14, 2024
57f6dae
Improve dims_send_image
beetlebugorg Nov 15, 2024
cff1694
Remove uptime from status
beetlebugorg Nov 15, 2024
469b94a
Improve dims_process_image
beetlebugorg Nov 15, 2024
a7a4601
Fix segfault when no query params are set
beetlebugorg Nov 15, 2024
468110f
Free image/format after sending
beetlebugorg Nov 15, 2024
492876e
Update dims.conf to show notes usage
beetlebugorg Nov 15, 2024
12daef4
Fix bug in downstream_ttl
beetlebugorg Nov 15, 2024
f171e32
Fix memory leak in dims_process_image
beetlebugorg Nov 15, 2024
8b338cb
Remove optimizedResize feature
beetlebugorg Nov 15, 2024
1de833b
Clean up logging
beetlebugorg Nov 15, 2024
07a4948
Replace imagemagick directives with envvars
beetlebugorg Nov 15, 2024
38933d3
Replace "no_image" with error background color
beetlebugorg Nov 15, 2024
abcd625
Simplify error codes
beetlebugorg Nov 15, 2024
d79147b
Use curl_easy_header
beetlebugorg Nov 16, 2024
99996b0
Remove unused url_encode method
beetlebugorg Nov 16, 2024
1d2c101
Fix memory leaks in dims_send_error
beetlebugorg Nov 16, 2024
21119f5
Remove zig ext from devcontainer
beetlebugorg Nov 16, 2024
cdb90d2
Fix env var name
beetlebugorg Nov 30, 2024
67ea5e2
Refactor dims_write_image_cb
beetlebugorg Nov 30, 2024
f816f21
Improve header parsing
beetlebugorg Nov 30, 2024
7721c0d
Refactor dims_process_image
beetlebugorg Nov 30, 2024
7ec1fa4
Set d->wand to NULL after freeing
beetlebugorg Nov 30, 2024
a8306f9
Use local vars
beetlebugorg Nov 30, 2024
2e0ea79
Use asserts to validate arguments
beetlebugorg Nov 30, 2024
3869cdf
Explicitly check for NULL when fetching profiles
beetlebugorg Nov 30, 2024
2ae2454
Verify memory allocations succeed
beetlebugorg Nov 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 27 additions & 57 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,74 +1,44 @@
ARG HTTPD_VERSION=2.4.49
ARG HTTPD_VERSION=2.4.62

FROM httpd:${HTTPD_VERSION} as build-mod-dims

ARG DIMS_VERSION=3.3.26
ARG IMAGEMAGICK_VERSION=6.9.12-34
ARG WEBP_VERSION=1.2.1
ARG TIFF_VERSION=4.3.0
ARG PREFIX=/usr/local/imagemagick
FROM httpd:${HTTPD_VERSION}-alpine

ENV DIMS_DOWNLOAD_TIMEOUT=60000
ENV DIMS_IMAGEMAGICK_TIMEOUT=20000
ENV DIMS_CLIENT=development
ENV DIMS_NO_IMAGE_URL="http://placehold.it/350x150"
ENV DIMS_DEFAULT_IMAGE_URL="http://placehold.it/350x150"
ENV DIMS_CACHE_CONTROL_MAX_AGE=604800
ENV DIMS_EDGE_CONTROL_DOWNSTREAM_TTL=604800
ENV DIMS_TRUST_SOURCE=true
ENV DIMS_SOURCE_CACHE=604800
ENV DIMS_MIN_SOURCE_CACHE=0
ENV DIMS_MAX_SOURCE_CACHE=604800
ENV DIMS_SECRET=""
ENV DIMS_CACHE_EXPIRE=604800
ENV DIMS_NO_IMAGE_CACHE_EXPIRE=60
ENV DIMS_WHITELIST="*.com *.org *.net *.io"
ENV DIMS_ERROR_IMAGE_CACHE_EXPIRE=60
ENV DIMS_ERROR_IMAGE_BACKGROUND="#5ADAFD"
ENV PREFIX=/usr/local/apache2
ENV PATH=${PREFIX}/bin:${PATH}

RUN apt-get -y update && \
apt-get install -y --no-install-recommends \
automake libtool autoconf build-essential \
git ca-certificates \
libapr1-dev libaprutil1-dev \
curl \
libcurl4-openssl-dev libfreetype6-dev libopenexr-dev libxml2-dev \
libgif-dev libjpeg62-turbo-dev libpng-dev \
liblcms2-dev pkg-config libssl-dev libpangocairo-1.0-0 wget
# Imagemagick configuration

# WEBP Library
RUN wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-${WEBP_VERSION}.tar.gz && \
tar xzvf libwebp-${WEBP_VERSION}.tar.gz && \
cd libwebp-${WEBP_VERSION} && \
./configure --prefix=/usr/local/imagemagick && \
make -j4 && make install
# 2GB disk limit
ENV MAGICK_DISK_LIMIT=2147483648

# TIFF Library
RUN wget http://download.osgeo.org/libtiff/tiff-${TIFF_VERSION}.tar.gz && \
tar xzvf tiff-${TIFF_VERSION}.tar.gz && \
cd tiff-${TIFF_VERSION} && \
./configure --prefix=$PREFIX --with-webp-include-dir=$PREFIX/include --with-webp-lib-dir=$PREFIX/lib && \
make -j4 && make install
# 512MB memory limit
ENV MAGICK_MEMORY_LIMIT=536870912

# Imagemagick
RUN wget https://download.imagemagick.org/ImageMagick/download/releases/ImageMagick-${IMAGEMAGICK_VERSION}.tar.xz && \
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig && \
tar xvf ImageMagick-${IMAGEMAGICK_VERSION}.tar.xz && \
cd ImageMagick-${IMAGEMAGICK_VERSION} && \
./configure --without-x --with-quantum-depth=8 --prefix=$PREFIX && \
make -j4 && make install
# 512MB map limit
ENV MAGICK_MAP_LIMIT=536870912

RUN apt-get --no-install-recommends install -y apt-transport-https apt-utils \
automake build-essential ccache cmake ca-certificates curl git \
gcc g++ libc-ares-dev libc-ares2 libcurl4-openssl-dev libre2-dev \
libssl-dev m4 make pkg-config tar wget zlib1g-dev
# 128MB area limit
ENV MAGICK_AREA_LIMIT=134217728

WORKDIR /build
RUN apk update && \
apk add vim gdb zig apr-dev apr-util-dev imagemagick-dev curl-dev \
imagemagick-jpeg imagemagick-webp imagemagick-tiff && \
zig build --verbose || true; \
ln -sf /workspaces/mod_dims/zig-out/lib/libmod_dims.so.4.0.0 ${PREFIX}/modules/libmod_dims.so

RUN apt-get install -y vim && \
chown -R www-data:www-data /usr/local/apache2 && \
sed "s|Listen 80|Listen 8000|" /usr/local/apache2/conf/httpd.conf -i && \
sed "s|^#LoadModule authz_core_module|LoadModule authz_core_module|" /usr/local/apache2/conf/httpd.conf -i && \
sed "s|^LogLevel warn|LogLevel debug|" /usr/local/apache2/conf/httpd.conf -i && \
echo "Include conf/extra/dims.conf" >> /usr/local/apache2/conf/httpd.conf
COPY dims.conf /usr/local/apache2/conf/httpd.conf

COPY docker/dims.conf /usr/local/apache2/conf/extra/dims.conf

ENV LC_ALL="C"
ENV DIMS_CLIENT=development
ENV DIMS_SECRET=devmode
ENV DIMS_WHITELIST="*.com *.net *.org *.io"
ENV DIMS_NO_IMAGE_URL="http://192.168.65.1:8081/mod-dims_00001_.jpg"
ENV DIMS_DEFAULT_IMAGE_URL="http://192.168.65.1:8081/mod-dims_00001_.jpg"
31 changes: 24 additions & 7 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,31 @@
"containerUser": "root",
"remoteUser": "root",

// Set *default* container specific settings.json values on container create.
"settings": {},


// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.cpptools"
],
"customizations": {
"vscode": {
"settings": {
"C_Cpp.default.compilerPath": "/usr/bin/zig",
"C_Cpp.default.includePath": [
"${default}",
"/usr/local/apache2/include",
"/usr/lib/zig/libc/include",
"/usr/lib/zig/libcxx/include",
"/usr/lib/zig/libc/include/generic-musl",
"/usr/include",
"/usr/include/apr-1/",
"/usr/include/ImageMagick-7/",
"/usr/lib/zig/libc/include/aarch64-linux-musl"
]
},
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"vscodevim.vim",
"GitHub.copilot"
]
},
},

// https://stackoverflow.com/questions/35860527/warning-error-disabling-address-space-randomization-operation-not-permitted
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
Expand Down
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.zig-cache
zig-out
zig-cache
15 changes: 15 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export DIMS_DOWNLOAD_TIMEOUT=60000
export DIMS_IMAGEMAGICK_TIMEOUT=20000
export DIMS_CLIENT=development
export DIMS_NO_IMAGE_URL="http://placehold.it/350x150"
export DIMS_DEFAULT_IMAGE_URL="http://placehold.it/350x150"
export DIMS_CACHE_CONTROL_MAX_AGE=604800
export DIMS_EDGE_CONTROL_DOWNSTREAM_TTL=604800
export DIMS_TRUST_SOURCE=true
export DIMS_SOURCE_CACHE=604800
export DIMS_MIN_SOURCE_CACHE=0
export DIMS_MAX_SOURCE_CACHE=604800
export DIMS_SECRET="devmode"
export DIMS_CACHE_EXPIRE=604800
export DIMS_NO_IMAGE_CACHE_EXPIRE=60
export DIMS_WHITELIST="*.com *.net *.org *.io 127.0.0.1 localhost"
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
.DS_Store
m4/
Makefile
Makefile.in
Expand All @@ -20,3 +22,20 @@ install-sh
missing
INSTALL
stamp-h1

*.lo
*.la
*.lai
*.o
*.Plo
*.Tpo
*.a
*~

*.dylib
*.so

.zig-out
.zig-cache
zig-out
zig-cache
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "mod-dims - debug",
"type": "cppdbg",
"request": "launch",
"program": "/usr/local/apache2/bin/httpd",
"args": ["-X"],
"stopAtEntry": false,
"cwd": ".",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "zig build"
},
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"*.templ": "templ",
"strings.h": "c"
}
}
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "zig build",
"type": "shell",
"command": "zig build --verbose",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Empty file removed AUTHORS
Empty file.
13 changes: 0 additions & 13 deletions ChangeLog

This file was deleted.

52 changes: 52 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
ARG HTTPD_VERSION=2.4.62

FROM httpd:${HTTPD_VERSION}-alpine AS builder

ENV PREFIX=/usr/local/apache2
ENV PATH=${PREFIX}/bin:${PATH}

COPY . /build/mod-dims
WORKDIR /build/mod-dims

RUN apk update && \
apk add vim gdb zig apr-dev apr-util-dev imagemagick-dev curl-dev \
imagemagick-jpeg imagemagick-webp imagemagick-tiff && \
zig build || true; \
ln -sf /build/mod-dims/zig-out/lib/libmod_dims.so.4.0.0 ${PREFIX}/modules/libmod_dims.so || true

FROM httpd:${HTTPD_VERSION}-alpine AS final

ENV DIMS_DOWNLOAD_TIMEOUT=60000
ENV DIMS_IMAGEMAGICK_TIMEOUT=20000
ENV DIMS_CACHE_CONTROL_MAX_AGE=604800
ENV DIMS_EDGE_CONTROL_DOWNSTREAM_TTL=604800
ENV DIMS_TRUST_SOURCE=true
ENV DIMS_MIN_SOURCE_CACHE=0
ENV DIMS_MAX_SOURCE_CACHE=604800
ENV DIMS_CACHE_EXPIRE=604800
ENV DIMS_ERROR_IMAGE_CACHE_EXPIRE=60
ENV DIMS_ERROR_IMAGE_BACKGROUND="#5ADAFD"
ENV PREFIX=/usr/local/apache2
ENV PATH=${PREFIX}/bin:${PATH}

# Imagemagick configuration

# 2GB disk limit
ENV MAGICK_DISK_LIMIT=2147483648

# 512MB memory limit
ENV MAGICK_MEMORY_LIMIT=536870912

# 512MB map limit
ENV MAGICK_MAP_LIMIT=536870912

# 128MB area limit
ENV MAGICK_AREA_LIMIT=134217728

RUN apk update && \
apk add imagemagick imagemagick-jpeg imagemagick-webp imagemagick-tiff curl

COPY --from=builder /build/mod-dims/zig-out/lib/libmod_dims.so.4.0.0 ${PREFIX}/modules/libmod_dims.so
COPY dims.conf /usr/local/apache2/conf/httpd.conf

EXPOSE 8000
1 change: 1 addition & 0 deletions COPYING → LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright 2009 AOL LLC
Copyright 2024 Jeremy Collins

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
Expand Down
2 changes: 0 additions & 2 deletions Makefile.am

This file was deleted.

Empty file removed NEWS
Empty file.
Empty file removed README
Empty file.
42 changes: 26 additions & 16 deletions README.markdown → README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
Dependencies
============

* Apache 2.2.x
* Imagemagick 6.6+
* libcurl 7.18.0+
mod-dims
========

Compiling
=========
mod-dims is an HTTP microservice for dynamic image manipulation. It run as an Apache httpd module.

./autorun.sh --with-imagemagick=/path/to/imagemagick --with-apache=/path/to/apache
Dependencies
------------

The paths provided above are prefix paths used to install those dependencies. If you installed
Imagemagick and Apache (including APR) in /usr/local you would run:
* Apache 2.4.x
* Imagemagick 7.1.x
* libcurl 7.x

./autorun.sh --with-imagemagick=/usr/local --with-apache=/usr/local
Compiling
---------

```bash
$ zig build
find zig-out/
zig-out/
zig-out/lib
zig-out/lib/libmod_dims.so.4
zig-out/lib/libmod_dims.so.4.0.0
zig-out/lib/libmod_dims.so
```

Installation
============
------------

Add the following to the Apache configuration:

```
<IfModule !mod_dims.c>
LoadModule dims_module modules/mod_dims.so
</IfModule>

AddHandler dims-local .gif .jpg

<Location /dims/>
SetHandler dims
<Location /dims3/>
SetHandler dims3
</Location>

<Location /dims3/>
<Location /dims4/>
SetHandler dims3
</Location>

<Location /dims-status/>
SetHandler dims-status
</Location>
```

This assumes mod_dims.so has been installed in $HTTP_ROOT/modules.

Expand Down
Loading