Skip to content

Commit f587210

Browse files
authored
Implementing Docker Image (#2)
1 parent d748719 commit f587210

File tree

6 files changed

+86
-11
lines changed

6 files changed

+86
-11
lines changed

.dockerignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# JBZoo Toolbox - Mock-Server
3+
#
4+
# This file is part of the JBZoo Toolbox project.
5+
# For the full copyright and license information, please view the LICENSE
6+
# file that was distributed with this source code.
7+
#
8+
# @package Mock-Server
9+
# @license MIT
10+
# @copyright Copyright (C) JBZoo.com, All rights reserved.
11+
# @link https://github.com/JBZoo/Mock-Server
12+
#
13+
14+
.idea
15+
.phan
16+
build
17+
mocks
18+
tests
19+
vendor
20+
21+
.editorconfig
22+
.phpunit.result.cache
23+
.travis.yml
24+
box.json.dist
25+
Makefile
26+
phpunit.xml.dist
27+
README.md

.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
# @link https://github.com/JBZoo/Mock-Server
1212
#
1313

14+
/build export-ignore
15+
/mocks export-ignore
16+
/examples export-ignore
17+
/tests export-ignore
18+
/.editorconfig export-ignore
19+
/.gitattributes export-ignore
20+
/.gitignore export-ignore
21+
/.phpstorm.meta.php export-ignore
22+
/.travis.yml export-ignore
23+
/phpunit.xml.dist export-ignore
24+
1425
* text eol=lf
1526

1627
# (binary is a macro for -text -diff)

Dockerfile

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,28 @@
1212
#
1313

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

16-
RUN apk add --no-cache libpng libpng-dev \
17-
&& docker-php-ext-install gd \
18-
&& apk del libpng-dev \
19-
&& docker-php-ext-install pcntl \
20-
&& docker-php-ext-install filter \
21-
&& docker-php-ext-install json
17+
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
18+
RUN chmod +x /usr/local/bin/install-php-extensions \
19+
&& sync \
20+
&& install-php-extensions \
21+
opcache \
22+
zip \
23+
gd \
24+
pcntl \
25+
ev \
26+
@composer
2227

23-
COPY build/jbzoo-mock-server.phar /jbzoo-mock-server.phar
28+
COPY . /app
29+
RUN cd /app \
30+
&& composer install --no-dev --optimize-autoloader --no-progress \
31+
&& chmod +x /app/jbzoo-mock-server \
32+
&& /app/jbzoo-mock-server --help
2433

25-
ENTRYPOINT ["/jbzoo-mock-server.phar"]
34+
ENV MOCK_SERVER_IN_DOCKER=1
35+
VOLUME /app/mocks
36+
EXPOSE 8089 8090
37+
ENTRYPOINT ["/app/jbzoo-mock-server"]
38+
39+
#HEALTHCHECK --interval=30s --timeout=3s --start-period=3s --retries=2 CMD curl -f http://localhost:8089 || exit 1

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ MOCK_SERVER_HOST_TLS ?= localhost
2323
MOCK_SERVER_PORT_TLS ?= 8090
2424
MOCK_SERVER_LOG ?= `pwd`/build/server.log
2525
MOCK_SERVER_BIN ?= $(PHP_BIN) `pwd`/jbzoo-mock-server
26+
MOCK_SERVER_DOCKER ?= docker run --rm \
27+
--name="jbzoo-mock-server" \
28+
-v `pwd`/tests/mocks:/mocks \
29+
-p $(MOCK_SERVER_PORT):8089 \
30+
-p $(MOCK_SERVER_PORT_TLS):8089 \
31+
jbzoo-mock-server
2632

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

5460

61+
build-docker:
62+
$(call title,"Building Docker Image")
63+
@docker build -t jbzoo-mock-server .
64+
65+
5566
update: ##@Project Update all 3rd party dependencies
5667
$(call title,"Update all 3rd party dependencies")
5768
@composer update --optimize-autoloader --no-progress
@@ -85,8 +96,20 @@ up-bg: ##@Project Start mock server (non-interactive mode)
8596
@AMP_LOG_COLOR=true make up 1>> "$(MOCK_SERVER_LOG)" 2>> "$(MOCK_SERVER_LOG)" &
8697

8798

99+
up-docker: ##@Project Start mock server (Docker Image)
100+
@$(MOCK_SERVER_DOCKER) \
101+
--host=0.0.0.0 \
102+
--port=8089 \
103+
--host-tls=localhost \
104+
--port-tls=8090 \
105+
--ansi \
106+
-vvv
107+
108+
88109
down: ##@Project Force killing Mock Server
110+
@pgrep -f "jbzoo-mock-server" || true
89111
@-pgrep -f "jbzoo-mock-server" | xargs kill -15 || true
112+
@-docker kill jbzoo-mock-server
90113
@echo "Mock Server killed"
91114

92115

jbzoo-mock-server

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ declare(strict_types=1);
1818

1919
use Amp\Http\Server\HttpServer;
2020
use Amp\Http\Server\Server;
21-
use Amp\Loop\NativeDriver;
2221
use JBZoo\MockServer\StartCommand;
2322
use Symfony\Component\Console\Application;
2423

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

35-
putenv('AMP_LOOP_DRIVER=' . NativeDriver::class);
34+
#define('MOCK_SERVER_IN_DOCKER', Env::bool('MOCK_SERVER_IN_DOCKER'));
35+
#putenv('AMP_LOOP_DRIVER=' . NativeDriver::class);
3636

3737
$application = new Application();
3838
$application->add(new StartCommand());

src/StartCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function configure(): void
4343
->addOption('port', null, $req, "Port", (string)MockServer::DEFAULT_PORT)
4444
->addOption('host-tls', null, $req, "Host", MockServer::DEFAULT_HOST)
4545
->addOption('port-tls', null, $req, "Port", (string)MockServer::DEFAULT_PORT_TLS)
46-
->addOption('mocks', null, $req, "Mocks path", './mocks')
46+
->addOption('mocks', null, $req, "Mocks path", '/mocks')
4747
->addOption('check-syntax', null, $none, 'Check syntax of PHP files before loading. It takes some time');
4848
}
4949

0 commit comments

Comments
 (0)