-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Docker Compose support to simplify local development (#47)
* Added Docker Compose support to simplify local development * Got app running PHP on nginx, fixed permissions issue with tmp, added integration for health check endpoint * Updated to mount the nginx conf as a volume to ease development, switched default port to 8080 for portability * Trying to get Xdebug working * Got Xdebug working * Removed unneeded IDE key from Xdebug config * Fixed issues with aphiria service, added composer service, added CI for Docker images * Trying to fix Docker Compose in CI * Trying to fix Docker Compose in CI * Added Composer root version so that the latest can be discerned without needing Git installed in the Docker image * Updated docker compose commands in CI to use modern syntax * Added step to install dependencies * Fixed missing strategy * Updated names of steps in Docker job, added commented-out steps that will eventually be re-enabledF * Updated README to document Docker Compose * Updated CHANGELOG
- Loading branch information
1 parent
a70d324
commit a297844
Showing
10 changed files
with
205 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
networks: | ||
aphiria: | ||
|
||
services: | ||
app: | ||
build: | ||
context: ./infrastructure/docker | ||
dockerfile: nginx.dockerfile | ||
volumes: | ||
- ./:/usr/share/nginx/html | ||
- ./infrastructure/docker/nginx.conf:/etc/nginx/conf.d/default.conf | ||
command: > | ||
sh -c "chmod -R 777 /usr/share/nginx/html/tmp && nginx -g 'daemon off;'" | ||
depends_on: | ||
- php | ||
ports: | ||
- "8080:80" | ||
networks: | ||
- aphiria | ||
|
||
php: | ||
build: | ||
context: ./infrastructure/docker | ||
dockerfile: php.dockerfile | ||
volumes: | ||
- ./:/usr/share/nginx/html | ||
- ./infrastructure/docker/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini | ||
ports: | ||
- "9004:9004" | ||
networks: | ||
- aphiria | ||
|
||
aphiria: | ||
build: | ||
context: ./infrastructure/docker | ||
dockerfile: php.dockerfile | ||
volumes: | ||
- ./:/app | ||
depends_on: | ||
- php | ||
entrypoint: [ 'php', '/app/aphiria' ] | ||
networks: | ||
- aphiria | ||
|
||
composer: | ||
build: | ||
context: ./infrastructure/docker | ||
dockerfile: php.dockerfile | ||
volumes: | ||
- ./:/app | ||
depends_on: | ||
- php | ||
environment: | ||
# Necessary so that Composer can tell what version of the app it's running | ||
- COMPOSER_ROOT_VERSION=1.0.0 | ||
entrypoint: [ 'composer', '--ignore-platform-reqs' ] | ||
networks: | ||
- aphiria |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
server { | ||
index index.php index.html; | ||
error_log /var/log/nginx/error.log; | ||
access_log /var/log/nginx/access.log; | ||
root /usr/share/nginx/html/public; | ||
add_header X-Frame-Options "SAMEORIGIN"; | ||
add_header X-XSS-Protection "1; mode=block"; | ||
add_header X-Content-Type-Options "nosniff"; | ||
|
||
location / { | ||
try_files $uri $uri/ /index.php$is_args$args; | ||
} | ||
|
||
location ~ \.php$ { | ||
fastcgi_split_path_info ^(.+\.php)(/.+)$; | ||
# Pass this through to the PHP image running in this pod on port 9000 (you must reference the "php" service exposed by docker-compose.yml) | ||
fastcgi_pass php:9000; | ||
fastcgi_index index.php; | ||
include fastcgi_params; | ||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
fastcgi_param PATH_INFO $fastcgi_path_info; | ||
fastcgi_hide_header X-Powered-By; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM nginx:alpine | ||
|
||
WORKDIR /usr/share/nginx/html | ||
|
||
# Remove the default content from the Nginx default web root | ||
RUN rm -rf /usr/share/nginx/html/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM php:8.4-fpm | ||
|
||
WORKDIR /app | ||
|
||
# Install dependencies and extensions | ||
RUN apt-get update && apt-get install -y git libxml2-dev libpq-dev libzip-dev unzip | ||
RUN docker-php-ext-install dom intl opcache zip | ||
|
||
# Install Xdebug via PECL | ||
RUN pecl install xdebug && docker-php-ext-enable xdebug | ||
|
||
# Install Composer | ||
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer | ||
|
||
CMD ["php-fpm", "-y", "/usr/local/etc/php-fpm.conf", "-R"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[Xdebug] | ||
zend_extension=xdebug.so | ||
xdebug.mode=debug | ||
xdebug.start_with_request=yes | ||
xdebug.client_host=host.docker.internal | ||
xdebug.client_port=9004 | ||
xdebug.log=/tmp/xdebug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Health\Api\Controllers; | ||
|
||
use Aphiria\Api\Controllers\Controller; | ||
use Aphiria\Net\Http\HttpException; | ||
use Aphiria\Net\Http\IResponse; | ||
use Aphiria\Routing\Attributes\Get; | ||
|
||
class HealthController extends Controller | ||
{ | ||
/** | ||
* Checks the health of the API | ||
* | ||
* @return IResponse The OK response | ||
* @throws HttpException Thrown if the request could not be negotiated | ||
*/ | ||
#[Get('/health')] | ||
public function checkHealth(): IResponse | ||
{ | ||
return $this->ok(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Integration\Health; | ||
|
||
use Aphiria\Net\Http\HttpStatusCode; | ||
use App\Tests\Integration\IntegrationTestCase; | ||
|
||
class HealthTest extends IntegrationTestCase | ||
{ | ||
public function testCheckingHealthReturnsOk(): void | ||
{ | ||
$this->assertStatusCodeEquals(HttpStatusCode::Ok, $this->get('/health')); | ||
} | ||
} |