Skip to content

Commit

Permalink
chore(e2e-env): add a dockerized e2e-env support (#156)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Lepoetre <[email protected]>
  • Loading branch information
jokesterfr and guillaume60240 authored Dec 1, 2023
1 parent 2b452bc commit 8d33724
Show file tree
Hide file tree
Showing 29 changed files with 7,398 additions and 1,515 deletions.
6 changes: 0 additions & 6 deletions .config.e2e.yml

This file was deleted.

27 changes: 11 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help build version zip zip-inte zip-preprod zip-prod zip-e2e build test composer-validate lint php-lint lint-fix phpunit phpstan phpstan-baseline docker-test docker-lint docker-lint docker-phpunit docker-phpstan
.PHONY: help build version zip zip-e2e zip-inte zip-preprod zip-prod build test composer-validate translation-validate lint docker-lint lint-fix docker-fix-lint php-cs-fixer php-cs-fixer-lint lint-fix docker-lint-fix php-lint docker-php-lint phpunit docker-phpunit phpunit-cov docker-phpunit-cov phpstan docker-phpstan phpstan-baseline docker-test
PHP = $(shell command -v php >/dev/null 2>&1 || { echo >&2 "PHP is not installed."; exit 1; } && which php)
VERSION ?= $(shell git describe --tags 2> /dev/null || echo "0.0.0")
SEM_VERSION ?= $(shell echo ${VERSION} | sed 's/^v//')
Expand All @@ -17,7 +17,7 @@ default: build
help:
@egrep "^#" Makefile

# target: build - Clean up the repository
# target: clean - Clean up the repository
clean:
git -c core.excludesfile=/dev/null clean -X -d -f

Expand All @@ -33,22 +33,13 @@ version:
zip: zip-prod zip-preprod zip-inte
dist:
@mkdir -p ./dist
.config.inte.yml:
@echo ".config.inte.yml file is missing, please create it. Exiting" && exit 1;
.config.preprod.yml:
@echo ".config.preprod.yml file is missing, please create it. Exiting" && exit 1;
.config.prod.yml:
@echo ".config.prod.yml file is missing, please create it. Exiting" && exit 1;
.config.e2e.yml:
@echo ".config.e2e.yml file is missing, please create it. Exiting" && exit 1;

define zip_it
$(eval TMP_DIR := $(shell mktemp -d))
mkdir -p ${TMP_DIR}/ps_eventbus;
cp -r $(shell cat .zip-contents) ${TMP_DIR}/ps_eventbus;
./tools/vendor/bin/autoindex prestashop:add:index ${TMP_DIR}
cp $1 ${TMP_DIR}/ps_eventbus/config/parameters.yml;
if [ $1 = ".config.e2e.yml" ]; then ./tests/Mocks/apply-ps-accounts-mock.sh ${TMP_DIR}/ps_eventbus; fi
cd ${TMP_DIR} && zip -9 -r $2 ./ps_eventbus;
mv ${TMP_DIR}/$2 ./dist;
rm -rf ${TMP_DIR:-/dev/null};
Expand All @@ -63,19 +54,19 @@ docker run \
endef

# target: zip-e2e - Bundle a local E2E integrable zip
zip-e2e: vendor dist .config.e2e.yml
@$(call zip_it,.config.e2e.yml,${PACKAGE}_e2e.zip)
zip-e2e: vendor dist
@$(call zip_it,./config/parameters.yml,${PACKAGE}_e2e.zip)

# target: zip-inte - Bundle an integration zip
zip-inte: vendor dist .config.inte.yml
zip-inte: vendor dist
@$(call zip_it,.config.inte.yml,${PACKAGE}_integration.zip)

# target: zip-preprod - Bundle a preproduction zip
zip-preprod: vendor dist .config.preprod.yml
zip-preprod: vendor dist
@$(call zip_it,.config.preprod.yml,${PACKAGE}_preproduction.zip)

# target: zip-prod - Bundle a production zip
zip-prod: vendor dist .config.prod.yml
zip-prod: vendor dist
@$(call zip_it,.config.prod.yml,${PACKAGE}.zip)

# target: build - Setup PHP & Node.js locally
Expand Down Expand Up @@ -119,6 +110,10 @@ translation-validate:
lint: php-cs-fixer php-lint
docker-lint: docker-php-cs-fixer docker-php-lint

# target: lint-fix (or docker-fix-lint) - Automatically fix the linting errors
lint-fix: php-cs-fixer-fix
docker-lint-fix: docker-php-cs-fixer-fix

# target: php-cs-fixer (or php-cs-fixer-lint) - Lint the code and expose errors
php-cs-fixer: tools/vendor
@PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --dry-run --diff --using-cache=no;
Expand Down
7 changes: 3 additions & 4 deletions config.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>ps_eventbus</name>
<displayName><![CDATA[PrestaShop Eventbus]]></displayName>
<displayName><![CDATA[PrestaShop EventBus]]></displayName>
<version><![CDATA[0.0.0]]></version>
<description><![CDATA[Link your PrestaShop account to synchronize your shop data to a tech partner of your choice. Do not uninstall this module if you are already using a service, as it will prevent it from working.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
<confirmUninstall><![CDATA[This action will immediately prevent your PrestaShop services and Community services from working as they are using PrestaShop CloudSync for syncing.]]></confirmUninstall>
<confirmUninstall><![CDATA[This action will immediately prevent your PrestaShop services and Community services from working as they are using PrestaShop CloudSync for syncing.]]></confirmUninstall>
<is_configurable>0</is_configurable>
<need_instance>0</need_instance>
<limited_countries></limited_countries>
</module>
</module>
9 changes: 4 additions & 5 deletions config/parameters.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Note: this file is here for documentation purpose
# It will be overridden by the Makefile
# Note: this file defaults to the E2E env, it will be overridden on zip build
parameters:
ps_eventbus.proxy_api_url: "https://eventbus-proxy.psessentials.net"
ps_eventbus.sync_api_url: "https://eventbus-sync.psessentials.net"
ps_eventbus.live_sync_api_url: "https://api.cloudsync.prestashop.com/live-sync/v1"
ps_eventbus.proxy_api_url: "http://reverse-proxy/collector"
ps_eventbus.sync_api_url: "http://reverse-proxy/sync-api"
ps_eventbus.live_sync_api_url: "http://reverse-proxy/live-sync-api/v1"
ps_eventbus.sentry_dsn: "https://[email protected]/stuff"
ps_eventbus.sentry_env: "development"
9 changes: 9 additions & 0 deletions e2e-env/.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Infrastructure dependencies
DOCKER_IMAGE_PRESTASHOP=prestashop/prestashop-flashlight:latest
DOCKER_VERSION_MARIADB=lts

# Infrastructure port binding on the host
HOST_PORT_BIND_PRESTASHOP=8000
HOST_PORT_BIND_MYSQL=3306
HOST_PORT_BIND_PHP_MY_ADMIN=6060
HOST_PORT_BIND_CLOUDSYNC_REVERSE_PROXY=80
2 changes: 2 additions & 0 deletions e2e-env/cloudsync-mock/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
54 changes: 54 additions & 0 deletions e2e-env/cloudsync-mock/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
root: true
env:
jest: true
es6: true
plugins:
- '@typescript-eslint'
- deprecation
- import
- unicorn
- prettier
extends:
- eslint:recommended
- plugin:@typescript-eslint/recommended
- plugin:import/recommended
- plugin:import/typescript
- plugin:prettier/recommended
parser: '@typescript-eslint/parser'
parserOptions:
sourceType: module
project: true
ignorePatterns:
- 'dist/'
- 'node_modules/'
- 'coverage/'
settings:
import/parsers:
'@typescript-eslint/parser':
- '.ts'
import/resolver:
typescript:
project: true
node:
project: true
rules:
'prettier/prettier': error
'@typescript-eslint/no-explicit-any': off
'@typescript-eslint/explicit-module-boundary-types': off
'@typescript-eslint/no-unused-vars':
- warn
- argsIgnorePattern: '^_'
varsIgnorePattern: '^_'
unicorn/filename-case:
- error
- case: kebabCase
deprecation/deprecation: warn
import/no-unresolved: error
import/no-extraneous-dependencies:
- error
- devDependencies:
- '**/*.ts'
optionalDependencies:
- '**/*.ts'
peerDependencies: true
12 changes: 12 additions & 0 deletions e2e-env/cloudsync-mock/.prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
singleQuote: true
trailingComma: all
plugins:
- 'prettier-plugin-organize-imports'
overrides:
- files:
- '**/*.js'
options:
singleQuote: false
parser: flow
trailingComma: 'es5'
tabWidth: 2
25 changes: 25 additions & 0 deletions e2e-env/cloudsync-mock/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false,
"dynamicImport": false,
"privateMethod": false,
"functionBind": false,
"exportDefaultFrom": false,
"exportNamespaceFrom": false,
"decorators": false,
"decoratorsBeforeExport": false,
"topLevelAwait": false,
"importMeta": false
},
"transform": null,
"target": "es2022",
"loose": false,
"externalHelpers": false,
// Requires v1.2.50 or upper and requires target to be es2016 or upper.
"keepClassNames": false
},
"minify": false
}
12 changes: 12 additions & 0 deletions e2e-env/cloudsync-mock/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:20.10-alpine

ENV CI=true
ENV RUN_IN_DOCKER=1
RUN npm install -g pnpm

WORKDIR /home/node
ADD . /home/node
RUN pnpm install

ENTRYPOINT [ "pnpm" ]
CMD [ "test" ]
14 changes: 14 additions & 0 deletions e2e-env/cloudsync-mock/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.ts$": "ts-jest"
},
"collectCoverageFrom": ["**/*.(t|j)s"],
"coverageDirectory": "../coverage",
"testEnvironment": "node",
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/$1"
}
}
62 changes: 62 additions & 0 deletions e2e-env/cloudsync-mock/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "cloudsync-mock",
"version": "0.0.0",
"type": "module",
"main": "dist/app.js",
"scripts": {
"build": "npx swc ./src -d dist",
"start:dev": "npx swc ./src -w -d dist",
"start": "node dist/app.js",
"lint": "eslint 'src/**/*.ts'",
"lint:fix": "eslint 'src/**/*.ts' --fix",
"format": "prettier --check ./src/**/*",
"format:fix": "prettier --write ./src/**/*",
"fix": "pnpm format:fix && pnpm lint:fix",
"test": "npx jest",
"docker:build": "docker compose -f ../docker-compose.yml build cloudsync-mock-test",
"docker:up": "docker compose -f ../docker-compose.yml up -d --wait",
"docker:down": "docker compose -f ../docker-compose.yml down"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@swc/cli": "^0.1.63",
"@swc/core": "^1.3.99",
"@swc/jest": "^0.2.29",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.10",
"@types/node": "^20.10.0",
"@types/supertest": "^2.0.16",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-unicorn": "^49.0.0",
"eslint": "^8.54.0",
"express-multipart-file-parser": "^0.1.2",
"express": "^4.18.2",
"jest-expect-message": "^1.1.3",
"jest-extended": "^4.0.2",
"jest-mock-extended": "^3.0.5",
"jest": "^29.7.0",
"mockttp": "^3.9.4",
"prettier-plugin-organize-imports": "^3.2.4",
"prettier": "^3.1.0",
"rimraf": "^5.0.5",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.3.2"
},
"engines": {
"yarn": "please use pnpm",
"npm": "please use pnpm",
"node": ">=20",
"pnpm": ">=8"
}
}
Loading

0 comments on commit 8d33724

Please sign in to comment.