Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve docker-compose issues in #69 #83

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
docker-compose.override.yml
31 changes: 0 additions & 31 deletions Dockerfile

This file was deleted.

111 changes: 111 additions & 0 deletions Dockerfile.shaark
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
FROM php:7.4.0-alpine
MAINTAINER Shaark contributors <https://github.com/MarceauKa/shaark>

WORKDIR /app
COPY . /app

# Install packages needed for shaark
RUN apk add --no-cache \
bash \
openssl \
zip \
unzip \
oniguruma-dev \
zlib-dev \
libpng-dev \
libzip-dev \
postgresql-dev \
gmp \
gmp-dev \
python3 \
git \
libcap \
mariadb-client \
nodejs \
npm \
busybox-suid

# Set inheritied capabilities on entrypoint
RUN setcap cap_net_raw+eip /app/app/entrypoint-shaark.sh && \
setcap cap_sys_admin+eip /app/app/entrypoint-shaark.sh && \
setcap cap_net_bind_service=+ep `which php`

# Installs latest Chromium (83) package.
RUN apk add --no-cache \
chromium \
nss \
freetype \
freetype-dev \
harfbuzz \
ca-certificates \
ttf-freefont

# Set environment variables
ENV \
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser \
DB_HOST="mariadb" \
REDIS_HOST="redis" \
APP_ENV="production" \
APP_DEBUG="false" \
APP_MIGRATE_DB="true" \
CACHE_DRIVER="redis" \
QUEUE_CONNECTION="redis" \
SESSION_DRIVER="redis" \
REDIS_HOST="redis"

# Puppeteer v3.1.0 works with Chromium 83.
RUN npm install [email protected]

# Add user so we don't have to run everything as root
RUN addgroup -S shaark && adduser -S -G shaark shaarkuser \
&& mkdir -p /home/shaarkuser/Downloads \
&& chown -R shaarkuser:shaark /home/shaarkuser \
&& chown -R shaarkuser:shaark /app

# Install youtube-dl binary
RUN curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/bin/youtube-dl && \
chmod a+rx /usr/bin/youtube-dl

# Make sure python binary is python3
RUN if [ ! -e /usr/bin/python ]; then ln -sf /usr/bin/python3 /usr/bin/python; fi

# Install composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
mv composer.phar /usr/local/bin/composer

# Install php extensions
RUN docker-php-ext-install \
pdo \
mbstring \
gd \
exif \
zip \
sockets \
pdo_mysql \
pgsql \
pdo_pgsql \
gmp \
bcmath

# Configure Backups cron
RUN crontab -u shaarkuser app/crontab

# Run everything after as non-privileged user.
USER shaarkuser

RUN composer install --no-dev -o

RUN cp .env.example .env && \
\
php artisan optimize && \
php artisan view:clear && \
\
php artisan key:generate && \
php artisan storage:link

EXPOSE 80
ENTRYPOINT [ "app/entrypoint-shaark.sh" ]
6 changes: 3 additions & 3 deletions app/Http/Controllers/Api/Manage/FeaturesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ protected function checkArchivePdf(Shaark $shaark)
return $this->sendError(__('Your node path is unreachable: :path', ['path' => $exec]));
}

$dir = base_path('node_modules/puppeteer/.local-chromium');
$dir = base_path('vendor/spatie/browsershot');

if (false === is_dir($dir)) {
return $this->sendError(__('Puppeteer dependencies not installed, run `npm install @nesk/puphpeteer --no-save`'));
return $this->sendError(__('Puppeteer dependencies not installed, run `composer require spatie/browsershot`'));
}

try {
$name = LinkArchive::archive(url()->route('home'), 'pdf');
$name = LinkArchive::archive('http://example.com', 'pdf');
} catch (\Exception $e) {
return $this->sendError(__('Unable to create archive, error is: :message', ['message' => $e->getMessage()]));
}
Expand Down
53 changes: 53 additions & 0 deletions app/Services/LinkArchive/BrowsershotProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Services\LinkArchive;

use Spatie\Browsershot\Browsershot;

class BrowsershotProvider extends BaseProvider
{
public function makeArchive(): ?string
{
$name = md5($this->url) . '.pdf';
$filename = sprintf('app/archives/%s', $name);
$windowWidth = app('shaark')->getArchivePdfWidth();
$windowHeight = app('shaark')->getArchivePdfHeight();
$nodeBin = app('shaark')->getNodeBin();

try {
$browsershot = new Browsershot($this->url, true);
$browsershot
->windowSize($windowWidth, $windowHeight)
->margins(0,0,0,0)
->setNodeBinary($nodeBin)
->setNodeModulePath('node_modules/')
->setIncludePath('/usr/bin/')
->showBackground()
->addChromiumArguments([
'disable-dev-shm-usage'
])
->noSandbox()
->ignoreHttpsErrors()
->dismissDialogs()
->waitUntilNetworkIdle()
->emulateMedia('screen')
->save(storage_path($filename))
;
} catch (\Exception $e) {
throw new \RuntimeException("Unable to create link archive", 0, $e);
}

return $name;
}

public function isEnabled(): bool
{
return app('shaark')->getLinkArchivePdf() === true;
}

public function canArchive(): bool
{
return true;
}
}

2 changes: 1 addition & 1 deletion app/Services/LinkArchive/LinkArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class LinkArchive
/** @var array $providers */
public static $providers = [
'media' => YoutubeDlProvider::class,
'pdf' => PuppeteerProvider::class,
'pdf' => BrowsershotProvider::class,
];

public static function availableFor(string $url): array
Expand Down
58 changes: 0 additions & 58 deletions app/Services/LinkArchive/PuppeteerProvider.php

This file was deleted.

10 changes: 10 additions & 0 deletions app/crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# do daily/weekly/monthly maintenance
# min hour day month weekday command
*/15 * * * * run-parts /etc/periodic/15min
0 * * * * run-parts /etc/periodic/hourly
0 2 * * * run-parts /etc/periodic/daily
0 3 * * 6 run-parts /etc/periodic/weekly
0 5 1 * * run-parts /etc/periodic/monthly
# run backups configured by Shaark
* * * * * cd /app && php artisan schedule:run >> /dev/null 2>&1

27 changes: 27 additions & 0 deletions app/entrypoint-shaark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

cd /app
echo "Clearing any cached config."
php artisan config:clear
if [ "`php artisan migrate:status`" = "Migration table not found." ]; then
echo "Migrating database and creating default Admin user."
php artisan migrate --seed --force
echo "Admin Username: [email protected]"
echo "Admin Password: "${APP_ADMIN_PASSWORD}
elif [ "${APP_MIGRATE_DB}" = 'true' ] && \
[ `php artisan migrate:status|cut -d'|' -f2 |grep -c "No"` -gt 0 ]; then
echo "Migrating database."
php artisan migrate --force
else
echo "Database migration skipped."
fi

if [ "${APP_DEBUG}" = 'true' ]; then
echo "Debugging enabled: creating verbose logs at /app/storage/logs/"
php artisan queue:work >> storage/logs/artisan_queue.log &
php artisan serve --host=0.0.0.0 --port=80 -vvv >> storage/logs/artisan_serve.log
else
echo "Starting Shaark!"
php artisan queue:work &
php artisan serve --host=0.0.0.0 --port=80
fi
Loading