Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging Laravel into main #27

Merged
merged 33 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5ee0953
refactor: wipe out mezzio installation prior to installing Laravel
chuckadams Oct 17, 2024
b1897eb
refactor: install laravel
chuckadams Oct 17, 2024
95c2208
fix: push attic'd composer.json that didn't make it into commit
chuckadams Oct 17, 2024
f5e7347
Adding several improvements (#23)
sarah-savage Oct 18, 2024
ba9a7f9
Merge branch 'main' into chuck/dev/laravel
chuckadams Oct 18, 2024
b8161af
build: regenerate lockfile
chuckadams Oct 18, 2024
c26261c
fix(build): move migrations to require-dev so laravel doesnt choke on it
chuckadams Oct 18, 2024
b6f98ef
feat: add mailhog service
chuckadams Oct 18, 2024
a308344
chore: tweak sample config
chuckadams Oct 18, 2024
b557104
fix: port make targets around db and migrations
chuckadams Oct 18, 2024
a9d7075
temp: add phinx migrations to attic
chuckadams Oct 18, 2024
510312b
fix: fix make list target formatting
chuckadams Oct 18, 2024
19caf00
chore: port initial schema migration
chuckadams Oct 18, 2024
79e1d39
chore: roll in remaining migrations
chuckadams Oct 18, 2024
c52caec
chore: publish cors config
chuckadams Oct 18, 2024
a5e687e
temp: rm the rest of .ATTIC
chuckadams Oct 18, 2024
2489901
Minor changes to provide correct settings for dev enviornment (#24)
sarah-savage Oct 19, 2024
a7fed13
fix: add correct DB environment vars to .env.example
chuckadams Oct 19, 2024
edaea95
fix: api.aspirepress.local -> api.aspirecloud.local in docker-compose…
chuckadams Oct 19, 2024
6af1801
Merge remote-tracking branch 'origin/chuck/dev/laravel' into chuck/de…
chuckadams Oct 19, 2024
90d6d10
feat: add generate-key target to Makefile
chuckadams Oct 19, 2024
6194493
feat: add stub api routes file
chuckadams Oct 19, 2024
2abefdd
Adding quality tools and fixing coding style
sarah-savage Oct 19, 2024
6c9afaa
Updating running checks to build the CLI container and then the Makef…
sarah-savage Oct 19, 2024
6400fe8
Fixing a style issue detected
sarah-savage Oct 19, 2024
fad434e
Generating app key for tests
sarah-savage Oct 19, 2024
74315c3
Add Catch All handler (#25)
mzalewski Oct 19, 2024
5dafc6f
fix: rm catchall route in api.php
chuckadams Oct 19, 2024
d687b4a
style: fix style to make pint happy
chuckadams Oct 19, 2024
30357b7
Populating the .env file if it doesn't exist
sarah-savage Oct 19, 2024
d8892a8
fix: give phpstan proper args in check target
chuckadams Oct 19, 2024
3bf6cc6
fix: phpstan qa issues
chuckadams Oct 19, 2024
bef98d4
Merge remote-tracking branch 'origin/chuck/dev/laravel' into chuck/de…
chuckadams Oct 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[docker-compose.yml]
indent_size = 4
6 changes: 0 additions & 6 deletions .env.dist

This file was deleted.

71 changes: 71 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
APP_NAME=AspireCloud
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://api.aspirecloud.local

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER=file
# APP_MAINTENANCE_STORE=database

PHP_CLI_SERVER_WORKERS=4

BCRYPT_ROUNDS=12

LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=pgsql
DB_HOST=postgres
DB_PORT=5432
DB_DATABASE=aspirecloud
DB_USERNAME=postgres
DB_PASSWORD=password

# root credentials used for initial db creation, not used at runtime.
# production should never contain these values.
DB_ROOT_USERNAME=postgres
DB_ROOT_PASSWORD=password

SESSION_DRIVER=redis
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database

CACHE_STORE=redis
CACHE_PREFIX=

MEMCACHED_HOST=127.0.0.1

REDIS_CLIENT=phpredis
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=log
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="do-not-reply@aspirepress.org"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

VITE_APP_NAME="${APP_NAME}"
14 changes: 11 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Force LF only on files where CRLF is deadly; git defaults are fine for the rest.
*.bash text=auto eol=lf
*.sh text=auto eol=lf
* text=auto eol=lf

*.blade.php diff=html
*.css diff=css
*.html diff=html
*.md diff=markdown
*.php diff=php

/.github export-ignore
CHANGELOG.md export-ignore
.styleci.yml export-ignore
16 changes: 11 additions & 5 deletions .github/workflows/run-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ jobs:
- uses: actions/checkout@v4

- name: Build container
run: docker build --target dev -t aspirepress/aspirecloud-php -f ./docker/webapp/Dockerfile .
run: docker build --target dev -t aspirepress/aspirecloud-cli -f ./docker/webapp/Dockerfile .

- name: Install Composer dependencies
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-php sh -c "composer install"
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-cli sh -c "composer install"

- name: Create .env file
run: cp .env.example .env

- name: Create App Key
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-cli sh -c "./artisan key:generate"

- name: Run style checks
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-php sh -c "./vendor/bin/phpcs"
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-cli sh -c "./vendor/bin/pint --test"

- name: Run quality check
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-php sh -c "./vendor/bin/phpstan --memory-limit=1G analyse"
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-cli sh -c "./vendor/bin/phpstan --memory-limit=1G analyse"

- name: Run unit tests
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-php sh -c "./vendor/bin/phpunit --testsuite=unit"
run: docker run --rm -v $(pwd):/var/www/html aspirepress/aspirecloud-cli sh -c "./vendor/bin/pest"
33 changes: 21 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
/.phpcs-cache
/.phpunit.result.cache
/clover.xml
/coveralls-upload.json
/phpunit.xml
/vendor/
docker-compose.override.yml
/assets/output/*
/node_modules/
/logs/error.log
mix-manifest.json
*.sql
/.phpunit.cache
/node_modules
/public/build
/public/hot
/public/storage
/storage/*.key
/storage/pail
/vendor
.env
.env.backup
.env.production
.phpactor.json
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.fleet
/.idea
/.vscode
/.zed
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

65 changes: 31 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ ifneq (,$(wildcard ./.env))
endif

list:
@grep -E '^[a-zA-Z%_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@grep -E '^[a-zA-Z%_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | perl -ne '/^(?:.*?:)?(.*?):.*##(.*$$)/ and printf "\033[36m%-30s\033[0m %s\n", $$1, $$2'

init: down clean build network up install-composer reset-database devmode-enable ## Initial configuration tasks
init: check-env down clean build network up install-composer reset-database generate-key ## Initial configuration tasks

check-env:
@[ -f .env ] || { cp .env.example .env && bin/dcrun ./artisan key:generate; }

build: ## Builds the Docker containers
docker compose build
Expand All @@ -37,18 +40,18 @@ down: ## Stops the Docker containers
docker compose down

unit: ## Run unit tests
bin/dcrun vendor/bin/phpunit --testsuite=unit ${OPTS}
bin/dcrun vendor/bin/pest --testsuite=unit ${OPTS}

functional: ## Run functional tests
bin/dcrun vendor/bin/phpunit --testsuite=functional ${OPTS}
bin/dcrun vendor/bin/pest --testsuite=functional ${OPTS}

test: unit functional acceptance ## Run all tests
test: unit functional ## Run all tests

acceptance: ## Run acceptance tests
bin/dcrun vendor/bin/behat -vvv ${OPTS}

quality: ## Run all quality checks
bin/dcrun vendor/bin/phpstan ${OPTS}
bin/dcrun vendor/bin/phpstan --memory-limit=1G analyse ${OPTS}

quality-baseline: ## Run all static analysis checks with baseline
bin/dcrun vendor/bin/phpstan analyse -b baseline.neon $(PHPSTAN_XDEBUG) src tests
Expand All @@ -66,55 +69,49 @@ sh-%: ## Execute shell for the container where % is a service name (webapp, post
docker compose exec $* sh || docker compose run --rm $* sh

clear-cache: ## Clear cache
rm -f data/cache/config-cache.php public/build
bin/dcrun php artisan optimize:clear

check: cs-fix quality test ## Check all quality and test elements
check: cs quality test ## Check all quality and test elements

cs: ## Run code style checks
bin/dcrun vendor/bin/phpcs ${OPTS}

cs-fix: ## Fix code style issues
bin/dcrun vendor/bin/phpcbf ${OPTS} && vendor/bin/phpcs ${OPTS}
bin/dcrun vendor/bin/pint ${OPTS}

create-migration: ## Create a new database migration
bin/dcrun vendor/bin/phinx create ${OPTS} -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun php artisan make:migration

create-seed: ## Create a new database seed
bin/dcrun vendor/bin/phinx seed:create ${OPTS} -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun php artisan make:seed

migrate: ## Run database migrations
bin/dcrun vendor/bin/phinx migrate -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun php artisan migrate --force --no-interaction

migration-rollback: ## Rollback database migrations
bin/dcrun vendor/bin/phinx rollback -e development -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun php artisan migrate --force --no-interaction

seed: ## Run database seeds
bin/dcrun vendor/bin/phinx seed:run -c vendor/aspirepress/aspirecloud-migrations/phinx.php

devmode-enable: ## Enable the PHP development mode
bin/dcrun composer development-enable

devmode-disable: ## Disable the PHP development mode
bin/dcrun composer development-disable

_empty-database: # internal target to empty database
bin/dcrun vendor/bin/phinx migrate -c vendor/aspirepress/aspirecloud-migrations/phinx.php -t 0
bin/dcrun php artisan db:seed

migrate-testing: ## Run database migrations
bin/dcrun vendor/bin/phinx migrate -e testing -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun php artisan migrate --database=test --force --no-interaction

seed-testing: ## Run database seeds
bin/dcrun vendor/bin/phinx seed:run -e testing -c vendor/aspirepress/aspirecloud-migrations/phinx.php
bin/dcrun php artisan db:seed --database=test

generate-key: ## Generate APP_KEY environment var
bin/dcrun php artisan key:generate

drop-database:
bin/dcrun sh -c "export PGPASSWORD=${DB_ROOT_PASSWORD} && psql -U ${DB_ROOT_USERNAME} -h ${DB_HOST} -c 'drop database if exists ${DB_DATABASE}'"

_empty-testing-database: # internal target to empty database
bin/dcrun vendor/bin/phinx migrate -e testing -c vendor/aspirepress/aspirecloud-migrations/phinx.php -t 0
create-database:
bin/dcrun sh -c "export PGPASSWORD=${DB_ROOT_PASSWORD} && psql -U ${DB_ROOT_USERNAME} -h ${DB_HOST} -c 'create database ${DB_DATABASE} owner ${DB_USERNAME}'"

reset-database: _empty-database migrate seed ## Clean database, run migrations and seeds
reset-database: drop-database create-database migrate seed ## run migrations and seeds

reset-testing-database: _empty-testing-database migrate-testing seed-testing
reset-testing-database: migrate-testing seed-testing

run-pgsql: ## Runs Postgres on the command line using the .env file variables
bin/dcrun sh -c "export PGPASSWORD=${DB_PASS} && psql -U ${DB_USER} -h ${DB_HOST} -d ${DB_NAME}"
run-psql: ## Runs Postgres on the command line using the .env file variables
bin/dcrun sh -c "PGPASSWORD=${DB_PASSWORD} psql -U ${DB_USERNAME} -h ${DB_HOST} -p ${DB_PORT} -d ${DB_USERNAME}"

network: ## Create docker networks for app and traefik proxy (if they don't exist already)
bin/create-external-network.sh wp-services
Expand Down
69 changes: 69 additions & 0 deletions app/Http/Controllers/CatchAllController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Client\RequestException;
use Illuminate\Http\Client\Response as ClientResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;

class CatchAllController extends Controller
{
public function handle(Request $request): Response
{
$requestData = $request->all();
$ua = $request->header('User-Agent');
$path = $request->path();
$queryParams = $request->query();

// If path is root, return a 200 OK empty response
if ($path === '/') {
return response()->noContent(200);
}

try {
$response = Http::withHeaders([
'User-Agent' => $ua,
'Accept' => '*/*',
])->asForm()->send($request->getMethod(), 'https://api.wordpress.org/'.$path, [
'query' => $queryParams,
'form_params' => $requestData,
]);

} catch (RequestException $e) {
$statusCode = $e->response->status();

return response()->noContent($statusCode);
}

// Get content type and status code
$contentType = $response->header('Content-Type');
$statusCode = $response->status();
$content = $response->body();

// Log request and response in DB
$this->saveData($request, $response, $content);

// Forward response through
return response($content, $statusCode)->header('Content-Type', $contentType);
}

private function saveData(Request $request, ClientResponse $response, string $content): void
{
DB::table('request_data')->insert([
'id' => Str::uuid()->toString(),
'request_path' => $request->path(),
'request_query_params' => json_encode($request->query()),
'request_body' => json_encode($request->all()),
'request_headers' => json_encode($request->headers->all()),
'response_code' => $response->status(),
'response_body' => $content,
'response_headers' => json_encode($response->headers()),
'created_at' => Carbon::now(),
]);
}
}
8 changes: 8 additions & 0 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace App\Http\Controllers;

abstract class Controller
{
//
}
Loading