improvements to run inside docker

This commit is contained in:
Shish 2020-03-22 15:23:23 +00:00
parent 9d3939b87f
commit ad9cca36b1
9 changed files with 89 additions and 72 deletions

View File

@ -5,3 +5,4 @@ data
images
thumbs
*.sqlite
Dockerfile

View File

@ -64,13 +64,13 @@ jobs:
- name: Run test suite
run: |
if [[ "${{ matrix.database }}" == "pgsql" ]]; then
export DSN="pgsql:user=shimmie;password=shimmie;host=127.0.0.1;dbname=shimmie"
export TEST_DSN="pgsql:user=shimmie;password=shimmie;host=127.0.0.1;dbname=shimmie"
fi
if [[ "${{ matrix.database }}" == "mysql" ]]; then
export DSN="mysql:user=root;password=root;host=127.0.0.1;dbname=shimmie"
export TEST_DSN="mysql:user=root;password=root;host=127.0.0.1;dbname=shimmie"
fi
if [[ "${{ matrix.database }}" == "sqlite" ]]; then
export DSN="sqlite:data/shimmie.sqlite"
export TEST_DSN="sqlite:data/shimmie.sqlite"
fi
vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover=data/coverage.clover
@ -82,7 +82,7 @@ jobs:
name: Publish
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/master'
if: github.event_name == 'push'
steps:
- uses: actions/checkout@master
- name: Publish to Registry
@ -92,3 +92,4 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
cache: ${{ github.event_name != 'schedule' }}
buildoptions: "--build-arg RUN_TESTS=false"

View File

@ -1,19 +1,39 @@
# "Build" shimmie (composer install - done in its own stage so that we don't
# need to include all the composer fluff in the final image)
FROM debian:stable-slim
ENV DEBIAN_FRONTEND=noninteractive
EXPOSE 8000
HEALTHCHECK --interval=5m --timeout=3s CMD curl --fail http://127.0.0.1:8000/ || exit 1
RUN apt update && apt install -y curl \
php7.3-cli php7.3-gd php7.3-pgsql php7.3-mysql php7.3-sqlite3 php7.3-zip php7.3-dom php7.3-mbstring php-xdebug \
composer imagemagick vim zip unzip
RUN apt update && apt install -y composer php7.3-gd php7.3-dom php7.3-sqlite3 imagemagick
COPY composer.json composer.lock /app/
WORKDIR /app
RUN composer install
COPY . /app/
#RUN echo '=== Installing ===' && mkdir -p data/config && echo "<?php \$dsn = \"sqlite:data/shimmie.sqlite\";" > data/config/auto_install.conf.php && php index.php && \
# echo '=== Smoke Test ===' && php index.php get-page /post/list && \
# echo '=== Unit Tests ===' && ./vendor/bin/phpunit --configuration tests/phpunit.xml && \
# echo '=== Coverage ===' && ./vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-text && \
# echo '=== Cleaning ===' && rm -rf data
ARG RUN_TESTS=true
RUN [ $RUN_TESTS = false ] || (\
echo '=== Installing ===' && mkdir -p data/config && INSTALL_DSN="sqlite:data/shimmie.sqlite" php index.php && \
echo '=== Smoke Test ===' && php index.php get-page /post/list && \
echo '=== Unit Tests ===' && ./vendor/bin/phpunit --configuration tests/phpunit.xml && \
echo '=== Coverage ===' && ./vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-text && \
echo '=== Cleaning ===' && rm -rf data)
# Build su-exec so that our final image can be nicer
FROM debian:stable-slim
RUN apt-get update && apt-get install -y --no-install-recommends gcc libc-dev curl
RUN curl -k -o /usr/local/bin/su-exec.c https://raw.githubusercontent.com/ncopa/su-exec/master/su-exec.c; \
gcc -Wall /usr/local/bin/su-exec.c -o/usr/local/bin/su-exec; \
chown root:root /usr/local/bin/su-exec; \
chmod 0755 /usr/local/bin/su-exec;
# Actually run shimmie
FROM debian:stable-slim
EXPOSE 8000
HEALTHCHECK --interval=5m --timeout=3s CMD curl --fail http://127.0.0.1:8000/ || exit 1
ENV UID=1000 \
GID=1000
RUN apt update && apt install -y curl \
php7.3-cli php7.3-gd php7.3-pgsql php7.3-mysql php7.3-sqlite3 php7.3-zip php7.3-dom php7.3-mbstring php-xdebug \
composer imagemagick vim zip unzip && \
rm -rf /var/lib/apt/lists/*
COPY --from=0 /app /app
COPY --from=1 /usr/local/bin/su-exec /usr/local/bin/su-exec
WORKDIR /app
CMD ["/bin/sh", "/app/tests/docker-init.sh"]

View File

@ -48,23 +48,21 @@ check out one of the versioned branches.
5. Follow instructions noted in "Installation" starting from step 3.
# Docker
If you just want to run shimmie inside docker, there's a pre-built image
in dockerhub - `shish2k/shimmie2` - which can be used like:
```
docker run -p 8000 -v /my/hard/drive:/app/data shish2k/shimmie2
```
Useful for testing in a known-good environment, this command will build a
simple debian image and run all the unit tests inside it:
If you want to build your own image from source:
```
docker build -t shimmie .
```
Once you have an image which has passed all tests, you can then run it to get
a live system:
```
docker run -p 0.0.0.0:8123:8000 -v /mnt/shimmie-data:/app/data shimmie
```
Then you can visit your server on port 8123 to see the site, with data
stored in /mnt/shimmie-data on your local drive.
There are various options settable with environment variables:
- `UID` / `GID` - which user ID to run as (default 1000/1000)
- `INSTALL_DSN` - specify a data source to install into, to skip the installer screen, eg
`-e INSTALL_DSN="pgsql:user=shimmie;password=6y5erdfg;host=127.0.0.1;dbname=shimmie"`
### Upgrade from earlier versions

View File

@ -18,7 +18,6 @@
function install()
{
date_default_timezone_set('UTC');
define("DATABASE_TIMEOUT", 10000);
if (is_readable("data/config/shimmie.conf.php")) {
exit_with_page(
@ -59,10 +58,8 @@ function install()
function get_dsn()
{
if (file_exists("data/config/auto_install.conf.php")) {
$dsn = null;
/** @noinspection PhpIncludeInspection */
require_once "data/config/auto_install.conf.php";
if (getenv("INSTALL_DSN")) {
$dsn = getenv("INSTALL_DSN");;
} elseif (@$_POST["database_type"] == DatabaseDriver::SQLITE) {
/** @noinspection PhpUnhandledExceptionInspection */
$id = bin2hex(random_bytes(5));
@ -136,37 +133,34 @@ function ask_questions()
$warn_msg
$err_msg
<h3>Database Install</h3>
<form action="index.php" method="POST">
<div style="text-align: center;">
<table class='form'>
<tr>
<th>Type:</th>
<td><select name="database_type" id="database_type" onchange="update_qs();">
$db_m
$db_p
$db_s
</select></td>
</tr>
<tr class="dbconf mysql pgsql">
<th>Host:</th>
<td><input type="text" name="database_host" size="40" value="localhost"></td>
</tr>
<tr class="dbconf mysql pgsql">
<th>Username:</th>
<td><input type="text" name="database_user" size="40"></td>
</tr>
<tr class="dbconf mysql pgsql">
<th>Password:</th>
<td><input type="password" name="database_password" size="40"></td>
</tr>
<tr class="dbconf mysql pgsql">
<th>DB&nbsp;Name:</th>
<td><input type="text" name="database_name" size="40" value="shimmie"></td>
</tr>
<tr><td colspan="2"><input type="submit" value="Go!"></td></tr>
</table>
</div>
<table class='form' style="margin: 1em auto;">
<tr>
<th>Type:</th>
<td><select name="database_type" id="database_type" onchange="update_qs();">
$db_m
$db_p
$db_s
</select></td>
</tr>
<tr class="dbconf mysql pgsql">
<th>Host:</th>
<td><input type="text" name="database_host" size="40" value="localhost"></td>
</tr>
<tr class="dbconf mysql pgsql">
<th>Username:</th>
<td><input type="text" name="database_user" size="40"></td>
</tr>
<tr class="dbconf mysql pgsql">
<th>Password:</th>
<td><input type="password" name="database_password" size="40"></td>
</tr>
<tr class="dbconf mysql pgsql">
<th>DB&nbsp;Name:</th>
<td><input type="text" name="database_name" size="40" value="shimmie"></td>
</tr>
<tr><td colspan="2"><input type="submit" value="Go!"></td></tr>
</table>
<script>
document.addEventListener('DOMContentLoaded', update_qs);
function q(n) {
@ -205,14 +199,14 @@ EOD
function create_dirs()
{
$data_exists = file_exists("data") || mkdir("data");
$data_writable = is_writable("data") || chmod("data", 0755);
$data_writable = $data_exists && (is_writable("data") || chmod("data", 0755));
if (!$data_exists || !$data_writable) {
throw new InstallerException(
"Directory Permissions Error:",
"<p>Shimmie needs to have a 'data' folder in its directory, writable by the PHP user.</p>
<p>If you see this error, if probably means the folder is owned by you, and it needs to be writable by the web server.</p>
<p>PHP reports that it is currently running as user: ".$_ENV["USER"]." (". $_SERVER["USER"] .")</p>
<p>PHP reports that it is currently running as user: ".get_current_user()." (". getmyuid() .")</p>
<p>Once you have created this folder and / or changed the ownership of the shimmie folder, hit 'refresh' to continue.</p>",
7
);
@ -319,7 +313,7 @@ function write_config($dsn)
}
if (file_put_contents("data/config/shimmie.conf.php", $file_content, LOCK_EX)) {
header("Location: index.php");
header("Location: index.php?flash=Installation%20complete");
exit_with_page(
"Installation Successful",
"<p>If you aren't redirected, <a href=\"index.php\">click here to Continue</a>."

View File

@ -29,7 +29,7 @@ and of course start organising your images :-)
";
$page->set_title("Welcome to Shimmie ".VERSION);
$page->set_heading("Welcome to Shimmie");
$page->add_block(new Block("Installation Succeeded!", $text, "main", 0));
$page->add_block(new Block("Nothing here yet!", $text, "main", 0));
}
/**

View File

@ -58,10 +58,10 @@ IMG.lazy {display: none;}
padding: 2px;
}
#installer H1 {
border-bottom: 1px solid black;
border-radius: 16px 16px 0 0;
}
#installer H3 {
border-top: 1px solid black;
border-bottom: 1px solid black;
}
#installer TH {

View File

@ -21,7 +21,7 @@ $_tracer = new EventTracer();
$_tracer->begin("bootstrap");
_load_core_files();
$cache = new Cache(CACHE_DSN);
$dsn = getenv("DSN");
$dsn = getenv("TEST_DSN");
$database = new Database($dsn ? $dsn : "sqlite::memory:");
create_dirs();
create_tables($database);

View File

@ -1,3 +1,6 @@
#!/bin/sh
echo "<?php define(\"DATABASE_DSN\", \"${DB_DSN}\");" > data/config/auto_install.conf.php
/usr/bin/php -d upload_max_filesize=50M -d post_max_size=50M -S 0.0.0.0:8000 tests/router.php
groupadd -g $GID shimmie
useradd -ms /bin/bash -u $UID -g $GID shimmie
mkdir /app/data
chown shimmie:shimmie /app/data
exec /usr/local/bin/su-exec shimmie:shimmie /usr/bin/php -d upload_max_filesize=50M -d post_max_size=50M -S 0.0.0.0:8000 tests/router.php