diff --git a/README.md b/README.md index ce17ab2e..99020818 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,15 @@ If you are a **facilitator**, go to [server/](./server/README.md) and find out h Have fun :D ## People running Extreme Carpaccio + - Find out what people are saying about Extreme Carpaccio on [Twitter](https://twitter.com/search?vertical=default&q=%22extreme%20carpaccio%22%20OR%20%22Xtreme%20carpaccio%22%20OR%20%23ExtremeCarpaccio&src=typd) + + cypress11: + image: cypress/included:cypress-12.5.1-node-16.18.1-chrome-110.0.5481.96-1-ff-109.0-edge-110.0.1587.41-1 + entrypoint: /bin/sh -c "cd ./apps/frontend && npm install esbuild-wasm && CYPRESS_BASE_URL=<http://127.0.0.1> cypress run --headless --browser chrome" + depends_on: + - front + working_dir: /test + volumes: + - ./:/test + - /tmp/.X11-unix:/tmp/.X11-unix diff --git a/server/.docker/nginx.conf b/server/.docker/nginx.conf new file mode 100644 index 00000000..527680a7 --- /dev/null +++ b/server/.docker/nginx.conf @@ -0,0 +1,48 @@ +server { + listen 80; + server_name localhost; + + gzip on; + gzip_disable "msie6"; + + gzip_vary on; + gzip_proxied any; + gzip_comp_level 6; + gzip_buffers 16 8k; + gzip_http_version 1.1; + gzip_min_length 256; + gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon; + + root /usr/share/nginx/html; + + location / { + try_files $uri /index.html; + add_header Cache-Control "no-store, no-cache, must-revalidate"; + add_header Pragma "no-cache"; + add_header Referrer-Policy origin-when-cross-origin; + add_header X-Frame-Options "SAMEORIGIN"; + add_header X-Content-Type-Options "nosniff"; + add_header X-XSS-Protection "1; mode=block"; + expires -1; + } + + # Media: images, icons, video, audio, HTC + location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { + expires 1y; + access_log off; + add_header Cache-Control "public"; + } + + # CSS and Javascript + location ~* \.(?:css|js)$ { + expires 1y; + access_log off; + add_header Cache-Control "public"; + } + + # redirect server error pages to the static page /50x.html + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} \ No newline at end of file diff --git a/server/.dockerignore b/server/.dockerignore new file mode 100644 index 00000000..c4d504ed --- /dev/null +++ b/server/.dockerignore @@ -0,0 +1,2 @@ +node_modules +.turbo \ No newline at end of file diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 00000000..879052a1 --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,17 @@ +FROM node:18.15.0-alpine3.17 AS builder + +RUN apk add --no-cache libc6-compat + +WORKDIR /app + +# First install the dependencies (as they change less often) +COPY . . +RUN npm ci +RUN npx turbo prune --scope=frontend --docker + +# Build the project +RUN npx turbo build --filter=frontend + +FROM nginx:latest +COPY .docker/nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=builder /app/apps/frontend/dist/ /usr/share/nginx/html/ diff --git a/server/Dockerfile-cypress b/server/Dockerfile-cypress new file mode 100644 index 00000000..79e563a4 --- /dev/null +++ b/server/Dockerfile-cypress @@ -0,0 +1,5 @@ +FROM cypress/included:cypress-12.5.1-node-16.18.1-chrome-110.0.5481.96-1-ff-109.0-edge-110.0.1587.41-1 +COPY /apps/frontend /front/ +WORKDIR /front +RUN npm install esbuild-wasm +ENTRYPOINT npm run test:e2e:docker diff --git a/server/apps/frontend/Dockerfile b/server/apps/frontend/Dockerfile deleted file mode 100644 index 6108971a..00000000 --- a/server/apps/frontend/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM cypress/browsers:node-16.18.1-chrome-110.0.5481.96-1-ff-109.0-edge-110.0.1587.41-1 -WORKDIR /app -COPY package.json ./ -COPY ./ ./ -RUN npm install -g npm@8.19.3 -RUN npm ci -CMD ["npm", "run", "start:server:local"] \ No newline at end of file diff --git a/server/apps/frontend/cypress/e2e/create-a-seller/create-a-seller.ts b/server/apps/frontend/cypress/e2e/create-a-seller/create-a-seller.ts index cfd144d1..49010dfe 100644 --- a/server/apps/frontend/cypress/e2e/create-a-seller/create-a-seller.ts +++ b/server/apps/frontend/cypress/e2e/create-a-seller/create-a-seller.ts @@ -1,3 +1,4 @@ +import { baseUrl } from './../share-util'; /// <reference types="cypress" /> import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'; import '@testing-library/cypress/add-commands'; @@ -5,7 +6,7 @@ import '@testing-library/cypress/add-commands'; Given(/^I'm a Seller$/, () => { cy.intercept( 'POST', - 'http://localhost:3000/seller', + `${baseUrl}/seller`, (req) => { if (req.body.includes('Xavier') || req.body.includes('newPassword')) { @@ -17,7 +18,7 @@ Given(/^I'm a Seller$/, () => { } } ); - cy.visit('http://localhost:3000/'); + cy.visit(baseUrl); }); When('I write the field {string} {string} with {string}', (_, label, value) => { cy.get(`[aria-label="your ${label}"]`).type(value); diff --git a/server/apps/frontend/cypress/e2e/display-sellers/display-sellers.ts b/server/apps/frontend/cypress/e2e/display-sellers/display-sellers.ts index c0111d3b..47bc6eaf 100644 --- a/server/apps/frontend/cypress/e2e/display-sellers/display-sellers.ts +++ b/server/apps/frontend/cypress/e2e/display-sellers/display-sellers.ts @@ -1,3 +1,4 @@ +import { baseUrl } from './../share-util'; /// <reference types="cypress" /> import { When, Then } from '@badeball/cypress-cucumber-preprocessor'; import '@testing-library/cypress/add-commands'; @@ -23,7 +24,7 @@ const checkTableSellers = (table) => { }; When('There are 3 sellers', () => { - cy.intercept('GET', 'http://localhost:3000/sellers', { + cy.intercept('GET', `${baseUrl}/sellers`, { statusCode: 200, body: [ { cash: 60, name: 'Lukasz', online: true }, @@ -38,7 +39,7 @@ Then('I see sellers:', (table) => { }); Then('there is a updating of sellers', () => { - cy.intercept('GET', 'http://localhost:3000/sellers', { + cy.intercept('GET', `${baseUrl}/sellers`, { statusCode: 200, body: [ { cash: 10000023210, name: 'Lukasz', online: true }, diff --git a/server/apps/frontend/cypress/e2e/history-sellers/history-sellers.ts b/server/apps/frontend/cypress/e2e/history-sellers/history-sellers.ts index 690499ad..40351ceb 100644 --- a/server/apps/frontend/cypress/e2e/history-sellers/history-sellers.ts +++ b/server/apps/frontend/cypress/e2e/history-sellers/history-sellers.ts @@ -1,3 +1,4 @@ +import { baseUrl } from './../share-util'; /// <reference types="cypress" /> import { When } from '@badeball/cypress-cucumber-preprocessor'; import '@testing-library/cypress/add-commands'; @@ -5,7 +6,7 @@ import '@testing-library/cypress/add-commands'; let number = 100; When('There are 100 iterations', () => { - cy.intercept('GET', 'http://localhost:3000/sellers/history?chunk=10', { + cy.intercept('GET', `${baseUrl}/sellers/history?chunk=10`, { statusCode: 200, body: { lastIteration: 100, @@ -20,7 +21,7 @@ When('There are 100 iterations', () => { }); When('There are 200 iterations', () => { - cy.intercept('GET', 'http://localhost:3000/sellers/history?chunk=10', { + cy.intercept('GET', `${baseUrl}/sellers/history?chunk=10`, { statusCode: 200, body: { lastIteration: 100, diff --git a/server/apps/frontend/cypress/e2e/share-util.ts b/server/apps/frontend/cypress/e2e/share-util.ts index 54863508..484bf2be 100644 --- a/server/apps/frontend/cypress/e2e/share-util.ts +++ b/server/apps/frontend/cypress/e2e/share-util.ts @@ -1,6 +1,6 @@ import { Given } from '@badeball/cypress-cucumber-preprocessor'; -export const baseUrl = 'http://localhost:3000/'; +export const baseUrl = Cypress.config().baseUrl; Given(/^I'm on the website$/, () => { cy.get('html').invoke('css', 'height', 'initial'); diff --git a/server/apps/frontend/docker-compose.yml b/server/apps/frontend/docker-compose.yml deleted file mode 100644 index d7b606b0..00000000 --- a/server/apps/frontend/docker-compose.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: '12.5.1' -services: - front: - build: ./ - environment: - - PORT=3000 - cypress: - image: cypress/included:cypress-12.5.1-node-16.18.1-chrome-110.0.5481.96-1-ff-109.0-edge-110.0.1587.41-1 - entrypoint: /bin/sh -c "npm install @esbuild/linux-x64 && CYPRESS_BASE_URL=http://front:3000 cypress run --headless --browser chrome" - depends_on: - - front - working_dir: /test - volumes: - - ./:/test - - /tmp/.X11-unix:/tmp/.X11-unix \ No newline at end of file diff --git a/server/apps/frontend/package.json b/server/apps/frontend/package.json index 8cc474a4..8bfeb8bd 100644 --- a/server/apps/frontend/package.json +++ b/server/apps/frontend/package.json @@ -23,7 +23,8 @@ "dev": "vite build --watch", "build": "vite build", "start:server:local": "vite", - "test:e2e": "cypress run --browser chrome", + "test:e2e:docker": "cypress run --config baseUrl=http://127.0.0.1 --headless --browser chrome", + "test:e2e": "cypress run --headless --browser chrome", "test": "vitest", "format:check": "prettier --list-different src", "format:fix": "prettier --write src", diff --git a/server/docker-compose.yml b/server/docker-compose.yml new file mode 100644 index 00000000..712b3217 --- /dev/null +++ b/server/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3.6' +services: + front: + build: ./ + restart: always + ports: + - '80:80' + cypress: + build: + context: . + dockerfile: Dockerfile-cypress + depends_on: + - front + network_mode: 'host'