Skip to content

pcpl2/EasyImageCdn

Repository files navigation

EasyImageCdn

Build Docker Image Size with architecture (latest by date/latest semver) Docker Image Size with architecture (latest by date/latest semver) Docker Pulls GitHub Docker Image Version (tag latest semver) GitHub go.mod Go version CodeFactor

Application to create a simple cdn server for images.

This application automatically converts the uploaded image to webp format and to all resolutions defined in the configuration.

How to use

docker run --name imagecdn -v /my/images/location:/var/lib/images -e API_KEY=EnterAdminKey -d ghcr.io/pcpl2/easy_image_cdn:0.2.3

OR

docker run --name imagecdn -v /my/images/location:/var/lib/images -e API_KEY=EnterAdminKey -d pcpl2/easy_image_cdn:0.2.3

This command launches the application with image conversion to 1024x720 and 800x600 enabled, with a maximum file size of 10Mb and your API key.

Example docker-compose config

version: '3.9'
  cdn:
    image: pcpl2/easy_image_cdn:0.2.3
    restart: always
    environment:
      API_KEY: 'EnterAdminKey'
      CONVERT_TO_RES: '1024x720,800x600'
      MAX_FILE_SIZE: 15
    ports:
      - '9324:9324'
      - '9555:9555'
    volumes:
      - './images:/var/lib/images'
      - './logs:/var/log/eic'

Endpoints

Admin

http://localhost:9324/v1/newImage -> For send and update Image Payload:

{
    "id": {Your image id as string},
    "image": {Your image in base64}
}

http://localhost:9324/v1/newImageMp?imageId={Your image id} -> For send and update Image as multipart and define image in multipart as imageFile

Public

http://localhost:9555/{Your image id} -> Has returned source image (if you have image/webp in accept header server will return the image in webp format).

To get the image in converted resolution, you add a resolution value after the image id. Example: http://localhost:9555/{Your image id}/1024x720

Configuration

Example .env file

API_KEY=00000000-0000-0000-0000-000000000000
API_KEY_HEADER=key
CONVERT_TO_RES=1024x720,800x600
MAX_FILE_SIZE=10

Config values description

Configuration key Default value Description
API_KEY 00000000-0000-0000-0000-000000000000 Api key for upload images
API_KEY_HEADER key Header name for an API key in the request.
CONVERT_TO_RES 1024x720,800x600 List of resolutions to which images will be converted.
MAX_FILE_SIZE 10 Maximum size of the file sent to the application in megabytes.
CACHE_TIME 30 Image cache lifetime set in minutes.
EXPVAR_ENABLED 0 Enable golang Expvar for monitoring. Data is available on 0.0.0.0:9125/debug/vars
PPROF_ENABLED 0 Enable golang Pprof for monitoring. Data is available on 0.0.0.0:9125/debug/pprof/

Volumes configuration in container

Path Description
/var/lib/images Location for saving all images
/var/log/eic Location for Application log files

Community

Sponsors

TODO()