Skip to content

Commit

Permalink
Merge pull request #234 from dayllanmaza/add-docker-dev-env
Browse files Browse the repository at this point in the history
Add docker dev environment
  • Loading branch information
MusikAnimal authored Oct 1, 2020
2 parents 1aa33e4 + 6d52baf commit 8d2ec45
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ composer.phar
config.php
*.sqlite
phpunit.xml
.env
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM php:7.2-apache-stretch

WORKDIR /var/www/html

COPY ./docker/000-default.conf /etc/apache2/sites-available/
COPY ./docker/ports.conf /etc/apache2/

EXPOSE 8080

# work around https://github.com/docker-library/openjdk/blob/0584b2804ed12dca7c5e264b5fc55fc07a3ac148/8-jre/slim/Dockerfile#L51-L54
RUN mkdir -p /usr/share/man/man1

RUN apt-get update -q && apt-get install -y \
epubcheck \
libzip-dev \
unzip \
wget \
xdg-utils \
xz-utils \
&& rm -rf /var/lib/apt/lists/* \
&& pecl install xdebug zip \
&& docker-php-ext-enable xdebug zip \
&& docker-php-ext-install pdo_mysql \
&& wget -nv -O- https://download.calibre-ebook.com/linux-installer.sh | sh /dev/stdin \
&& wget -nv -O- https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer


ENV COMPOSER_ALLOW_SUPERUSER 1
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,62 @@ $ ./vendor/bin/phpunit --exclude-group integration
$ ./vendor/bin/phpunit --group integration # runs integration tests (slow)
```


Docker Developer Environment
============================

Wikisource export can also be run for development using Docker Compose. _(beta, only tested on linux)_

The default environment provides PHP, Apache, Calibre, Epubcheck and a MariaDB database.

### Requirements

You'll need a locally running Docker and Docker Compose:

- [Docker installation instructions][docker-install]
- [Docker Compose installation instructions][docker-compose]

[docker-install]: https://docs.docker.com/install/
[docker-compose]: https://docs.docker.com/compose/install/

---

### Quickstart

Run the following command to add your user ID and group ID to your `.env` file:

```bash
echo "WS_DOCKER_PORT=8888
WS_DOCKER_UID=$(id -u)
WS_DOCKER_GID=$(id -g)" >> .env
```

#### Start environment and install

```bash
# -d is detached mode - runs containers in the background:
docker-compose up -d
```

```bash
# This will create a `config.php` file that you can edit.
docker-compose exec wsexport composer install
```

Modify config.php accordingly
```php
'dbDsn' => 'mysql:host=database;dbname=wsexport;charset=utf8',
'dbUser' => 'root',
'dbPass' => '',
```

```bash
docker-compose exec wsexport php ./bin/install.php
```

Wikisource export should be up at http://localhost:8888


Licence
=======

Expand Down
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.7'
services:
wsexport:
build: ./
user: "${WS_DOCKER_UID}:${WS_DOCKER_GID}"
ports:
- "${WS_DOCKER_PORT}:8080"
volumes:
- ./:/var/www/html:cached
links:
- database:database
environment:
APACHE_RUN_USER: daemon
database:
image: mariadb
restart: always
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=1
- MYSQL_DATABASE=wsexport
32 changes: 32 additions & 0 deletions docker/000-default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<VirtualHost *:8080>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/public
DirectoryIndex book.php

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
15 changes: 15 additions & 0 deletions docker/ports.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 8080

<IfModule ssl_module>
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

0 comments on commit 8d2ec45

Please sign in to comment.