PEPIC
Pepic is a small app that helps me to upload, store, convert and serve pictures (or videos) on my dedicated servers.
I use it as media proxy for my pet-projects and on my blog.
Pepic can convert, resize and optimize media files in-flight to save you monies and bandwidth.
Internally it uses ffmpeg for videos and vips for images,
which means it's quite fast and supports JPG, PNG, GIF, WEBP, SVG, HEIF, TIFF and wide range of video formats.
It's not meant to be used by anyone else except me. Use it only if you're brave. Scroll down this README for better alternatives.
π€ How to run it locally
This command starts a local server on localhost:8118. Useful for development.
go run main.go serve --config ./etc/pepic/config.yml
β οΈ If you're getting invalid flag in pkg-config
error, run export CGO_CFLAGS_ALLOW="-Xpreprocessor"
in advance
π³ Running in Docker
-
Get Docker
-
Clone the repo
git clone git@github.com:vas3k/pepic.git
cd pepic
- Build and run the app
docker build .
docker run -p 8118:8118 -v ${PWD}/uploads:/app/uploads $(docker build -q .)
-
Go to http://localhost:8118 and try uploading something.
You should see uploaded images or videos in the data directory (./uploads
) after that.
-
Try to resize an image by adding a number of pixels to its URL. For example: https://localhost:8118/file.jpg -> https://localhost:8118/500/file.jpg
-
Check out the etc/pepic/config.yml file. Some stuff is turned off by default.
You can tweak them for yourself and rebuild the docker again (step 3) to apply them.
π’ Production Usage
β οΈ If you plan to host anything bigger than a blog, always put it behind CDN.
CloudFlare offers a free one if you don't hate big corporations :D
Let's say, you want to host it on https://media.mydomain.org
1. Modify etc/pepic/config.yml
to your taste
global:
host: 0.0.0.0
port: 8118 # internal host and port, leave it as it is
base_url: "https://media.mydomain.org"
secret_code: "secretpass"
max_upload_size: "500M"
2. Build and run production docker
Don't forget to mount upload volume to store files on host (or you can lose those files when container will be killed).
docker run -p 8118:8118 -v /host/dir/uploads:/app/uploads --restart=always $(docker build -q .)
If you prefer docker-compose, you can use it too. Check out the included docker-compose.example.yml.
You can easily transform it into your favourite k8s config or whatever is fashionable this summer.
π Don't forger to periodically backup the /host/dir/uploads
directory just in case :)
3. Use nginx or your other favourite proxy
Just proxy all calls from the domain (media.mydomain.org) to pepic backend (0.0.0.0:8118). It can handle static files too.
server {
listen 80;
server_name media.mydomain.org;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://0.0.0.0:8118;
}
}
π Contributions
Contributions are welcome.
Open an Issue if you want to report a bug and propose an idea.
β
TODO
- Tests :D
- Upload by URL
- Crop, rotate and other useful transformations (face blur? pre-loader generator?)
- Live conversion by changing file's extension
- Set format and quality during the upload (using GET/POST params?)
π€ Alternatives
After reading all this, you probably realized how bad it is and looking for other alternatives. Here's my recommendations:
π©βπΌ License
It's MIT.
Contact me if you have any questions β me@vas3k.ru.
β€οΈ