From f9f38bfc84d686f0e3770a77f51d2a26076b4bf9 Mon Sep 17 00:00:00 2001 From: Fabio Cicerchia Date: Wed, 9 Jun 2021 19:49:22 +0200 Subject: [PATCH] fixed dockerfile image for php in order to install correctly the dependencies with composer + updated parameters for cloudformation --- .dockerignore | 1 - src/Contributors/Model/Contributor.php | 7 +++++-- sys/cloudformation/parameters.prod.json | 6 +++--- sys/docker/alpine-phpfpm/Dockerfile | 2 +- sys/docker/alpine-phpfpm/start.sh | 6 +++++- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.dockerignore b/.dockerignore index 7b836e74..e7433fb3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ -.env *.md .git node_modules/ diff --git a/src/Contributors/Model/Contributor.php b/src/Contributors/Model/Contributor.php index b4e10607..23572756 100644 --- a/src/Contributors/Model/Contributor.php +++ b/src/Contributors/Model/Contributor.php @@ -6,7 +6,7 @@ final class Contributor implements \Stringable { private const DEFAULT_IMG_SIZE = 160; - private function __construct(private string $username, private string $profileUrl, private string $profileImg, private int $size = self::DEFAULT_IMG_SIZE) + private function __construct(private string $username, private string $profileUrl, private string $profileImg, private ?int $size = null) { } @@ -34,8 +34,11 @@ private function getUrlSeparator(string $url): string public function getProfileImg(): string { + // Very annoying bug happening only on prod, triggering the following error: + // Uncaught PHP Exception Error: "Typed property App\\Contributors\\Model\\Contributor::$size must not be accessed before initialization" + $size = empty($this->size) ? self::DEFAULT_IMG_SIZE : $this->size; $sep = $this->getUrlSeparator($this->profileImg); - $qs = \http_build_query(['s' => $this->size]); + $qs = \http_build_query(['s' => $size]); return $this->profileImg.$sep.$qs; } diff --git a/sys/cloudformation/parameters.prod.json b/sys/cloudformation/parameters.prod.json index e2a5129c..21ef1cb8 100644 --- a/sys/cloudformation/parameters.prod.json +++ b/sys/cloudformation/parameters.prod.json @@ -1,8 +1,8 @@ [ {"ParameterKey": "ELBCertificateArn", "ParameterValue": ""}, - {"ParameterKey": "EcrImageTagNginx", "ParameterValue": "1617796334"}, - {"ParameterKey": "EcrImageTagPhp", "ParameterValue": "1617796334"}, - {"ParameterKey": "EcrImageTagPhpCanary", "ParameterValue": "1617796334"}, + {"ParameterKey": "EcrImageTagNginx", "ParameterValue": "1623402500"}, + {"ParameterKey": "EcrImageTagPhp", "ParameterValue": "1623402500"}, + {"ParameterKey": "EcrImageTagPhpCanary", "ParameterValue": "1623402500"}, {"ParameterKey": "Environment", "ParameterValue": "prod"}, {"ParameterKey": "ExecRoleArn", "ParameterValue": ""}, {"ParameterKey": "Subnets", "ParameterValue": ""}, diff --git a/sys/docker/alpine-phpfpm/Dockerfile b/sys/docker/alpine-phpfpm/Dockerfile index d2b6fa31..9fdeb396 100644 --- a/sys/docker/alpine-phpfpm/Dockerfile +++ b/sys/docker/alpine-phpfpm/Dockerfile @@ -54,7 +54,7 @@ ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer -RUN /usr/local/bin/composer install --no-plugins --no-scripts --optimize-autoloader --no-ansi --no-interaction --no-progress --ignore-platform-reqs \ +RUN /usr/local/bin/composer install --optimize-autoloader --no-ansi --no-interaction --no-progress \ && apk del .builddeps \ && php-fpm -t \ && php-fpm -tt diff --git a/sys/docker/alpine-phpfpm/start.sh b/sys/docker/alpine-phpfpm/start.sh index 2e1e9343..9b7b47ec 100755 --- a/sys/docker/alpine-phpfpm/start.sh +++ b/sys/docker/alpine-phpfpm/start.sh @@ -1,12 +1,16 @@ #!/bin/sh if [ "$ENABLE_CW" = "1" ]; then + echo "Enabling CloudWatch Agent" /opt/aws/amazon-cloudwatch-agent/bin/start-amazon-cloudwatch-agent fi if [ "$APP_ENV" = "prod" ]; then + echo "Dumping .env for $APP_ENV" cd /application - /usr/local/bin/composer dump-env $APP_ENV + printenv | egrep $(printf "%s" "$(egrep -v "^#|^$" .env | sed "s/=.*//")" | tr "\n" "|") > .env.new && mv .env.new .env + echo "COMPOSER_ALLOW_SUPERUSER=1 /usr/local/bin/composer dump-env $APP_ENV" + COMPOSER_ALLOW_SUPERUSER=1 /usr/local/bin/composer dump-env $APP_ENV fi set -e