MarceauKa / shaark

Self-hosted platform to keep and share your content: web links, posts, passwords and pictures.
579 stars 59 forks source link

Feedback welcome on custom Docker image #70

Closed frenchvandal closed 4 years ago

frenchvandal commented 4 years ago

I decided to create this spin-off not to pollute #69

Despite all the tips provided on the former issue, I have not managed to install Shaark with MariaDB so for now I stick to SQLite.

Here is my Dockerfile:

FROM alpine/git as builder
WORKDIR /tmp
RUN set -x \
    && git clone https://github.com/MarceauKa/shaark.git shaark

FROM php:7-alpine
WORKDIR /app
COPY --from=builder /tmp/shaark /app
RUN set -x && \
        touch database/shaark.sqlite && \
        mv .env.example .env && \
        \
        sed -i s/APP_ENV=local/APP_ENV=production/ .env && \
        sed -i s/APP_DEBUG=true/APP_DEBUG=false/ .env && \
        sed -i 's|APP_URL=http:\/\/dev.shaark|APP_URL=https:\/\/normco.re|' .env && \
        sed -i s/DB_CONNECTION=mysql/DB_CONNECTION=sqlite/ .env && \
        sed -i 's|DB_DATABASE=homestead|DB_DATABASE=\/app\/database\/shaark\.sqlite|' .env && \
        #test with Redis
        sed -i s/REDIS_HOST=127.0.0.1/REDIS_HOST=redis/ .env && \
        sed -i s/CACHE_DRIVER=file/CACHE_DRIVER=redis/ .env && \
        sed -i s/QUEUE_CONNECTION=sync/QUEUE_CONNECTION=redis/ .env && \
        sed -i s/SESSION_DRIVER=file/SESSION_DRIVER=redis/ .env && \
        sed -i s/REDIS_HOST=127.0.0.1/REDIS_HOST=redis/ .env && \
        #test with Redis
        \
        apk -U upgrade && \
        apk add --no-cache --update openssl \
        zip \
        unzip \
        oniguruma-dev \
        zlib-dev libpng-dev \
        libzip-dev \
        postgresql-dev \
        gmp \
        gmp-dev \
        nodejs \
        npm && \
        echo "**** install Python ****" && \
        apk add --no-cache python3 && \
        if [ ! -e /usr/bin/python ]; then ln -sf python3 /usr/bin/python ; fi && \
        \
        curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/bin/youtube-dl && \
        chmod a+rx /usr/bin/youtube-dl && \
        curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
        docker-php-ext-install pdo mbstring gd exif zip sockets pdo_mysql pgsql pdo_pgsql gmp bcmath && \
        apk --no-cache add pcre-dev ${PHPIZE_DEPS} && \
        pecl install -o -f redis && \
        docker-php-ext-enable redis && \
        apk del pcre-dev ${PHPIZE_DEPS} && \
        rm -rf /tmp/* && \
        \
        composer install --no-dev -o && \
        npm install -g @nesk/puphpeteer --no-save --unsafe-perm=true --allow-root && \
        php artisan optimize && \
        php artisan view:clear && \
        \
        php artisan key:generate && \
        php artisan storage:link && \
        php artisan config:cache && \
        php artisan migrate --seed -n --force

VOLUME /app

CMD php artisan serve --host=0.0.0.0 --port=80
EXPOSE 80

My docker-compose.yml file:

version: "3.7"

volumes:
  app:
  data:

services:
  shaark:
    #image: frenchvandal/shaark:attack
    image: shaark:attack
    build: .
    container_name: shaark
    restart: always
    depends_on:
      - redis
    volumes:
      - app:/app:rw
      - data:/data:rw

  redis:
    image: redis:alpine3.11
    container_name: redis
    restart: unless-stopped
    volumes:
      - data:/data:rw

networks:
  default:
    external:
      name: firefly

(firefly is the default network of all my containers)

A few comments about things I added but not sure really sure if they are actually needed:

The image builds successfully and Shaark is up when I hit the URL.

Globally it is functional, except a few things:

Any feedback on my Dockerfile is welcome, and obviously any part of it can be reused for the repo.

MarceauKa commented 4 years ago

@frenchvandal Thank you for your PR! I'm just a simple user with Docker so I can't help you with that. Maybe you should have a look at Laradock, it's a docker config for Laravel. It can help you to create your docker config.

FYI, I use these env to run Shaark. Env HTTP PHP DB Redis ext Jobs driver
dev Apache PHP 7.2 MySQL 5.7 (pdo_mysql) phpredis in database
prod Apache + nginx proxy PHP 7.1 MariaDB 10.2 predis in redis
frenchvandal commented 4 years ago

Thank you 😄 I will check this info.

I made some quick tests with my new install. Everything seems functional, except:

I love Shaarli but I do not think I can go back to it now that I have found out about Shaark!

@MarceauKa do you happen to have a SVG version of the Shaark icon?

MarceauKa commented 4 years ago

Can you give me the 500 error you get? (see it in storage/logs/laravel.log). Nope, I don't have the logo in svg format :(

frenchvandal commented 4 years ago

Here it is: laravel-2020-03-29.log

I have noticed another thing: when I add an album with a simple image, after I hit Send, I get a server error message. Though if I leave and go back to the front page, the album is published (so each time I hit Send, the message shows up and the image is published)

Here are the logs.

On a side note, I did not find the pattern yet but the upload of images sometimes fail: logs image

frenchvandal commented 4 years ago

@MarceauKa is it possible to share with me an example of Apache prod conf? I am trying to reverse proxy with Caddy (similar to nginx) but something is wrong with Apache, when I hit the URL I got:

Forbidden You don't have permission to access this resource.

Apache/2.4.38 (Debian) Server at normco.re Port 80

I am not familiar with Apache. I put all the content of the /shaark folder in /var/www/html

Thank you a lot!

MarceauKa commented 4 years ago

@frenchvandal Just put the document root to /public

frenchvandal commented 4 years ago

Thank you @MarceauKa eventually I managed directly with my web server and without Apache.

I have some issues for displaying images posted with albums. I can see they are stored correctly in their storage path, but they get a 404 error when displayed in a browser.

Is there any specific directive to deal with images in nginx or Apache?

MarceauKa commented 4 years ago

Call php artisan storage:link as mentionned in the doc. All uploaded files are stored outsite document root. This command will create a symlink in the public path to the storage folder.

frenchvandal commented 4 years ago

Thanks man, I actually did the command during install. I am so dumb, the symlink was broken because I change afterwards the root path of Shaark inside the container.

I managed to get a working dockerized Shaark with MariaDB (but includes manual steps from the user). I still have 2 issues to solve before pushing anything: getting mail sent and a functional Redis archiving.

tborychowski commented 4 years ago

Hi @frenchvandal, did you get around to fixing this? would you have a copy of your changes anywhere online, or maybe steps to reproduce? I'd really love to make it work 😄