Skip to content

Commit

Permalink
Implementing Docker Image (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis authored Apr 12, 2021
1 parent d748719 commit f587210
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 11 deletions.
27 changes: 27 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# JBZoo Toolbox - Mock-Server
#
# This file is part of the JBZoo Toolbox project.
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#
# @package Mock-Server
# @license MIT
# @copyright Copyright (C) JBZoo.com, All rights reserved.
# @link https://github.com/JBZoo/Mock-Server
#

.idea
.phan
build
mocks
tests
vendor

.editorconfig
.phpunit.result.cache
.travis.yml
box.json.dist
Makefile
phpunit.xml.dist
README.md
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
# @link https://github.com/JBZoo/Mock-Server
#

/build export-ignore
/mocks export-ignore
/examples export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.phpstorm.meta.php export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore

* text eol=lf

# (binary is a macro for -text -diff)
Expand Down
30 changes: 22 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,28 @@
#

FROM php:7.4-cli-alpine
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

RUN apk add --no-cache libpng libpng-dev \
&& docker-php-ext-install gd \
&& apk del libpng-dev \
&& docker-php-ext-install pcntl \
&& docker-php-ext-install filter \
&& docker-php-ext-install json
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions \
&& sync \
&& install-php-extensions \
opcache \
zip \
gd \
pcntl \
ev \
@composer

COPY build/jbzoo-mock-server.phar /jbzoo-mock-server.phar
COPY . /app
RUN cd /app \
&& composer install --no-dev --optimize-autoloader --no-progress \
&& chmod +x /app/jbzoo-mock-server \
&& /app/jbzoo-mock-server --help

ENTRYPOINT ["/jbzoo-mock-server.phar"]
ENV MOCK_SERVER_IN_DOCKER=1
VOLUME /app/mocks
EXPOSE 8089 8090
ENTRYPOINT ["/app/jbzoo-mock-server"]

#HEALTHCHECK --interval=30s --timeout=3s --start-period=3s --retries=2 CMD curl -f http://localhost:8089 || exit 1
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ MOCK_SERVER_HOST_TLS ?= localhost
MOCK_SERVER_PORT_TLS ?= 8090
MOCK_SERVER_LOG ?= `pwd`/build/server.log
MOCK_SERVER_BIN ?= $(PHP_BIN) `pwd`/jbzoo-mock-server
MOCK_SERVER_DOCKER ?= docker run --rm \
--name="jbzoo-mock-server" \
-v `pwd`/tests/mocks:/mocks \
-p $(MOCK_SERVER_PORT):8089 \
-p $(MOCK_SERVER_PORT_TLS):8089 \
jbzoo-mock-server

PHAR_BOX ?= $(PHP_BIN) `pwd`/vendor/bin/box.phar
PHAR_FILE ?= `pwd`/build/jbzoo-mock-server.phar
Expand Down Expand Up @@ -52,6 +58,11 @@ build-phar: ##@Project Compile phar file
@composer config autoloader-suffix --unset -v


build-docker:
$(call title,"Building Docker Image")
@docker build -t jbzoo-mock-server .


update: ##@Project Update all 3rd party dependencies
$(call title,"Update all 3rd party dependencies")
@composer update --optimize-autoloader --no-progress
Expand Down Expand Up @@ -85,8 +96,20 @@ up-bg: ##@Project Start mock server (non-interactive mode)
@AMP_LOG_COLOR=true make up 1>> "$(MOCK_SERVER_LOG)" 2>> "$(MOCK_SERVER_LOG)" &


up-docker: ##@Project Start mock server (Docker Image)
@$(MOCK_SERVER_DOCKER) \
--host=0.0.0.0 \
--port=8089 \
--host-tls=localhost \
--port-tls=8090 \
--ansi \
-vvv


down: ##@Project Force killing Mock Server
@pgrep -f "jbzoo-mock-server" || true
@-pgrep -f "jbzoo-mock-server" | xargs kill -15 || true
@-docker kill jbzoo-mock-server
@echo "Mock Server killed"


Expand Down
4 changes: 2 additions & 2 deletions jbzoo-mock-server
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ declare(strict_types=1);

use Amp\Http\Server\HttpServer;
use Amp\Http\Server\Server;
use Amp\Loop\NativeDriver;
use JBZoo\MockServer\StartCommand;
use Symfony\Component\Console\Application;

Expand All @@ -32,7 +31,8 @@ if (!class_exists(Server::class)) {
\class_alias(HttpServer::class, Server::class);
}

putenv('AMP_LOOP_DRIVER=' . NativeDriver::class);
#define('MOCK_SERVER_IN_DOCKER', Env::bool('MOCK_SERVER_IN_DOCKER'));
#putenv('AMP_LOOP_DRIVER=' . NativeDriver::class);

$application = new Application();
$application->add(new StartCommand());
Expand Down
2 changes: 1 addition & 1 deletion src/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function configure(): void
->addOption('port', null, $req, "Port", (string)MockServer::DEFAULT_PORT)
->addOption('host-tls', null, $req, "Host", MockServer::DEFAULT_HOST)
->addOption('port-tls', null, $req, "Port", (string)MockServer::DEFAULT_PORT_TLS)
->addOption('mocks', null, $req, "Mocks path", './mocks')
->addOption('mocks', null, $req, "Mocks path", '/mocks')
->addOption('check-syntax', null, $none, 'Check syntax of PHP files before loading. It takes some time');
}

Expand Down

0 comments on commit f587210

Please sign in to comment.