From 9729f5f3aaba58b8e09c12e2b97c99eefeeace4c Mon Sep 17 00:00:00 2001 From: Pim Jansen Date: Sun, 10 Nov 2024 22:18:18 +0100 Subject: [PATCH] Docker integration for local dev and fixed CI stuff --- .docker/www.conf | 25 +++++++++++++++ .gitignore | 6 ++-- Dockerfile | 39 +++++++++++++++++++++++ Makefile | 42 +++++++++++++++++++++++++ compose.yml | 25 +++++++++++++++ composer.json | 4 +-- phpunit.xml | 9 +++--- src/AzureStorageBlobServiceProvider.php | 2 +- tests/AzureStorageBlobAdapterTest.php | 21 +++++++++++++ 9 files changed, 163 insertions(+), 10 deletions(-) create mode 100644 .docker/www.conf create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 compose.yml diff --git a/.docker/www.conf b/.docker/www.conf new file mode 100644 index 0000000..d6449ba --- /dev/null +++ b/.docker/www.conf @@ -0,0 +1,25 @@ +[global] +; pid = /var/run/php-fpm.pid +error_log = /proc/self/fd/2 +log_level = notice +daemonize = no +; https://github.com/docker-library/php/pull/725#issuecomment-443540114 +log_limit = 8192 + +[www] +user = azure-oss +group = azure-oss + +listen = 127.0.0.1:9000 +catch_workers_output = yes +decorate_workers_output = no + +; Allow access to the environment variables that were passed on to Docker +clear_env = no + +; Process manager +pm = ondemand +pm.max_children = 5 +pm.process_idle_timeout = 10s +pm.max_requests = 500 +pm.status_path = /status diff --git a/.gitignore b/.gitignore index 0b779ae..b0d3f58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /vendor/ -composer.lock -.idea -.phpunit.cache \ No newline at end of file +/composer.lock +/.idea +/.build \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..37d57f0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +FROM php:8.1-fpm-buster + +# Install Composer +COPY --from=composer:2 /usr/bin/composer /usr/bin/composer + +# Install PHP package installer +COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ + +# Install packages +RUN apt update && apt install -y zip curl fcgiwrap && \ + chmod uga+x /usr/local/bin/install-php-extensions && \ + install-php-extensions curl && \ + mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" + +ENV USER=azure-oss +ENV UID=10000 +ENV GID=10001 + +RUN addgroup \ + --gid $GID \ + --system $USER \ + && adduser \ + --uid $UID \ + --disabled-password \ + --gecos "" \ + --ingroup $USER \ + $USER \ + && mkdir -p /app \ + && chown -R $UID:$GID /app + +# Add configuration files for PHP and PHPFPM +COPY ./.docker/www.conf /usr/local/etc/php-fpm.d/ + +ARG UID=${UID:-10000} +ARG GID=${GID:-10001} +ARG USER=${USER:-azure-oss} +RUN usermod -u $UID $USER && groupmod -g $GID $USER + +WORKDIR /app diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4aad3c0 --- /dev/null +++ b/Makefile @@ -0,0 +1,42 @@ +.PHONY: build +build: cs static test install ## Runs cs, static, and test targets + +# https://www.gnu.org/software/make/manual/html_node/Force-Targets.html +always: + +.PHONY: help +help: + @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: install +install: ## Install depedencies + docker compose run phpfpm rm -rf composer.lock + docker compose run phpfpm composer install + +.PHONY: cs +cs: ## Fixes coding standard issues with laravel/pint + docker compose run phpfpm vendor/bin/pint --repair + +.PHONY: coverage +coverage: ## Collects coverage with phpunit + docker compose run phpfpm vendor/bin/phpunit --coverage-text --coverage-clover=.build/logs/clover.xml + +.PHONY: test +test: ## Runs tests with phpunit + docker compose run -e AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://azurite:10000/devstoreaccount1;QueueEndpoint=http://azurite:10001/devstoreaccount1;TableEndpoint=http://azurite:10002/devstoreaccount1;" phpfpm vendor/bin/phpunit + +.PHONY: static +static: ## Runs static analyzers + docker compose run phpfpm vendor/bin/phpstan --memory-limit=2G + +.PHONY: baseline +baseline: ## Generate baseline files + docker compose run phpfpm vendor/bin/phpstan --memory-limit=2G --generate-baseline + +.PHONY: clean +clean: ## Cleans up build and vendor files + rm -rf vendor composer.lock .build + +.PHONY: bc +bc: ## Check for breaking changes since last release + docker run --env GITHUB_REPOSITORY="Azure-OSS/azure-storage-php-adapter-laravel" -u $(shell id -u) -v $(shell pwd):/app nyholm/roave-bc-check-ga diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..d0be7e9 --- /dev/null +++ b/compose.yml @@ -0,0 +1,25 @@ +services: + phpfpm: + build: + context: . + args: + UID: ${USER_ID:-1000} + GID: ${GROUP_ID:-1000} + user: "${UID:-1000}:${GID:-1000}" + links: + - "azurite" + volumes: + - .:/app + + azurite: + image: mcr.microsoft.com/azure-storage/azurite + ports: + - 10000:10000 + - 10001:10001 + - 10002:10002 + volumes: + - azurite:/data + +volumes: + azurite: + driver: local diff --git a/composer.json b/composer.json index 6748039..3b4dd53 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ }, "autoload-dev": { "psr-4": { - "AzureOss\\LaravelAzureStorageBlob\\Tests": "tests/" + "AzureOss\\LaravelAzureStorageBlob\\Tests\\": "tests/" } }, "authors": [ @@ -27,7 +27,7 @@ }, "require-dev": { "laravel/pint": "^1.17", - "orchestra/testbench": "^9.2", + "orchestra/testbench": "^8.27", "phpstan/phpstan": "^1.11", "phpstan/phpstan-deprecation-rules": "^1.2", "phpstan/phpstan-strict-rules": "^1.6" diff --git a/phpunit.xml b/phpunit.xml index e9e24b5..9d5062b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,12 +2,13 @@ + failOnWarning="true" + displayDetailsOnTestsThatTriggerWarnings="true"> @@ -19,7 +20,7 @@ - + src diff --git a/src/AzureStorageBlobServiceProvider.php b/src/AzureStorageBlobServiceProvider.php index b44fcb1..25d4d01 100644 --- a/src/AzureStorageBlobServiceProvider.php +++ b/src/AzureStorageBlobServiceProvider.php @@ -26,7 +26,7 @@ public function boot(): void if (isset($config['prefix']) && ! is_string($config['prefix'])) { throw new \InvalidArgumentException('The [prefix] must be a string in the disk configuration.'); } - + if (isset($config['root']) && ! is_string($config['root'])) { throw new \InvalidArgumentException('The [root] must be a string in the disk configuration.'); } diff --git a/tests/AzureStorageBlobAdapterTest.php b/tests/AzureStorageBlobAdapterTest.php index 230a889..785f796 100644 --- a/tests/AzureStorageBlobAdapterTest.php +++ b/tests/AzureStorageBlobAdapterTest.php @@ -4,6 +4,8 @@ use AzureOss\LaravelAzureStorageBlob\AzureStorageBlobAdapter; use AzureOss\LaravelAzureStorageBlob\AzureStorageBlobServiceProvider; +use AzureOss\Storage\Blob\BlobContainerClient; +use AzureOss\Storage\Blob\BlobServiceClient; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Storage; use Orchestra\Testbench\TestCase; @@ -25,6 +27,25 @@ protected function getEnvironmentSetUp($app): void ]); } + private static function createContainerClient(): BlobContainerClient + { + $connectionString = getenv('AZURE_STORAGE_CONNECTION_STRING'); + + if (empty($connectionString)) { + self::markTestSkipped('AZURE_STORAGE_CONNECTION_STRING is not provided.'); + } + + return BlobServiceClient::fromConnectionString($connectionString)->getContainerClient( + getenv('AZURE_STORAGE_CONTAINER') + ); + } + + public static function setUpBeforeClass(): void + { + self::createContainerClient()->deleteIfExists(); + self::createContainerClient()->create(); + } + #[Test] public function it_resolves_from_manager(): void {