Skip to content

Commit

Permalink
fix: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Sep 4, 2023
1 parent b0cf130 commit 9754fd4
Show file tree
Hide file tree
Showing 37 changed files with 689 additions and 204 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ jobs:
POSTGRES_PASSWORD: aae5bf316ef5fe87ad806c6a9240fff68bcfdaf7
KEYCLOAK_POSTGRES_PASSWORD: 26d7f630f1524eb210bbf496443f2038a9316e9e
KEYCLOAK_ADMIN_PASSWORD: 2f31e2fad93941b818449fd8d57fd019b6ce7fa5
KEYCLOAK_HTTPS_CERTIFICATE_FILE: ./helm/api-platform/keycloak/certs/tls.crt
KEYCLOAK_HTTPS_CERTIFICATE_KEY_FILE: ./helm/api-platform/keycloak/certs/tls.pem
# https://docs.docker.com/compose/environment-variables/envvars/
COMPOSE_FILE: docker-compose.yml:docker-compose.prod.yml
steps:
Expand Down Expand Up @@ -146,14 +148,10 @@ jobs:
working-directory: pwa
run: pnpm exec playwright install --with-deps
-
name: Run Playwright @read
name: Run Playwright
working-directory: pwa
run: pnpm exec playwright test --grep @read
-
name: Run Playwright @write
working-directory: pwa
# use 1 worker to prevent conflict between write scenarios
run: pnpm exec playwright test --grep @write --workers=1
# use 1 worker to prevent conflict between scenarios
run: pnpm exec playwright test --workers=1
-
uses: actions/upload-artifact@v3
if: failure()
Expand Down
32 changes: 16 additions & 16 deletions api/config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ api_platform:
scopes:
openid: (required) Indicates that the application intends to use OIDC to verify the user's identity

when@prod:
parameters:
# The api url that is called to invalidate cached resources
# Can't be set in .env file cause it's only available on prod env
env(SOUIN_API_URL): http://caddy/souin-api/souin

api_platform:
http_cache:
invalidation:
enabled: true
purger: 'api_platform.http_cache.purger.souin'
urls: ['%env(SOUIN_API_URL)%']
defaults:
cache_headers:
max_age: 0
shared_max_age: 3600
#when@prod:
# parameters:
# # The api url that is called to invalidate cached resources
# # Can't be set in .env file cause it's only available on prod env
# env(SOUIN_API_URL): http://caddy/souin-api
#
# api_platform:
# http_cache:
# invalidation:
# enabled: true
# purger: 'api_platform.http_cache.purger.souin'
# urls: ['%env(SOUIN_API_URL)%']
# defaults:
# cache_headers:
# max_age: 0
# shared_max_age: 3600

services:
app.filter.review.admin.search:
Expand Down
14 changes: 3 additions & 11 deletions api/src/DataFixtures/Story/DefaultStory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use App\DataFixtures\Factory\ReviewFactory;
use App\DataFixtures\Factory\UserFactory;
use App\Enum\BookCondition;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Zenstruck\Foundry\Story;

Expand All @@ -24,7 +23,7 @@ public function build(): void
// Create default book (must be created first to appear first in list)
$defaultBook = BookFactory::createOne([
'condition' => BookCondition::UsedCondition,
'book' => 'https://openlibrary.org/books/OL17267881W.json',
'book' => 'https://openlibrary.org/books/OL25840917M.json',
'title' => 'The Three-Body Problem',
'author' => 'Liu Cixin',
]);
Expand Down Expand Up @@ -75,13 +74,15 @@ public function build(): void
BookmarkFactory::createOne([
'book' => $defaultBook,
'user' => $defaultUser,
'bookmarkedAt' => new \DateTimeImmutable('-1 hour'),
]);

// Default user has bookmarked other books
foreach (array_rand($books, 30) as $key) {
BookmarkFactory::createOne([
'user' => $defaultUser,
'book' => $books[$key],
'bookmarkedAt' => \DateTimeImmutable::createFromMutable(BookmarkFactory::faker()->dateTime('-1 week')),
]);
}

Expand All @@ -93,13 +94,4 @@ public function build(): void
'roles' => ['ROLE_ADMIN'],
]);
}

private function getData(string $uri): array
{
return $this->decoder->decode($this->client->request(Request::METHOD_GET, $uri, [
'headers' => [
'Accept' => 'application/json',
],
])->getContent(), 'json');
}
}
2 changes: 1 addition & 1 deletion api/src/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Book
*/
#[ApiProperty(
types: ['https://schema.org/itemOffered', 'https://purl.org/dc/terms/BibliographicResource'],
example: 'https://openlibrary.org/books/OL17267881W.json'
example: 'https://openlibrary.org/books/OL25840917M.json'
)]
#[Assert\NotBlank(allowNull: false)]
#[Assert\Url(protocols: ['https'])]
Expand Down
1 change: 1 addition & 0 deletions api/src/Entity/Bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
#[ApiResource(
types: ['https://schema.org/BookmarkAction'],
order: ['bookmarkedAt' => 'DESC'],
operations: [
new GetCollection(),
new Delete(
Expand Down
6 changes: 3 additions & 3 deletions api/tests/Api/BookmarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testAsAUserICanGetACollectionOfMyBookmarksWithoutFilters(): void

public function testAsAnonymousICannotCreateABookmark(): void
{
$book = BookFactory::createOne(['book' => 'https://openlibrary.org/books/OL17267881W.json']);
$book = BookFactory::createOne(['book' => 'https://openlibrary.org/books/OL25840917M.json']);

$this->client->request('POST', '/bookmarks', [
'json' => [
Expand Down Expand Up @@ -123,7 +123,7 @@ public function testAsAUserICannotCreateABookmarkWithInvalidData(): void
*/
public function testAsAUserICanCreateABookmark(): void
{
$book = BookFactory::createOne(['book' => 'https://openlibrary.org/books/OL17267881W.json']);
$book = BookFactory::createOne(['book' => 'https://openlibrary.org/books/OL25840917M.json']);
$user = UserFactory::createOne();
self::getMercureHub()->reset();

Expand Down Expand Up @@ -164,7 +164,7 @@ public function testAsAUserICanCreateABookmark(): void

public function testAsAUserICannotCreateADuplicateBookmark(): void
{
$book = BookFactory::createOne(['book' => 'https://openlibrary.org/books/OL17267881W.json']);
$book = BookFactory::createOne(['book' => 'https://openlibrary.org/books/OL25840917M.json']);
$user = UserFactory::createOne();
BookmarkFactory::createOne(['book' => $book, 'user' => $user]);
self::getMercureHub()->reset();
Expand Down
4 changes: 2 additions & 2 deletions api/tests/Serializer/BookNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testItNormalizesData(): void
->method('normalize')
->with($expectedObject, null, [BookNormalizer::class => true])
->willReturn([
'book' => 'https://openlibrary.org/books/OL17267881W.json',
'book' => 'https://openlibrary.org/books/OL25840917M.json',
'title' => 'Foundation',
'author' => 'Liu Cixin',
'condition' => BookCondition::NewCondition->value,
Expand All @@ -82,7 +82,7 @@ public function testItNormalizesData(): void
]);

$this->assertEquals([
'book' => 'https://openlibrary.org/books/OL17267881W.json',
'book' => 'https://openlibrary.org/books/OL25840917M.json',
'title' => 'Foundation',
'author' => 'Liu Cixin',
'condition' => BookCondition::NewCondition->value,
Expand Down
4 changes: 2 additions & 2 deletions api/tests/State/Processor/BookPersistProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp(): void
$this->responseMock = $this->createMock(ResponseInterface::class);
$this->decoderMock = $this->createMock(DecoderInterface::class);
$this->objectMock = $this->createMock(Book::class);
$this->objectMock->book = 'https://openlibrary.org/books/OL17267881W.json';
$this->objectMock->book = 'https://openlibrary.org/books/OL25840917M.json';
$this->operationMock = $this->createMock(Operation::class);

$this->processor = new BookPersistProcessor(
Expand All @@ -56,7 +56,7 @@ public function testItUpdatesBookDataBeforeSaveAndSendMercureUpdates(): void
->method('request')
->withConsecutive(
[
Request::METHOD_GET, 'https://openlibrary.org/books/OL17267881W.json', [
Request::METHOD_GET, 'https://openlibrary.org/books/OL25840917M.json', [
'headers' => [
'Accept' => 'application/json',
],
Expand Down
24 changes: 15 additions & 9 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ services:
environment:
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
CADDY_GLOBAL_OPTIONS: |
order cache before rewrite
cache {
api {
souin
}
}
CADDY_CACHE: cache
# CADDY_GLOBAL_OPTIONS: |
# order cache before rewrite
# cache {
# api {
# souin
# }
# }
# CADDY_CACHE: cache

database:
environment:
Expand All @@ -47,5 +47,11 @@ services:
keycloak:
environment:
KEYCLOAK_PRODUCTION: "true"
KEYCLOAK_ENABLE_HTTPS: "false"
KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD}
KEYCLOAK_ENABLE_HTTPS: "true"
KEYCLOAK_HTTPS_USE_PEM: "true"
KEYCLOAK_HTTPS_CERTIFICATE_FILE: /opt/bitnami/keycloak/certs/tls.crt
KEYCLOAK_HTTPS_CERTIFICATE_KEY_FILE: /opt/bitnami/keycloak/certs/tls.key
volumes:
- ${KEYCLOAK_HTTPS_CERTIFICATE_FILE}:/opt/bitnami/keycloak/certs/tls.crt:ro
- ${KEYCLOAK_HTTPS_CERTIFICATE_KEY_FILE}:/opt/bitnami/keycloak/certs/tls.key:ro
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
retries: 3
start_period: 30s
test: ["CMD", "docker-healthcheck"]
environment: &php-env
environment:
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-15}
TRUSTED_PROXIES: ${TRUSTED_PROXIES:-127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
TRUSTED_HOSTS: ^${SERVER_NAME:-example\.com|localhost}|caddy$$
Expand Down
21 changes: 21 additions & 0 deletions helm/api-platform/keycloak/certs/tls.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDazCCAlOgAwIBAgIUGiIkdQOTG1A7NvXDLig7TVDsymIwDQYJKoZIhvcNAQEL
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGd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0 deletions helm/api-platform/keycloak/certs/tls.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCvnrhtub8e1nwp
Rj7a0MDDnlH77BzANSVHLR54kB0xH4wFCIn7GIRXZsKr4xOH68obhtAFbXu+U6fK
6ZkmHqhTtro/nU6eGGZhFK6eSVsg4Hp07eoQ7oNsRX33nScZfpWo6YnH0yFwiUFM
8oQW5rNBOUlJfwVONnPQcdGN6X6olmuG2j0devmlKoohoIR/P/TNU/4X+PSvotjt
1TyPFOeTWPwYvuOoYMiSFQSFNoRyc67N4Np88PGL84zl9FjZO9ndGje/CDgm3FJj
7gswetNX7+4Ge3Q0121vfsvZ2M6kGTX6jwEysSyvbI0ewjX04IwuWjz1nXYgc4+X
bC7N7pmdAgMBAAECggEAAKMWtSFLoN/nd4EtyD6UqysZfSQXwi+UOJDgpmtqyBz+
tZ1VULLeBD5Otl7pgX0WRN2BHoTDatYe9M56+AGJaWnNsw17Zobj0QcTSMUUFvhI
pukX7PVgignZp2TEz5gTRpeImfGm6fsevtZzAjeFmqEE8FryE9LRlhoKVXWBvx2m
ZzrYzSk9I6rVWopTiPQGb3XYfstPByDS72CdqOfs3nNr9IV8G5lCbTEa6Tlqrg+/
KXPg/P4a5s47kSU+i6bJeBk2jK5WXIVG0dqEbUGko+TGrHqO/zTyZVE+H98HjsJV
XHCc5vuJsPAiMF662w+P76+e61LVwgXfDd1SYR6EJQKBgQDTYmCaLDi7lvBsiYyr
Ra1IY7X2pwSf1ddjda8chXcj7MpiWtw1lEegr7KF+zm113wGhvRrH4Dwvsmmg6hX
wlOQot1J5HTeFfjbPf2j56aFRlQoTK8FCuiv/Om9Cn3o32CfS+66NAQunFQWBbgm
ollwmDrD/MekG5IrApv0axTXvwKBgQDUr+i997uoBm9siUo7XjSD0hs2+4I1xqDT
9MASCzJTFhA7Yf7LEBNZC6Njt5kMm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FCIn7GIRXZsKr4xOH68obhtAFbXu+U6fK6ZkmHqhTtro/nU6eGGZhFK6eSVsg
4Hp07eoQ7oNsRX33nScZfpWo6YnH0yFwiUFM8oQW5rNBOUlJfwVONnPQcdGN6X6o
lmuG2j0devmlKoohoIR/P/TNU/4X+PSvotjt1TyPFOeTWPwYvuOoYMiSFQSFNoRy
c67N4Np88PGL84zl9FjZO9ndGje/CDgm3FJj7gswetNX7+4Ge3Q0121vfsvZ2M6k
GTX6jwEysSyvbI0ewjX04IwuWjz1nXYgc4+XbC7N7pmdAgMBAAGjUzBRMB0GA1Ud
DgQWBBT2Hy1/xksuYgSTATWa/O6aD39wvDAfBgNVHSMEGDAWgBT2Hy1/xksuYgST
ATWa/O6aD39wvDAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBF
RDCteKuQ+RTEyzsAzslbPm+S/4T8bI+51Xuy+2ehidJtp0RXBk1VIcG2qG3rQdJF
eTe4QbRZPC2g1CjnbBLkoMDJuGCY9a7b1Bc7pCS8oAfN5V044Uem7ydJuekoMEAR
br95hojGe8RN/YOjOa/U9TazjCTo5JFi1UWg+WKK/r8YrBJJWsU+ORxCNMOaVgFp
286Gqdn+4aQo6bPx3xV0X/ny7Dq5i6FpvQkFopUcNpRUnYg+VpB01mNO6BsuduuG
3nmnDCo77LIOVvBuoRpRLaXsqDc7JbLeE1B9lRp1mbvPhTaDXotUglUIaASegA/d
JwdqphZXvvEVMCufLfoY
-----END CERTIFICATE-----
1 change: 1 addition & 0 deletions helm/api-platform/keycloak/config/realm-demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"displayName": "API Platform - Demo",
"enabled": true,
"registrationAllowed": false,
"accessCodeLifespan": 1,
"users": [
{
"username": "chuck.norris",
Expand Down
3 changes: 1 addition & 2 deletions helm/api-platform/templates/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ spec:
- name: {{ .Chart.Name }}-cronjob
image: "{{ .Values.php.image.repository }}:{{ .Values.php.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.php.image.pullPolicy }}
command: ['/bin/sh', '-c']
args: ['composer install --prefer-dist --no-progress --no-interaction && bin/console doctrine:schema:drop --force --no-interaction && bin/console doctrine:migrations:version --delete --all --no-interaction && bin/console doctrine:migrations:migrate --no-interaction && bin/console doctrine:fixtures:load --no-interaction']
args: ['bin/console', 'doctrine:fixtures:load', '--no-interaction']
env:
- name: OIDC_SERVER_URL
valueFrom:
Expand Down
3 changes: 1 addition & 2 deletions helm/api-platform/templates/fixtures-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ spec:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.php.image.repository }}:{{ .Values.php.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.php.image.pullPolicy }}
command: ['/bin/sh', '-c']
args: ['composer install --prefer-dist --no-progress --no-interaction && bin/console doctrine:fixtures:load --no-interaction']
args: ['bin/console', 'doctrine:fixtures:load', '--no-interaction']
env:
- name: OIDC_SERVER_URL
valueFrom:
Expand Down
2 changes: 1 addition & 1 deletion pwa/components/admin/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const MyLayout = (props: React.JSX.IntrinsicAttributes & LayoutProps) => <Layout

const AdminUI = ({ session, children }: { session: Session, children?: React.ReactNode | undefined }) => {
// @ts-ignore
const dataProvider = useRef<DataProvider>(undefined);
const dataProvider = useRef<DataProvider>();
const { docType } = useContext(DocContext);

dataProvider.current = hydraDataProvider({
Expand Down
16 changes: 8 additions & 8 deletions pwa/components/book/Filters.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Formik } from "formik";
import { type FunctionComponent } from "react";
import { type UseMutationResult } from "react-query";
import { debounce, Checkbox, FormControlLabel, FormGroup, TextField, Typography } from "@mui/material";
import {Formik} from "formik";
import {type FunctionComponent} from "react";
import {type UseMutationResult} from "react-query";
import {Checkbox, debounce, FormControlLabel, FormGroup, TextField, Typography} from "@mui/material";

import { type FiltersProps } from "@/utils/book";
import { type FetchError, type FetchResponse } from "@/utils/dataAccess";
import { type PagedCollection } from "@/types/collection";
import { type Book } from "@/types/Book";
import {type FiltersProps} from "@/utils/book";
import {type FetchError, type FetchResponse} from "@/utils/dataAccess";
import {type PagedCollection} from "@/types/collection";
import {type Book} from "@/types/Book";

interface Props {
filters: FiltersProps | undefined;
Expand Down
7 changes: 4 additions & 3 deletions pwa/components/book/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Head from "next/head";
import { useRouter } from "next/router";
import { useMutation } from "react-query";
import FilterListOutlinedIcon from "@mui/icons-material/FilterListOutlined";
import { FormControl, InputLabel, MenuItem, Select } from "@mui/material";
import { MenuItem, Select } from "@mui/material";

import { Item } from "@/components/book/Item";
import { Filters } from "@/components/book/Filters";
Expand All @@ -18,11 +18,12 @@ interface Props {
data: PagedCollection<Book> | null;
hubURL: string | null;
filters: FiltersProps;
page: number;
}

const getPagePath = (page: number): string => `/books?page=${page}`;

export const List: NextPage<Props> = ({ data, hubURL, filters }) => {
export const List: NextPage<Props> = ({ data, hubURL, filters, page }) => {
const collection = useMercure(data, hubURL);
const router = useRouter();

Expand Down Expand Up @@ -76,7 +77,7 @@ export const List: NextPage<Props> = ({ data, hubURL, filters }) => {
<Item key={book["@id"]} book={book}/>
))}
</div>
<Pagination collection={collection} getPagePath={getPagePath} currentPage={filters?.page}/>
<Pagination collection={collection} getPagePath={getPagePath} currentPage={page}/>
</>
) || (
<p className="w-full flex px-8 pb-4 text-lg">No books found.</p>
Expand Down
Loading

0 comments on commit 9754fd4

Please sign in to comment.