Skip to content

Commit

Permalink
Merge pull request #12 from R0Wi/docker-setup
Browse files Browse the repository at this point in the history
Add docker based setup
  • Loading branch information
amenk committed Jul 6, 2023
2 parents e6dd01e + 9ba7732 commit e4f514f
Show file tree
Hide file tree
Showing 12 changed files with 2,034 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./public/demo
./public/env.php
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
public/env.php
logs/polite.log
logs/polite.log
/vendor/
.phpunit.cache
/coverage/
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM php:8.2-apache

# Set default logging to stdout so that logs can be shown via docker logs
ENV LOG_FILE php://stdout

# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

# Install php extension apcu
RUN pecl install apcu \
&& docker-php-ext-enable apcu

# Copy our application code
COPY ./public /var/www/html
COPY ./src /var/www/src

# Activate the env file (configuration will be done via env-variables)
RUN mv /var/www/src/FriendlyCaptcha/Lite/Env.template.php /var/www/src/FriendlyCaptcha/Lite/Env.php \
&& chown -R www-data:www-data /var/www/src
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,35 @@ You need a web server running PHP 7.4 or later.
Instead of `https://api.friendlycaptcha.com/api/v1/siteverify` use `https://yourserver/siteverify.php`.
Instead of `https://(eu-)api.friendlycaptcha.eu/api/v1/puzzle"` use `https://yourserver/puzzle.php`.

## Running as Docker Container

You can also run the server as a docker container. Use the following command to build the container:

```bash
docker build -t friendly-lite-server .
```

Then run the container with the following command:

```bash
docker run -d -p 80:80 -e "SECRET=FILL-YOUR-SECRET-HERE" -e "API_KEY=FILL-YOUR-API-KEY-HERE" friendly-lite-server
```

Alternatively, use the following `docker-compose` commands:

```bash
docker-compose build
docker-compose up -d
```

When using Docker, the following environment variables are available:

* `SECRET`: Your secret
* `API_KEY`: Your api key
* `LOG_FILE`: Default is `php://stdout`.
* `SCALING_TTL_SECONDS`: Default is `1800`
* `EXPIRY_TIMES_5_MINUTES`: Default is `12`

## What works

* Check of signature
Expand All @@ -34,6 +63,23 @@ Instead of `https://(eu-)api.friendlycaptcha.eu/api/v1/puzzle"` use `https://you
* Replay checks
* Basic difficulty scaling

## Executing tests

To run the included [PHPUnit](https://phpunit.de/index.html) tests, make sure you have [composer](https://getcomposer.org/) installed. Then run:

```bash
composer install
./vendor/bin/phpunit
```

If you want to execute the [PHPUnit code coverage reporting](https://docs.phpunit.de/en/9.6/textui.html#the-command-line-test-runner), make sure you have [XDebug](https://xdebug.org/docs/install) installed and activated in your PHP CLI ini. You could for example install it via `pecl install xdebug` and then make sure your `/etc/php/x.xx/cli/php.ini` contains a line like `zend_extension=xdebug.so`. Then, to for example create an HTML coverage report, run:

```bash
XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html coverage
```

Your report will be saved to the `coverage` folder in this example.

## License

This software is [**fair-code**](http://faircode.io) distributed under [**Apache 2.0 with Commons Attribution Clause**](https://github.com/FriendlyCaptcha/friendly-lite-server/blob/main/LICENSE) license.
Expand Down
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "friendlycaptcha/friendly-lite-server",
"description": "Lite server for Friendly Captcha",
"require-dev": {
"phpunit/phpunit": "^9.6"
},
"license": "Apache 2.0 with Commons Attribution Clause",
"authors": [
{
"name": "Friendly Captcha GmbH (www.friendlycaptcha.com)"
}
],
"require": {},
"autoload": {
"psr-4": {
"FriendlyCaptcha\\Lite\\": "src/FriendlyCaptcha/Lite"
},
"classmap": [
"src/"
]
}
}

0 comments on commit e4f514f

Please sign in to comment.