Skip to content

Commit

Permalink
[CI] Update docker prod image
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed May 23, 2023
1 parent 4d5bbc7 commit 7067eb2
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 33 deletions.
48 changes: 37 additions & 11 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
*.md
.git
.gitignore
**/*.log
**/*.md
**/*.php~
**/*.dist.php
**/*.dist
**/*.cache
**/._*
**/.dockerignore
**/.DS_Store
**/.git/
**/.gitattributes
**/.gitignore
**/.gitmodules
**/docker-compose.*.yaml
**/docker-compose.*.yml
**/docker-compose.yaml
**/docker-compose.yml
**/Dockerfile
**/Thumbs.db
.github/
docs/
public/bundles/
tests/
var/
vendor/
.editorconfig
.env.*.local
.env.dev
.env.local
.env.local.php
.env.test
.idea
.tmp
app/
docker-dev.md5
.php_cs.*
docker-compose.*
supervisord.*
behat.yml.dist
features
Makefile
dump
docs
node_modules
package.json
phpunit.xml.dist
tests
var
vendor
scripts
webpack.*.js
yarn.lock
src/DataFixtures
gcloud-service-key.json
assets
front
docker-dev.lock
tailwind.config*.js
postcss.config.js
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
/npm-debug.log
/phpunit.xml
/.phpunit.result.cache
/supervisord.log
/supervisord.pid
/yarn-error.log
/.php_cs
/.docker-dev.md5
Expand Down
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FROM node:${NODE_VERSION}-alpine AS node
RUN apk add --no-cache git
WORKDIR /srv/app

FROM caddy:${CADDY_VERSION} AS caddy
FROM caddy:${CADDY_VERSION}-alpine AS caddy

FROM mlocati/php-extension-installer:2 AS php_extension_installer

Expand All @@ -21,7 +21,7 @@ ENV APP_ENV=prod
WORKDIR /srv/app

# php extensions installer: https://github.com/mlocati/docker-php-extension-installer
COPY --from=php_extension_installer --link /usr/bin/install-php-extensions /usr/local/bin/
COPY --link --from=php_extension_installer /usr/bin/install-php-extensions /usr/local/bin/

# persistent / runtime deps
RUN apk add --no-cache \
Expand Down Expand Up @@ -58,7 +58,7 @@ RUN mkdir -p /var/run/php
COPY --link docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck

HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]
HEALTHCHECK --interval=30s --timeout=3s --retries=3 CMD ["docker-healthcheck"]

COPY --link docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
Expand All @@ -67,7 +67,7 @@ RUN chmod +x /usr/local/bin/docker-entrypoint
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV PATH="${PATH}:/root/.composer/vendor/bin"

COPY --from=composer/composer:2-bin --link /composer /usr/bin/composer
COPY --link --from=composer/composer:2-bin /composer /usr/bin/composer

COPY --link . .

Expand All @@ -78,11 +78,12 @@ RUN test -z "$BUILD_DEV" && ( \
composer dump-autoload --classmap-authoritative --no-dev; \
composer dump-env prod; \
composer run-script --no-dev post-install-cmd; \
rm -rf /root/.composer; \
chmod +x bin/console; sync \
) || :

COPY --from=caddy /usr/bin/caddy /usr/bin/caddy
COPY docker/caddy/Caddyfile /etc/caddy/Caddyfile
COPY --link --from=caddy /usr/bin/caddy /usr/bin/caddy
COPY --link docker/caddy/Caddyfile /etc/caddy/Caddyfile

EXPOSE 80

Expand Down
4 changes: 3 additions & 1 deletion docker/caddy/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
auto_https off
}

:80
:80

{$CADDY_EXTRA_CONFIG}

log

route {
respond /healthcheck 200

root * /srv/app/public
php_fastcgi unix//var/run/php/php-fpm.sock
encode zstd gzip
Expand Down
6 changes: 6 additions & 0 deletions docker/php/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ if [ "${1#-}" != "$1" ]; then
fi

if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
if [ "$APP_ENV" = 'prod' ]; then
rm -rf var/cache/*
bin/console cache:clear --env=prod --no-warmup
bin/console cache:warmup --env=prod
fi

setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
fi
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/AdherentMandate/AbstractAdherentMandate.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ abstract class AbstractAdherentMandate implements AdherentMandateInterface
*/
public $provisional = false;

final public function __construct(
public function __construct(
Adherent $adherent,
?string $gender,
\DateTime $beginAt,
Expand Down
4 changes: 3 additions & 1 deletion src/Entity/AdherentMessage/AbstractAdherentMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
* @ApiFilter(OrderFilter::class, properties={"createdAt"})
*
* @ValidAuthorRoleMessageType
*
* @phpstan-consistent-constructor
*/
abstract class AbstractAdherentMessage implements AdherentMessageInterface
{
Expand Down Expand Up @@ -240,7 +242,7 @@ abstract class AbstractAdherentMessage implements AdherentMessageInterface
*/
private $source = self::SOURCE_PLATFORM;

final public function __construct(UuidInterface $uuid = null, Adherent $author = null)
public function __construct(UuidInterface $uuid = null, Adherent $author = null)
{
$this->uuid = $uuid ?? Uuid::uuid4();
$this->author = $author;
Expand Down
15 changes: 5 additions & 10 deletions src/Entity/AdherentToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* An abstract temporary token for Adherent.
*
* @ORM\MappedSuperclass
*
* @phpstan-consistent-constructor
*/
abstract class AdherentToken implements AdherentExpirableTokenInterface
{
Expand Down Expand Up @@ -52,12 +54,8 @@ abstract class AdherentToken implements AdherentExpirableTokenInterface
*/
private $usedAt;

final private function __construct(
UuidInterface $adherentUuid,
\DateTime $createdAt,
\DateTime $expiration,
SHA1 $value
) {
public function __construct(UuidInterface $adherentUuid, \DateTime $createdAt, \DateTime $expiration, SHA1 $value)
{
if ($expiration <= new \DateTime('now')) {
throw new \InvalidArgumentException('Expiration date must be in the future.');
}
Expand All @@ -69,10 +67,7 @@ final private function __construct(
$this->expiredAt = $expiration;
}

/**
* @return static
*/
public static function generate(Adherent $adherent, string $lifetime = '+1 day'): AdherentExpirableTokenInterface
public static function generate(Adherent $adherent, string $lifetime = '+1 day'): static
{
$timestamp = new \DateTime('now');
$adherentUuid = clone $adherent->getUuid();
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/Report/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ abstract class Report
/**
* @throws \InvalidArgumentException
*/
final public function __construct(ReportableInterface $subject, Adherent $author, array $reasons, ?string $comment)
public function __construct(ReportableInterface $subject, Adherent $author, array $reasons, ?string $comment)
{
if (!\count($reasons)) {
throw new \InvalidArgumentException('At least one reason must be provided');
Expand Down

0 comments on commit 7067eb2

Please sign in to comment.