ソドイキ

Alfred's Thoughts

Image hosting for this site

2 May 2024
,

When the setup of this site was finished, with the help of Ben Yafai. I wanted to somehow visualize how I upload the pictures and host them, the easiest solution was to just dump the images into a folder like /public/image/... or something. I wanted to first strip any metadata of the images I upload and also to compress them, as well as to be able randomize their name during upload, so instead of it saying WhatsApp Image yada.png it would be a random string SDFSDFSSDF.png.

Now I could've done this all by hand if needed per image, it isnt like I am posting too many images? (Hopefully I will do that in the future, maybe setup a gallery page? I really like how Keir Ansell showcases his pictures).

I explored a few options like Cloudflare Images, MySQL Databases (overkill much?). I then found this GitHub repo of awesome open source self-hosted applications. Within their Single-click & Drag-n-drop Upload options they had quite a few.

The main options I tested were; ass, Uploady, and Zipline. All of them were pretty easy to setup using Docker, thanks to the knowledge I have gained in Docker recently from Ben. Zipline took a bit of back-and-forth editing of Dockerfile and docker-compose.yml file to get it working but overall it went pretty smooth. After some testing I decided I will go with Zipline.

zipline logo

Zipline describes itself as "A ShareX/file upload server that is easy to use, packed with features, and with an easy setup!" which for the a lot of it is pretty true! Has a pretty clean UI and overall from my testing it seems pretty straight forward.

The most important thing is it offers the features I needed the most from above. Setting it up with my Cloudflare tunnel and Docker was a little tricky, and development of the project is pretty active. They are currently working on releasing v4 of Zipline which is going to bring new changes and much more!

If you are interested in what I ran into issues with Zipline and how I fixed them, read on below.

Technical Troubleshooting of Zipline

I used the default provided docker-compose.yml file from Zipline developers, however I wanted to modify it so it works with my Cloudflare tunnel so I did not have to expose any of my server ports to the public.

version: '3'
services:
  postgres:
    image: postgres:15
    restart: unless-stopped
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DATABASE=postgres
    volumes:
      - pg_data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U postgres']
      interval: 10s
      timeout: 5s
      retries: 5

  zipline:
    image: ghcr.io/diced/zipline
    ports:
      - '3000:3000'
    restart: unless-stopped
    environment:
      - CORE_RETURN_HTTPS=false
      - CORE_SECRET=changethis
      - CORE_HOST=0.0.0.0
      - CORE_PORT=3000
      - CORE_DATABASE_URL=postgres://postgres:postgres@postgres/postgres
      - CORE_LOGGER=true
    volumes:
      - './uploads:/zipline/uploads'
      - './public:/zipline/public'
    depends_on:
      - 'postgres'

volumes:
  pg_data:

I added the following bits into the docker-compose.yml:

...
  zipline:
    ...
    ports:
      - '3001:3000'
    networks:
      - cloudflare
    ...

...

networks:
  cloudflare:
      external: true

In theory this should have made it work just fine, but alas it would not be that easy. I figured out that adding the networks: cloudflare to the zipline service disconnected it from the postgres service, and they were not able to communicate with each other. I then tried adding default to the networks within zipline and that seems to allowed the connection.

...
  zipline:
    ...
    networks:
      - cloudflare
      - default
    ...

This small change took me almost 5 days to figure out, I reinstall Docker and the project multiple times thinking it was wrong, but ofcourse it was just a simple extra line.

I have been running Zipline since then pretty smoothly, added a bunch modifiers as well from their documentation and all is well. Not sure how the storage will be affected, I keep the images pretty small but might want to add a extra storage volume to the Hetzner server maybe, will see in the future.

WeblogPoMo 2024
This blog post is part of the #WebLogPoMo2024 series, it is a month-long blog posting extravaganza where I will try to post daily for the month of May. Read more about it here and check other people!


Until next time,