From bdbd631e72f7bc2c380596c8300c3757081cac9e Mon Sep 17 00:00:00 2001 From: Vincent Chalamon <407859+vincentchalamon@users.noreply.github.com> Date: Fri, 25 Aug 2023 21:58:03 +0200 Subject: [PATCH] fix: ci --- .github/workflows/ci.yml | 13 ++++---- api/src/DataFixtures/Factory/BookFactory.php | 31 +++++++++++++++----- docker-compose.prod.yml | 12 ++++++++ docker-compose.yml | 16 +++++----- 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59dc67867..26f52ed04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,12 +84,8 @@ jobs: env: PHP_DOCKER_IMAGE: eu.gcr.io/${{ secrets.GKE_PROJECT }}/php:latest APP_SECRET: "ba63418865d58089f7f070e0a437b6d16b1fb970" - CADDY_MERCURE_JWT_SECRET: "f8675b65055fc9f1ccdc21e425c00798633d5556" PWA_DOCKER_IMAGE: eu.gcr.io/${{ secrets.GKE_PROJECT }}/pwa:latest - NEXTAUTH_SECRET: "0efafa22ed0e5f4d1875777584eebeebf14068f1" CADDY_DOCKER_IMAGE: eu.gcr.io/${{ secrets.GKE_PROJECT }}/caddy:latest - POSTGRES_PASSWORD: "01c3b2511ddbff2838fa39cc3b823037e1627397" - KEYCLOAK_POSTGRES_PASSWORD: "b8ef720708474177fa169a5c3fec495e04660f44" steps: - name: Checkout @@ -113,13 +109,16 @@ jobs: *.cache-to=type=gha,scope=${{github.ref}}-e2e,mode=max - name: Start Services - run: docker compose up --wait --no-build + run: docker compose -f docker-compose.yml -f docker-compose.prod.yml up --wait --no-build - name: Debug Services if: failure() run: | - docker compose ps - docker compose logs + docker compose -f docker-compose.yml -f docker-compose.prod.yml ps + docker compose -f docker-compose.yml -f docker-compose.prod.yml logs + - + name: Load Fixtures + run: docker compose -f docker-compose.yml -f docker-compose.prod.yml run --rm --env APP_ENV=dev php bin/console doctrine:fixtures:load --no-interaction - name: Cache Playwright Binaries uses: actions/cache@v3 diff --git a/api/src/DataFixtures/Factory/BookFactory.php b/api/src/DataFixtures/Factory/BookFactory.php index 4f0453711..b5121e528 100644 --- a/api/src/DataFixtures/Factory/BookFactory.php +++ b/api/src/DataFixtures/Factory/BookFactory.php @@ -49,12 +49,16 @@ */ final class BookFactory extends ModelFactory { + private readonly array $data; + /** * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services */ - public function __construct(private readonly DecoderInterface $decoder) + public function __construct(readonly DecoderInterface $decoder) { parent::__construct(); + + $this->data = $decoder->decode(file_get_contents(__DIR__.'/../books.json'), 'json'); } /** @@ -62,13 +66,7 @@ public function __construct(private readonly DecoderInterface $decoder) */ protected function getDefaults(): array { - $data = $this->decoder->decode(file_get_contents(__DIR__.'/../books.json'), 'json'); - $datum = $data[array_rand($data)]; - return [ - 'book' => $datum['book'], - 'title' => $datum['title'], - 'author' => $datum['author'], 'condition' => self::faker()->randomElement(BookCondition::getCases()), ]; } @@ -79,7 +77,24 @@ protected function getDefaults(): array protected function initialize(): self { return $this - // ->afterInstantiate(function(Book $book): void {}) + ->afterInstantiate(function(Book $book): void { + if ($book->book && $book->title && $book->author) { + return; + } + + $book->book ??= $this->data[array_rand($this->data)]['book']; + + if ($book->title && $book->author) { + return; + } + + $datum = current(array_filter($this->data, static function (array $datum) use ($book) { + return $book->book === $datum['book']; + })); + + $book->title ??= $datum['title'] ?? self::faker()->title(); + $book->author ??= $datum['author'] ?? self::faker()->name(); + }) ; } diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index dda4329a1..147484f98 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -9,12 +9,15 @@ services: target: php_prod environment: APP_SECRET: ${APP_SECRET} + MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET} pwa: image: ${PWA_DOCKER_IMAGE} build: context: ./pwa target: prod + environment: + NEXTAUTH_SECRET: ${NEXTAUTH_SECRET} caddy: image: ${CADDY_DOCKER_IMAGE} @@ -33,6 +36,15 @@ services: } CADDY_CACHE: cache + database: + environment: + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + + keycloak-database: + environment: + POSTGRES_PASSWORD: ${KEYCLOAK_POSTGRES_PASSWORD} + keycloak: environment: KEYCLOAK_PRODUCTION: "true" + KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD} diff --git a/docker-compose.yml b/docker-compose.yml index 1e312d4ac..63a47c9a8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -69,10 +69,10 @@ services: database: image: postgres:${POSTGRES_VERSION:-15}-alpine environment: - - POSTGRES_DB=${POSTGRES_DB:-app} + POSTGRES_DB: ${POSTGRES_DB:-app} # You should definitely change the password in production - - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-!ChangeMe!} - - POSTGRES_USER=${POSTGRES_USER:-app} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!} + POSTGRES_USER: ${POSTGRES_USER:-app} volumes: - db_data:/var/lib/postgresql/data # you may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data! @@ -86,10 +86,10 @@ services: keycloak-database: image: postgres:${KEYCLOAK_POSTGRES_VERSION:-15}-alpine environment: - - POSTGRES_DB=${KEYCLOAK_POSTGRES_DB:-keycloak} + POSTGRES_DB: ${KEYCLOAK_POSTGRES_DB:-keycloak} # You should definitely change the password in production - - POSTGRES_PASSWORD=${KEYCLOAK_POSTGRES_PASSWORD:-!ChangeMe!} - - POSTGRES_USER=${KEYCLOAK_POSTGRES_USER:-keycloak} + POSTGRES_PASSWORD: ${KEYCLOAK_POSTGRES_PASSWORD:-!ChangeMe!} + POSTGRES_USER: ${KEYCLOAK_POSTGRES_USER:-keycloak} volumes: - keycloak_db_data:/var/lib/postgresql/data @@ -117,8 +117,8 @@ services: image: bitnami/keycloak-config-cli:5-debian-11 environment: KEYCLOAK_URL: http://caddy/oidc/ - KEYCLOAK_USER: ${KEYCLOAK_USER:-admin} - KEYCLOAK_PASSWORD: ${KEYCLOAK_PASSWORD:-!ChangeMe!} + KEYCLOAK_USER: ${KEYCLOAK_ADMIN_USER:-admin} + KEYCLOAK_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD:-!ChangeMe!} KEYCLOAK_AVAILABILITYCHECK_ENABLED: true KEYCLOAK_AVAILABILITYCHECK_TIMEOUT: 120s IMPORT_FILES_LOCATIONS: "/config/*"