diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b3a58a..483947d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,3 +42,32 @@ jobs: run: | composer global require php-coveralls/php-coveralls php-coveralls --coverage_clover=./.coverage/clover.xml --json_path=./coveralls-upload.json -v + docker-ci: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + include: + - php: '8.4' + stability: prefer-stable + name: Docker Compose ${{ matrix.php }} - ${{ matrix.stability }} + steps: + - name: Check Out Code + uses: actions/checkout@v4 + - name: Set Up Docker + uses: docker/setup-buildx-action@v2 + - name: Build Docker Images + run: docker compose build + - name: Start Docker Compose + run: docker compose up -d + - name: Install Dependencies + run: docker compose run --rm composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --ignore-platform-reqs + - name: Run Tests + run: docker compose run --rm composer phpunit + #- name: Run Linter + # run: docker compose run --rm composer phpcs-test + #- name: Run Psalm Static Analysis + # run: docker compose run --rm composer psalm -- --shepherd + - name: Stop Docker Compose + if: always() + run: docker compose down diff --git a/CHANGELOG.md b/CHANGELOG.md index d229659..b2f4c73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [v1.0.0-alpha6](https://github.com/aphiria/app/compare/v1.0.0-alpha5...v1.0.0-alpha6) (?) +## [v1.0.0-alpha7](https://github.com/aphiria/app/compare/v1.0.0-alpha6...v1.0.0-alpha7) (?) ### Added @@ -8,6 +8,16 @@ ### Changed +- Nothing + +## [v1.0.0-alpha6](https://github.com/aphiria/app/compare/v1.0.0-alpha5...v1.0.0-alpha6) (2024-12-03) + +### Added + +- Added support for running the skeleton app via Docker Compose ([#47](https://github.com/aphiria/app/pull/47)) + +### Changed + - Required PHP 8.4 ([#46](https://github.com/aphiria/app/pull/46)) - Updated to Symfony 7.0 ([#43](https://github.com/aphiria/app/pull/43)) diff --git a/README.md b/README.md index 5aaacce..df48857 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,24 @@ composer create-project aphiria/app --prefer-dist --stability dev ## Running Locally -You can run your app locally (defaults to http://localhost:8080): +You can run your app locally either directly via the built-in PHP web server or via Docker Compose. Both solutions result in your app being hosted at http://localhost:8080. -```php +### Built-In PHP Web Server + +``` php aphiria app:serve ``` +### Docker Compose Web Server + +This app comes bundled with a Docker Compose setup meant to ease local development. It is not meant for production, but can get you up and running quickly with an nginx web server running your application along with Xdebug for debugging. Simply run: + +``` +docker compose up -d --build app +``` + +To start debugging with Xdebug, configure your IDE to map your checked out Aphiria code to the /app directory within the php service created by Docker Compose. Ensure that your IDE is configured to listen to port 9004 for Xdebug connections. + ## Demo This app comes with a simple demo that can store, retrieve, and authenticate users from a local SQLite database. It uses Phinx to manage database migrations and seeding, which can be executed with the following commands, respectively: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c6aa4d7 --- /dev/null +++ b/docker-compose.yml @@ -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 diff --git a/infrastructure/docker/nginx.conf b/infrastructure/docker/nginx.conf new file mode 100644 index 0000000..c5673a1 --- /dev/null +++ b/infrastructure/docker/nginx.conf @@ -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; + } +} diff --git a/infrastructure/docker/nginx.dockerfile b/infrastructure/docker/nginx.dockerfile new file mode 100644 index 0000000..277d91b --- /dev/null +++ b/infrastructure/docker/nginx.dockerfile @@ -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/* diff --git a/infrastructure/docker/php.dockerfile b/infrastructure/docker/php.dockerfile new file mode 100644 index 0000000..e88eefb --- /dev/null +++ b/infrastructure/docker/php.dockerfile @@ -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"] diff --git a/infrastructure/docker/xdebug.ini b/infrastructure/docker/xdebug.ini new file mode 100644 index 0000000..aa6e9e6 --- /dev/null +++ b/infrastructure/docker/xdebug.ini @@ -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 diff --git a/src/Health/Api/Controllers/HealthController.php b/src/Health/Api/Controllers/HealthController.php new file mode 100644 index 0000000..a372c07 --- /dev/null +++ b/src/Health/Api/Controllers/HealthController.php @@ -0,0 +1,25 @@ +ok(); + } +} diff --git a/tests/Integration/Health/HealthTest.php b/tests/Integration/Health/HealthTest.php new file mode 100644 index 0000000..fe812d8 --- /dev/null +++ b/tests/Integration/Health/HealthTest.php @@ -0,0 +1,16 @@ +assertStatusCodeEquals(HttpStatusCode::Ok, $this->get('/health')); + } +}