forked from MarceauKa/shaark
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from squ1rr3lly/fix_archiving
Fix archiving/backup, update pdf library, clean up Dockerfile
- Loading branch information
Showing
12 changed files
with
192 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ Homestead.yaml | |
npm-debug.log | ||
package-lock.json | ||
yarn-error.log | ||
docker-compose.override.yml |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
FROM php: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 puppeteer@3.1.0 | ||
|
||
# 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 and php extensions | ||
RUN 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 | ||
|
||
# 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" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
#!/bin/bash | ||
FILE=.app_initialized | ||
|
||
cd /app | ||
echo "Clearing any cached config." | ||
php artisan config:clear | ||
if [ ! -f $FILE ]; then | ||
echo "Migrating database and creating default Admin user." | ||
php artisan migrate --seed --force | ||
echo "Admin Username: admin@example.com" | ||
echo "Admin Password: secret" | ||
touch $FILE | ||
elif [ "${APP_MIGRATE_DB}" = 'true' ]; then | ||
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: admin@example.com" | ||
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 | ||
php artisan serve --host=0.0.0.0 --port=80 | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters