diff --git a/.circleci/config.yml b/.circleci/config.yml index 3e8143d1..97062be4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -118,7 +118,11 @@ jobs: # deploy gcloud app deploy app-<< parameters.serviceName >>.yaml --version ${CIRCLE_BUILD_NUM} gcloud app deploy cron.yaml dispatch.yaml --version ${CIRCLE_BUILD_NUM} - + - run: | + # deploy to google run too + gcloud run deploy dropapp-test --source . --project ${GOOGLE_PROJECT_ID} \ + --add-cloudsql-instances=${<< parameters.envVariablePrefix >>DBNAME} \ + --set-env-vars GOOGLE_CLOUD_PROJECT=${GOOGLE_PROJECT_ID} create-sentry-release: docker: - image: circleci/node:4.8.2 diff --git a/.docker/.gitkeep b/.docker/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/.docker/php/Dockerfile b/.docker/php/Dockerfile deleted file mode 100644 index 3cbc32be..00000000 --- a/.docker/php/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM php:7.4.25-apache -# enable mod_rewrite -RUN a2enmod rewrite -# install needed libraries -RUN apt-get update \ - && apt-get -y --no-install-recommends install libfontconfig1 libxrender1 libxext6 zlib1g-dev libpng-dev libfreetype6-dev libjpeg62-turbo-dev \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* -# PHP extensions -RUN docker-php-ext-install pdo_mysql exif gd -# Enable xdebug for debugging & profiling -RUN pecl install xdebug && docker-php-ext-enable xdebug gd \ No newline at end of file diff --git a/.docker/php/dropapp.conf b/.docker/php/dropapp.conf deleted file mode 100644 index 85a40e5f..00000000 --- a/.docker/php/dropapp.conf +++ /dev/null @@ -1,25 +0,0 @@ - - ServerAdmin webmaster@localhost - DocumentRoot /var/www/html - ErrorLog ${APACHE_LOG_DIR}/error.log - CustomLog ${APACHE_LOG_DIR}/access.log combined - - # Prevents browsers from receiving a 400 error when sending Auth0 cookies - LimitRequestFieldSize 12392 - - - Options +FollowSymLinks -MultiViews - - # Don't look for .htaccess files, etc. - AllowOverride None - Order allow,deny - allow from all - - RewriteEngine On - - RewriteCond %{REQUEST_URI} !^/assets - RewriteCond %{REQUEST_URI} !^/uploads - RewriteCond %{REQUEST_URI} !^/gcloud-entry.php - RewriteRule ^(.*)$ /gcloud-entry.php/$1 [L,QSA] - - \ No newline at end of file diff --git a/.gcloudignore b/.gcloudignore index 2b357a61..7280e813 100644 --- a/.gcloudignore +++ b/.gcloudignore @@ -18,5 +18,4 @@ # other folders to ignore .docker phinx.yml -docker-compose.yml -build.php +docker-compose.yml \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 97508461..f8250bab 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -6,7 +6,7 @@ "recommendations": [ "xdebug.php-debug", "bmewburn.vscode-intelephense-client", - "fterrag.vscode-php-cs-fixer" + "junstyle.php-cs-fixer" ], // List of extensions recommended by VS Code that should not be recommended for users of this workspace. "unwantedRecommendations": [ diff --git a/.vscode/launch.json b/.vscode/launch.json index 667ffd76..06c4522a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,14 +4,14 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - { "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9003, "pathMappings": { - "/var/www/html": "${workspaceFolder}"}, + "/var/www/html": "${workspaceFolder}" + }, "log": true }, { diff --git a/.vscode/settings.json b/.vscode/settings.json index 4798d260..107eaefa 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { "[php]": { "editor.formatOnSave": true, - "editor.defaultFormatter": "fterrag.vscode-php-cs-fixer" + "editor.defaultFormatter": "junstyle.php-cs-fixer" }, "php-cs-fixer.rules": "@PhpCsFixer", "intelephense.format.enable": false diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..c5ab8b59 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,96 @@ +FROM php:7.4.25-apache AS base +WORKDIR /var/www/html + +# install needed libraries +RUN apt-get update \ + && apt-get -y --no-install-recommends install libfontconfig1 libxrender1 libxext6 zlib1g-dev libpng-dev libfreetype6-dev libjpeg62-turbo-dev \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN a2enmod rewrite + +RUN docker-php-ext-install \ + gd \ + pdo_mysql \ + exif + +# op cache +RUN docker-php-ext-install -j "$(nproc)" opcache + +RUN set -ex; \ + { \ + echo "; Cloud Run enforces memory & timeouts"; \ + echo "memory_limit = -1"; \ + echo "max_execution_time = 0"; \ + echo "; File upload at Cloud Run network limit"; \ + echo "upload_max_filesize = 32M"; \ + echo "post_max_size = 32M"; \ + echo "; Configure Opcache for Containers"; \ + echo "opcache.enable = On"; \ + echo "opcache.validate_timestamps = Off"; \ + echo "; Configure Opcache Memory (Application-specific)"; \ + echo "opcache.memory_consumption = 32"; \ + } > "$PHP_INI_DIR/conf.d/cloud-run.ini" + +RUN pecl install opencensus-alpha + +# Use the PORT environment variable in Apache configuration files. +# https://cloud.google.com/run/docs/reference/container-contract#port +RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf + +FROM base AS debug + +# RUN enable-xdebug in PHP 8 env +RUN pecl install xdebug && docker-php-ext-enable xdebug +# Configure PHP for development. +# https://github.com/docker-library/docs/blob/master/php/README.md#configuration +RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" + +FROM composer:2.1.11 AS build + +WORKDIR /var/www/html +# ensures we use docker cache and only rebuild composer +# if the dependencies have changed +COPY composer.json . +COPY composer.lock . +RUN composer install --no-dev --no-scripts --ignore-platform-reqs +COPY . . +RUN composer dump-autoload --optimize +RUN ls +RUN php build/build.php +RUN rm -r build/ + +FROM base AS final + +# Configure PHP for production. +# https://github.com/docker-library/docs/blob/master/php/README.md#configuration +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" + +COPY --from=build /var/www/html /var/www/html + + + +# docker pull myimage:latest-build | true +# docker pull myimage:latest | true + +# docker build . --target=build --cache-from=myimage:latest-build -t myimage:latest-build +# docker build . --cache-from=myimage:latest-build --cache-from=myimage:latest -t myimage:latest + +# docker push myimage:latest-build +# docker push myimage:latest + + +# use docker build from circleci and then push to gcloud run +# gcloud auth configure-docker +# docker tag dropapp europe-west1-docker.pkg.dev/dropapp-242214/cloudrun/dropapp +# docker push europe-west1-docker.pkg.dev/dropapp-242214/cloudrun/dropapp +# gcloud run deploy + +# gcloud config set builds/use_kaniko True +# docker build -t dropapp . && docker run -e PORT=8080 -p 81:8080 dropapp +# use cloud build as (a) we only have 1gb free data transfer from circleci +# and (b) cloud build offers 120 mins free per day + +# gcloud run deploy dropapp-test --source . --project dropapp-242214 --add-cloudsql-instances=dropapp-242214:europe-west1:boxtribute-production + +# docker run -it dropapp sh \ No newline at end of file diff --git a/README.md b/README.md index c94cfa85..addd764f 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,6 @@ If you are interested in being part of this project, write us at [jointheteam@bo docker-compose up - Alternatively, you can run using the PHP development server - - GOOGLE_CLOUD_PROJECT=xxx php -S localhost:8000 gcloud-entry.php - 5. To initialize the database for the first time, you should run: vendor/bin/phinx migrate -e development diff --git a/build.php b/build/build.php similarity index 100% rename from build.php rename to build/build.php diff --git a/composer.json b/composer.json index 276a4792..d3874b45 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ }, "require": { "robmorgan/phinx": "^0.12", + "symfony/yaml": "^5.0", "google/cloud-storage": "^1.12", "opencensus/opencensus-exporter-stackdriver": "^0.1.0", "smarty/smarty": "^4.3", diff --git a/composer.lock b/composer.lock index cf02f68d..4e93221e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "75994d7bafb809cbfceea414e8ccc02d", + "content-hash": "8f96a65145d6f7b51c39d68fc7017ab8", "packages": [ { "name": "auth0/auth0-php", @@ -863,16 +863,16 @@ }, { "name": "google/auth", - "version": "v1.23.1", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/googleapis/google-auth-library-php.git", - "reference": "cb43cb8ccde76ace65ec40130a9e9c2a15ecfe17" + "reference": "1f8cff5aa324700d041efd2df1a0855112a2e7ae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/cb43cb8ccde76ace65ec40130a9e9c2a15ecfe17", - "reference": "cb43cb8ccde76ace65ec40130a9e9c2a15ecfe17", + "url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/1f8cff5aa324700d041efd2df1a0855112a2e7ae", + "reference": "1f8cff5aa324700d041efd2df1a0855112a2e7ae", "shasum": "" }, "require": { @@ -887,8 +887,8 @@ "guzzlehttp/promises": "0.1.1|^1.3", "kelvinmo/simplejwt": "^0.2.5|^0.5.1", "phpseclib/phpseclib": "^2.0.31", - "phpspec/prophecy-phpunit": "^1.1", - "phpunit/phpunit": "^7.5||^8.5", + "phpspec/prophecy-phpunit": "^1.1||^2.0", + "phpunit/phpunit": "^7.5||^9.0.0", "sebastian/comparator": ">=1.2.3", "squizlabs/php_codesniffer": "^3.5" }, @@ -915,9 +915,9 @@ "support": { "docs": "https://googleapis.github.io/google-auth-library-php/main/", "issues": "https://github.com/googleapis/google-auth-library-php/issues", - "source": "https://github.com/googleapis/google-auth-library-php/tree/v1.23.1" + "source": "https://github.com/googleapis/google-auth-library-php/tree/v1.24.0" }, - "time": "2022-10-26T20:30:45+00:00" + "time": "2022-11-28T18:29:23+00:00" }, { "name": "google/cloud-core", @@ -4118,16 +4118,16 @@ }, { "name": "symfony/console", - "version": "v5.4.15", + "version": "v5.4.16", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "ea59bb0edfaf9f28d18d8791410ee0355f317669" + "reference": "8e9b9c8dfb33af6057c94e1b44846bee700dc5ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/ea59bb0edfaf9f28d18d8791410ee0355f317669", - "reference": "ea59bb0edfaf9f28d18d8791410ee0355f317669", + "url": "https://api.github.com/repos/symfony/console/zipball/8e9b9c8dfb33af6057c94e1b44846bee700dc5ef", + "reference": "8e9b9c8dfb33af6057c94e1b44846bee700dc5ef", "shasum": "" }, "require": { @@ -4197,7 +4197,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.15" + "source": "https://github.com/symfony/console/tree/v5.4.16" }, "funding": [ { @@ -4213,7 +4213,7 @@ "type": "tidelift" } ], - "time": "2022-10-26T21:41:52+00:00" + "time": "2022-11-25T14:09:27+00:00" }, { "name": "symfony/deprecation-contracts", @@ -5132,6 +5132,81 @@ } ], "time": "2022-10-05T15:16:54+00:00" + }, + { + "name": "symfony/yaml", + "version": "v5.4.16", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "ebd37c71f62d5ec5f6e27de3e06fee492d4c6298" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/ebd37c71f62d5ec5f6e27de3e06fee492d4c6298", + "reference": "ebd37c71f62d5ec5f6e27de3e06fee492d4c6298", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/polyfill-ctype": "^1.8" + }, + "conflict": { + "symfony/console": "<5.3" + }, + "require-dev": { + "symfony/console": "^5.3|^6.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, + "bin": [ + "Resources/bin/yaml-lint" + ], + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Loads and dumps YAML files", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/yaml/tree/v5.4.16" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-25T16:04:03+00:00" } ], "packages-dev": [ diff --git a/docker-compose.yml b/docker-compose.yml index f5eff256..2da876fe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.1' +version: '3.4' services: db_mysql: @@ -13,20 +13,20 @@ services: ports: - "9906:3306" web: - build: .docker/php + build: + context: . + target: debug depends_on: - db_mysql volumes: - .:/var/www/html/ - - ./.docker/php/dropapp.conf:/etc/apache2/sites-available/000-default.conf - ./.docker/php/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini - ./.docker/php/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini ports: - "8100:80" environment: - # WARNING: you do *not* want these environment variables set - # in a production environment, as they enable remote - # debugging + PORT: 80 + DISABLE_GCLOUD: "true" GOOGLE_CLOUD_PROJECT: DUMMY_ID stdin_open: true tty: true diff --git a/gcloud-entry.php b/gcloud-entry.php index 2301c01c..916edfde 100644 --- a/gcloud-entry.php +++ b/gcloud-entry.php @@ -2,9 +2,6 @@ define('LOADED_VIA_SINGLE_ENTRY_POINT', true); -// config for GCloud error reporting taken from https://github.com/GoogleCloudPlatform/php-docs-samples/tree/6609166f71b1049f45360480963c2327b00b7959/appengine/standard/errorreporting -require_once __DIR__.'/vendor/google/cloud-error-reporting/src/prepend.php'; - require_once 'vendor/autoload.php'; // load configuration file require_once 'library/config.php'; @@ -22,6 +19,8 @@ // The GAE environment requires a single entry point, so we're // doing basic routing from here +// Cloud Run does not, but keeping for consistency for now + use OpenCensus\Trace\Tracer; // permanent redirect for old market.drapenihavet.no url diff --git a/library/gcloud.php b/library/gcloud.php index d4c39214..4e1a8766 100644 --- a/library/gcloud.php +++ b/library/gcloud.php @@ -37,13 +37,15 @@ function registerGoogleCloudServices($projectId) $settings['upload_dir'] = "gs://{$projectId}.appspot.com/{$hostName}/uploads"; // configure session storage - $datastore = new Google\Cloud\Datastore\DatastoreClient(); - ini_set('session.save_path', "sessions-{$projectId}-{$hostName}"); - session_set_save_handler(new Google\Cloud\Datastore\DatastoreSessionHandler($datastore), true); + if (!getenv('DISABLE_GCLOUD')) { + ini_set('session.save_path', "sessions-{$projectId}-{$hostName}"); + $datastore = new Google\Cloud\Datastore\DatastoreClient(); + session_set_save_handler(new Google\Cloud\Datastore\DatastoreSessionHandler($datastore), true); + } } $googleProjectId = getenv('GOOGLE_CLOUD_PROJECT'); if (!$googleProjectId) { - throw new Exception("No GOOGLE_CLOUD_PROJECT set"); + throw new Exception('No GOOGLE_CLOUD_PROJECT set'); } -registerGoogleCloudServices($googleProjectId); \ No newline at end of file +registerGoogleCloudServices($googleProjectId); diff --git a/php.ini b/php.ini index 0edd6364..e8e47c55 100644 --- a/php.ini +++ b/php.ini @@ -1,9 +1,7 @@ short_open_tag = On -; required for smarty templates in google cloud -allow_url_include = "1" ; unfortunately it seems this has to be hard coded for now ; as the documented #default# shortcut doesn't work google_app_engine.allow_include_gs_buckets = "dropapp-242214.appspot.com" -; this configuration for Google cloud error reporting did not work anymore and we moved it now to gcloud-entry.php -; auto_prepend_file=/vendor/google/cloud-error-reporting/src/prepend.php +; Google cloud error reporting +auto_prepend_file=vendor/google/cloud-error-reporting/src/prepend.php extension=opencensus.so \ No newline at end of file