Skip to content

Commit ed85946

Browse files
author
Simon Lightfoot
committed
Initial project commit
0 parents  commit ed85946

File tree

6 files changed

+115
-0
lines changed

6 files changed

+115
-0
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
LICENSE*
2+
README*
3+
app/vendor/*

Caddyfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
0.0.0.0
2+
3+
# Start PHP application listening for FastCGI requests
4+
startup /usr/bin/php /srv/command.php run --port=9000 --host=localhost &
5+
6+
# Tell caddy to forward requests of FastCGI to PHP app
7+
fastcgi / localhost:9000
8+
9+
# Set logging to stdout
10+
log stdout
11+
errors stdout

Dockerfile

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
FROM alpine:3.3
2+
3+
# Expose HTTP HTTPS and Caddy ports
4+
EXPOSE 80 443 2015
5+
6+
# Update/Upgrade packages
7+
RUN apk update --no-cache && apk upgrade --no-cache --available
8+
9+
# Install ssh-client, php and required php extensions for composer and app
10+
RUN apk add --no-cache --update \
11+
openssh-client \
12+
tar \
13+
php \
14+
php-curl \
15+
php-openssl \
16+
php-phar \
17+
php-pcntl \
18+
php-json
19+
20+
# Register the COMPOSER_HOME environment variable
21+
ENV COMPOSER_HOME /composer
22+
23+
# Add global binary directory to PATH and make sure to re-export it
24+
ENV PATH /composer/vendor/bin:$PATH
25+
26+
# Allow Composer to be run as root
27+
ENV COMPOSER_ALLOW_SUPERUSER 1
28+
29+
# Setup the Composer installer
30+
RUN curl -o /tmp/composer-setup.php https://getcomposer.org/installer \
31+
&& curl -o /tmp/composer-setup.sig https://composer.github.io/installer.sig \
32+
&& php -r "if (hash('SHA384', file_get_contents('/tmp/composer-setup.php')) !== trim(file_get_contents('/tmp/composer-setup.sig'))) { unlink('/tmp/composer-setup.php'); echo 'Invalid installer' . PHP_EOL; exit(1); }"
33+
34+
# Install composer and show version information
35+
RUN php /tmp/composer-setup.php --install-dir=/usr/sbin --filename=composer \
36+
&& rm -rf /tmp/composer-setup.php \
37+
&& composer --version
38+
39+
# Download and install Caddy and show version information
40+
RUN curl --silent --show-error --fail --location \
41+
--header "Accept: application/tar+gzip, application/x-gzip, application/octet-stream" -o - \
42+
"https://caddyserver.com/download/build?os=linux&arch=amd64" \
43+
| tar --no-same-owner -C /usr/sbin/ -xz caddy \
44+
&& chmod 0755 /usr/sbin/caddy \
45+
&& /usr/sbin/caddy -version
46+
47+
# Set the working directory to /srv
48+
WORKDIR /srv
49+
50+
# Copy application to container
51+
COPY app/ /srv
52+
53+
# Run composer on application
54+
RUN chdir /srv && /usr/sbin/composer --ansi install
55+
56+
# Copy Caddy config file over
57+
ADD Caddyfile /etc/Caddyfile
58+
59+
# Set container entry point and parameters to Caddy
60+
ENTRYPOINT ["/usr/sbin/caddy"]
61+
CMD ["--conf", "/etc/Caddyfile"]

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
Build docker image with:
3+
```bash
4+
docker build -t phpfastcgi .
5+
```
6+
7+
Run docker image with:
8+
```bash
9+
docker run -it --rm -p :2015:2015 --name phpfastcgi phpfastcgi
10+
```
11+
or detached with:
12+
```bash
13+
docker run -d -p :2015:2015 --name phpfastcgi phpfastcgi
14+
```

app/command.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php // command.php
2+
3+
// Include the composer autoloader
4+
require_once dirname(__FILE__) . '/vendor/autoload.php';
5+
6+
use PHPFastCGI\FastCGIDaemon\ApplicationFactory;
7+
use PHPFastCGI\FastCGIDaemon\Http\RequestInterface;
8+
use Zend\Diactoros\Response\HtmlResponse;
9+
10+
// A simple kernel. This is the core of your application
11+
$kernel = function (RequestInterface $request) {
12+
// $request->getServerRequest() returns PSR-7 server request object
13+
// $request->getHttpFoundationRequest() returns HTTP foundation request object
14+
return new HtmlResponse('<h1>Hello, World!</h1>');
15+
};
16+
17+
// Create your Symfony console application using the factory
18+
$application = (new ApplicationFactory)->createApplication($kernel);
19+
20+
// Run the Symfony console application
21+
$application->run();

app/composer.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"phpfastcgi/fastcgi-daemon": "^0.8.0"
4+
}
5+
}

0 commit comments

Comments
 (0)