improvements to run inside docker
This commit is contained in:
parent
9d3939b87f
commit
ad9cca36b1
@ -5,3 +5,4 @@ data
|
|||||||
images
|
images
|
||||||
thumbs
|
thumbs
|
||||||
*.sqlite
|
*.sqlite
|
||||||
|
Dockerfile
|
||||||
|
9
.github/workflows/test_and_publish.yml
vendored
9
.github/workflows/test_and_publish.yml
vendored
@ -64,13 +64,13 @@ jobs:
|
|||||||
- name: Run test suite
|
- name: Run test suite
|
||||||
run: |
|
run: |
|
||||||
if [[ "${{ matrix.database }}" == "pgsql" ]]; then
|
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
|
fi
|
||||||
if [[ "${{ matrix.database }}" == "mysql" ]]; then
|
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
|
fi
|
||||||
if [[ "${{ matrix.database }}" == "sqlite" ]]; then
|
if [[ "${{ matrix.database }}" == "sqlite" ]]; then
|
||||||
export DSN="sqlite:data/shimmie.sqlite"
|
export TEST_DSN="sqlite:data/shimmie.sqlite"
|
||||||
fi
|
fi
|
||||||
vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover=data/coverage.clover
|
vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover=data/coverage.clover
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ jobs:
|
|||||||
name: Publish
|
name: Publish
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: test
|
needs: test
|
||||||
if: github.ref == 'refs/heads/master'
|
if: github.event_name == 'push'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- name: Publish to Registry
|
- name: Publish to Registry
|
||||||
@ -92,3 +92,4 @@ jobs:
|
|||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
cache: ${{ github.event_name != 'schedule' }}
|
cache: ${{ github.event_name != 'schedule' }}
|
||||||
|
buildoptions: "--build-arg RUN_TESTS=false"
|
||||||
|
46
Dockerfile
46
Dockerfile
@ -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
|
FROM debian:stable-slim
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
RUN apt update && apt install -y composer php7.3-gd php7.3-dom php7.3-sqlite3 imagemagick
|
||||||
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
|
|
||||||
|
|
||||||
COPY composer.json composer.lock /app/
|
COPY composer.json composer.lock /app/
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN composer install
|
RUN composer install
|
||||||
|
|
||||||
COPY . /app/
|
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 && \
|
ARG RUN_TESTS=true
|
||||||
# echo '=== Smoke Test ===' && php index.php get-page /post/list && \
|
RUN [ $RUN_TESTS = false ] || (\
|
||||||
# echo '=== Unit Tests ===' && ./vendor/bin/phpunit --configuration tests/phpunit.xml && \
|
echo '=== Installing ===' && mkdir -p data/config && INSTALL_DSN="sqlite:data/shimmie.sqlite" php index.php && \
|
||||||
# echo '=== Coverage ===' && ./vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-text && \
|
echo '=== Smoke Test ===' && php index.php get-page /post/list && \
|
||||||
# echo '=== Cleaning ===' && rm -rf data
|
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"]
|
CMD ["/bin/sh", "/app/tests/docker-init.sh"]
|
||||||
|
22
README.md
22
README.md
@ -48,23 +48,21 @@ check out one of the versioned branches.
|
|||||||
5. Follow instructions noted in "Installation" starting from step 3.
|
5. Follow instructions noted in "Installation" starting from step 3.
|
||||||
|
|
||||||
# Docker
|
# 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
|
If you want to build your own image from source:
|
||||||
simple debian image and run all the unit tests inside it:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
docker build -t shimmie .
|
docker build -t shimmie .
|
||||||
```
|
```
|
||||||
|
|
||||||
Once you have an image which has passed all tests, you can then run it to get
|
There are various options settable with environment variables:
|
||||||
a live system:
|
- `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"`
|
||||||
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.
|
|
||||||
|
|
||||||
### Upgrade from earlier versions
|
### Upgrade from earlier versions
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
function install()
|
function install()
|
||||||
{
|
{
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
define("DATABASE_TIMEOUT", 10000);
|
|
||||||
|
|
||||||
if (is_readable("data/config/shimmie.conf.php")) {
|
if (is_readable("data/config/shimmie.conf.php")) {
|
||||||
exit_with_page(
|
exit_with_page(
|
||||||
@ -59,10 +58,8 @@ function install()
|
|||||||
|
|
||||||
function get_dsn()
|
function get_dsn()
|
||||||
{
|
{
|
||||||
if (file_exists("data/config/auto_install.conf.php")) {
|
if (getenv("INSTALL_DSN")) {
|
||||||
$dsn = null;
|
$dsn = getenv("INSTALL_DSN");;
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
require_once "data/config/auto_install.conf.php";
|
|
||||||
} elseif (@$_POST["database_type"] == DatabaseDriver::SQLITE) {
|
} elseif (@$_POST["database_type"] == DatabaseDriver::SQLITE) {
|
||||||
/** @noinspection PhpUnhandledExceptionInspection */
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
$id = bin2hex(random_bytes(5));
|
$id = bin2hex(random_bytes(5));
|
||||||
@ -136,37 +133,34 @@ function ask_questions()
|
|||||||
$warn_msg
|
$warn_msg
|
||||||
$err_msg
|
$err_msg
|
||||||
|
|
||||||
<h3>Database Install</h3>
|
|
||||||
<form action="index.php" method="POST">
|
<form action="index.php" method="POST">
|
||||||
<div style="text-align: center;">
|
<table class='form' style="margin: 1em auto;">
|
||||||
<table class='form'>
|
<tr>
|
||||||
<tr>
|
<th>Type:</th>
|
||||||
<th>Type:</th>
|
<td><select name="database_type" id="database_type" onchange="update_qs();">
|
||||||
<td><select name="database_type" id="database_type" onchange="update_qs();">
|
$db_m
|
||||||
$db_m
|
$db_p
|
||||||
$db_p
|
$db_s
|
||||||
$db_s
|
</select></td>
|
||||||
</select></td>
|
</tr>
|
||||||
</tr>
|
<tr class="dbconf mysql pgsql">
|
||||||
<tr class="dbconf mysql pgsql">
|
<th>Host:</th>
|
||||||
<th>Host:</th>
|
<td><input type="text" name="database_host" size="40" value="localhost"></td>
|
||||||
<td><input type="text" name="database_host" size="40" value="localhost"></td>
|
</tr>
|
||||||
</tr>
|
<tr class="dbconf mysql pgsql">
|
||||||
<tr class="dbconf mysql pgsql">
|
<th>Username:</th>
|
||||||
<th>Username:</th>
|
<td><input type="text" name="database_user" size="40"></td>
|
||||||
<td><input type="text" name="database_user" size="40"></td>
|
</tr>
|
||||||
</tr>
|
<tr class="dbconf mysql pgsql">
|
||||||
<tr class="dbconf mysql pgsql">
|
<th>Password:</th>
|
||||||
<th>Password:</th>
|
<td><input type="password" name="database_password" size="40"></td>
|
||||||
<td><input type="password" name="database_password" size="40"></td>
|
</tr>
|
||||||
</tr>
|
<tr class="dbconf mysql pgsql">
|
||||||
<tr class="dbconf mysql pgsql">
|
<th>DB Name:</th>
|
||||||
<th>DB Name:</th>
|
<td><input type="text" name="database_name" size="40" value="shimmie"></td>
|
||||||
<td><input type="text" name="database_name" size="40" value="shimmie"></td>
|
</tr>
|
||||||
</tr>
|
<tr><td colspan="2"><input type="submit" value="Go!"></td></tr>
|
||||||
<tr><td colspan="2"><input type="submit" value="Go!"></td></tr>
|
</table>
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', update_qs);
|
document.addEventListener('DOMContentLoaded', update_qs);
|
||||||
function q(n) {
|
function q(n) {
|
||||||
@ -205,14 +199,14 @@ EOD
|
|||||||
function create_dirs()
|
function create_dirs()
|
||||||
{
|
{
|
||||||
$data_exists = file_exists("data") || mkdir("data");
|
$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) {
|
if (!$data_exists || !$data_writable) {
|
||||||
throw new InstallerException(
|
throw new InstallerException(
|
||||||
"Directory Permissions Error:",
|
"Directory Permissions Error:",
|
||||||
"<p>Shimmie needs to have a 'data' folder in its directory, writable by the PHP user.</p>
|
"<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>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>",
|
<p>Once you have created this folder and / or changed the ownership of the shimmie folder, hit 'refresh' to continue.</p>",
|
||||||
7
|
7
|
||||||
);
|
);
|
||||||
@ -319,7 +313,7 @@ function write_config($dsn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (file_put_contents("data/config/shimmie.conf.php", $file_content, LOCK_EX)) {
|
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(
|
exit_with_page(
|
||||||
"Installation Successful",
|
"Installation Successful",
|
||||||
"<p>If you aren't redirected, <a href=\"index.php\">click here to Continue</a>."
|
"<p>If you aren't redirected, <a href=\"index.php\">click here to Continue</a>."
|
||||||
|
@ -29,7 +29,7 @@ and of course start organising your images :-)
|
|||||||
";
|
";
|
||||||
$page->set_title("Welcome to Shimmie ".VERSION);
|
$page->set_title("Welcome to Shimmie ".VERSION);
|
||||||
$page->set_heading("Welcome to Shimmie");
|
$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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,10 +58,10 @@ IMG.lazy {display: none;}
|
|||||||
padding: 2px;
|
padding: 2px;
|
||||||
}
|
}
|
||||||
#installer H1 {
|
#installer H1 {
|
||||||
border-bottom: 1px solid black;
|
|
||||||
border-radius: 16px 16px 0 0;
|
border-radius: 16px 16px 0 0;
|
||||||
}
|
}
|
||||||
#installer H3 {
|
#installer H3 {
|
||||||
|
border-top: 1px solid black;
|
||||||
border-bottom: 1px solid black;
|
border-bottom: 1px solid black;
|
||||||
}
|
}
|
||||||
#installer TH {
|
#installer TH {
|
||||||
|
@ -21,7 +21,7 @@ $_tracer = new EventTracer();
|
|||||||
$_tracer->begin("bootstrap");
|
$_tracer->begin("bootstrap");
|
||||||
_load_core_files();
|
_load_core_files();
|
||||||
$cache = new Cache(CACHE_DSN);
|
$cache = new Cache(CACHE_DSN);
|
||||||
$dsn = getenv("DSN");
|
$dsn = getenv("TEST_DSN");
|
||||||
$database = new Database($dsn ? $dsn : "sqlite::memory:");
|
$database = new Database($dsn ? $dsn : "sqlite::memory:");
|
||||||
create_dirs();
|
create_dirs();
|
||||||
create_tables($database);
|
create_tables($database);
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
echo "<?php define(\"DATABASE_DSN\", \"${DB_DSN}\");" > data/config/auto_install.conf.php
|
groupadd -g $GID shimmie
|
||||||
/usr/bin/php -d upload_max_filesize=50M -d post_max_size=50M -S 0.0.0.0:8000 tests/router.php
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user