From 90cdab110ac8168794e24af54963ca4ca57e93cc Mon Sep 17 00:00:00 2001 From: Filip Sushko Date: Thu, 25 Jul 2019 18:44:29 +0300 Subject: [PATCH 1/2] SC-1728: updated templates for using separate test container --- generator/index.php | 17 +++--- generator/src/templates/deploy.bash.twig | 39 ++++++++++-- .../templates/docker-compose.test.yml.twig | 59 ++++++++++++++++--- .../src/templates/env/cli/store.env.twig | 8 ++- .../templates/nginx/http/rpc.server.conf.twig | 11 +++- 5 files changed, 105 insertions(+), 29 deletions(-) diff --git a/generator/index.php b/generator/index.php index 057aa3371..f902cd4fa 100644 --- a/generator/index.php +++ b/generator/index.php @@ -25,7 +25,7 @@ $mountMode = $projectData['_mountMode'] = retrieveMountMode($projectData, $platform); $projectData['_ports'] = retrieveUniquePorts($projectData); $defaultPort = $projectData['_defaultPort'] = getDefaultPort($projectData); -$yvesEndpointMap = $projectData['_yvesEndpointMap'] = buildYvesEndpointMapByStore($projectData['groups']); +$endpointMap = $projectData['_endpointMap'] = buildEndpointMapByStore($projectData['groups']); mkdir($deploymentDir . DS . 'env' . DS . 'cli', 0777, true); mkdir($deploymentDir . DS . 'context' . DS . 'nginx' . DS . 'conf.d', 0777, true); @@ -90,7 +90,7 @@ $projectData['regions'][$groupData['region']]['stores'][$endpointData['store']]['services'], $endpointData['services'] ?? [] ), - 'yvesEndpointMap' => $yvesEndpointMap, + 'endpointMap' => $endpointMap, ]) ); } @@ -117,6 +117,7 @@ $projectData['regions'][$groupData['region']]['stores'][$endpointData['store']]['services'], $endpointData['services'] ?? [] ), + 'endpointMap' => $endpointMap, ]) ); } @@ -330,9 +331,9 @@ function getBrokerConnections(array $projectData): string * * @return string[] */ -function buildYvesEndpointMapByStore(array $projectGroups): array +function buildEndpointMapByStore(array $projectGroups): array { - $yvesEndpointMap = []; + $endpointMap = []; foreach ($projectGroups as $projectGroup) { $applicationsPerRegion = $projectGroup['applications']; @@ -340,16 +341,12 @@ function buildYvesEndpointMapByStore(array $projectGroups): array foreach ($applicationsPerRegion as $application) { $applicationName = $application['application']; - if ($applicationName !== 'yves') { - continue; - } - foreach ($application['endpoints'] as $endpoint => $endpointData) { $storeName = $endpointData['store']; - $yvesEndpointMap[$storeName] = $endpoint; + $endpointMap[$storeName][$applicationName] = $endpoint; } } } - return $yvesEndpointMap; + return $endpointMap; } diff --git a/generator/src/templates/deploy.bash.twig b/generator/src/templates/deploy.bash.twig index e31cb7e28..b07d09b9a 100644 --- a/generator/src/templates/deploy.bash.twig +++ b/generator/src/templates/deploy.bash.twig @@ -71,6 +71,7 @@ function showHelp() echo -e " ${GREEN}console${NC}\t - Run Spryker console command, e.g. \`${ITALIC}${SPRYKER_SELF_SCRIPT} console code:test -vvv -g Acceptance\`${NC}." echo -e " ${GREEN}codecept${NC}\t - Start a new container where you can run Codeception commands in the test environment." echo -e " ${GREEN}code-checks${NC}\t - Run code-checks." + echo -e " ${GREEN}api-tests${NC} - Run api-tests, e.g. \`${ITALIC}${SPRYKER_SELF_SCRIPT} api-tests -v -g Product\`${NC} or \`${ITALIC}${SPRYKER_SELF_SCRIPT} api-tests -h\`${NC}." echo -e " ${GREEN}acceptance-tests${NC} - Run acceptance-tests, e.g. \`${ITALIC}${SPRYKER_SELF_SCRIPT} acceptance-tests -v -g Acceptance\`${NC} or \`${ITALIC}${SPRYKER_SELF_SCRIPT} acceptance-tests -h\`${NC}." echo -e " ${GREEN}functional-tests${NC} - Run functional-tests, e.g. \`${ITALIC}${SPRYKER_SELF_SCRIPT} functional-tests -v\`${NC} or \`${ITALIC}${SPRYKER_SELF_SCRIPT} functional-tests -h\`${NC}." echo -e " ${GREEN}demo|demo-data${NC} - Populate Spryker demo data." @@ -466,6 +467,27 @@ function execSpryker() ${SPRYKER_DOCKER_PREFIX}_cli:${SPRYKER_DOCKER_TAG} /usr/local/bin/execute.sh } +function execCodecept() +{ + waitFor database + waitFor broker + waitFor search + waitFor key_value_store + waitFor session + + local tty + [ -t -0 ] && tty='' || tty='-T' + + local binary=/usr/local/bin/execute.sh + [ -z "${*}" ] && binary=bash + + execDockerCompose exec \ + -e COMMAND="${*}" \ + -e PS1="spryker@codecept\$" \ + codecept \ + ${binary} +} + function execSprykerMultiString() { setExtraEnvFiles @@ -501,7 +523,7 @@ function execDockerCompose() --project-directory ${PROJECT_DIR} \ --project-name ${SPRYKER_DOCKER_PREFIX} \ ${DOCKER_COMPOSE_FILES} \ - $@ + "$@" } function doUp() @@ -554,6 +576,8 @@ function doPull() } case $1 in + api-tests) + ;; acceptance-tests) ;; functional-tests) @@ -703,16 +727,21 @@ case $1 in ;; codecept) ensureTestingMode - PS1="spryker-codecept@\u\$ " # TODO what is it? - doCli $2 ${@:3} + execCodecept "${@:2}" ;; functional-tests) ensureTestingMode - doCli console code:test:functional ${@:2} + execCodecept console code:test:functional "${@:2}" ;; acceptance-tests) ensureTestingMode - doCli console code:test:acceptance ${@:2} + execCodecept console code:test:acceptance "${@:2}" + ;; + api-tests) + ensureTestingMode + execCodecept console code:fixtures "${@:2}" + execCodecept console queue:worker:start + execCodecept console code:test:api "${@:2}" ;; logs) execSpryker "find ${SPRYKER_LOG_DIRECTORY} -type f \( -name \"exception.log\" \) -exec tail -f \"$file\" {} +" diff --git a/generator/src/templates/docker-compose.test.yml.twig b/generator/src/templates/docker-compose.test.yml.twig index 3e783779e..d54e8ccf9 100644 --- a/generator/src/templates/docker-compose.test.yml.twig +++ b/generator/src/templates/docker-compose.test.yml.twig @@ -1,10 +1,36 @@ version: "3.5" +x-volumes: + &app-volumes + volumes: + - logs:${SPRYKER_LOG_DIRECTORY}:rw + - ./${DEPLOYMENT_PATH}/context/php/php-fpm.d/worker.conf:/usr/local/etc/php-fpm.d/worker.conf:ro + - ./${DEPLOYMENT_PATH}/context/php/php.ini:/usr/local/etc/php.ini:ro +{% if _mountMode != 'baked' %} + - ./${DEPLOYMENT_PATH}/context/php/conf.d/opcache_dev.ini:/usr/local/etc/php/conf.d/opcache.ini:ro +{% if _mountMode == 'native' %} + - ./:/data +{% else %} + - ${SPRYKER_DOCKER_PREFIX}_${SPRYKER_DOCKER_TAG}_data_sync:/data +{% endif %} +{% endif %} + x-env_file: &test-envfile env_file: - ${DEPLOYMENT_PATH}/env/testing.env +x-links: + &test-links + links: +{% for group in groups %} +{% for applicationName, applicationData in group['applications'] %} +{% for endpoint, endpointData in applicationData['endpoints'] %} + - frontend:{{ endpoint | split(':') | first }} +{% endfor %} +{% endfor %} +{% endfor %} + services: {% for group in groups %} {% for applicationName, applicationData in group['applications'] %} @@ -23,16 +49,33 @@ services: ports: - 4444:4444 command: "phantomjs --webdriver=4444 --disk-cache=true --load-images=false --webdriver-loglevel=DEBUG" - links: -{% for group in groups %} -{% for applicationName, applicationData in group['applications'] %} -{% for endpoint, endpointData in applicationData['endpoints'] %} - - frontend:{{ endpoint | split(':') | first }} -{% endfor %} -{% endfor %} -{% endfor %} + <<: *test-links + + codecept: + image: ${SPRYKER_DOCKER_PREFIX}_cli:${SPRYKER_DOCKER_TAG} + networks: + - services + - public + - private + depends_on: + - database + - broker + - key_value_store + - session + - search + env_file: + - ${DEPLOYMENT_PATH}/env/cli/{{ docker['testing']['store'] | lower }}.env + - ${DEPLOYMENT_PATH}/env/cli/testing.env + <<: *app-volumes + <<: *test-links + tty: true + command: + - "nc" + - "-l" + - "9000" scheduler: image: nginx:alpine + user: "0:0" volumes: - ./${DEPLOYMENT_PATH}/context/nginx/dummy/scheduler.conf:/etc/nginx/conf.d/default.conf:ro diff --git a/generator/src/templates/env/cli/store.env.twig b/generator/src/templates/env/cli/store.env.twig index c90c989f6..acbc0c21c 100644 --- a/generator/src/templates/env/cli/store.env.twig +++ b/generator/src/templates/env/cli/store.env.twig @@ -9,7 +9,9 @@ SPRYKER_KEY_VALUE_STORE_NAMESPACE={{ services['key_value_store']['namespace'] }} SPRYKER_BROKER_NAMESPACE={{ services['broker']['namespace'] }} SPRYKER_SESSION_BE_NAMESPACE={{ services['session']['namespace'] }} -{% if yvesEndpointMap[storeName] is not empty %} -SPRYKER_FE_HOST={{ yvesEndpointMap[storeName] | split(':') | first }} -SPRYKER_FE_PORT={{ (yvesEndpointMap[storeName] | split(':'))[1] | default(80) }} +{% if endpointMap[storeName] is not empty %} +SPRYKER_FE_HOST={{ endpointMap[storeName]['yves'] | split(':') | first }} +SPRYKER_FE_PORT={{ (endpointMap[storeName]['yves'] | split(':'))[1] | default(80) }} +SPRYKER_API_HOST={{ endpointMap[storeName]['glue'] | split(':') | first }} +SPRYKER_API_PORT={{ (endpointMap[storeName]['glue'] | split(':'))[1] | default(80) }} {% endif %} diff --git a/generator/src/templates/nginx/http/rpc.server.conf.twig b/generator/src/templates/nginx/http/rpc.server.conf.twig index 261a21af9..6914912a4 100644 --- a/generator/src/templates/nginx/http/rpc.server.conf.twig +++ b/generator/src/templates/nginx/http/rpc.server.conf.twig @@ -10,9 +10,14 @@ fastcgi_param SPRYKER_BE_HOST {{ host }}; fastcgi_param SPRYKER_BE_PORT {{ port }}; -{% if project['_yvesEndpointMap'][endpointData['store']] is not empty %} - fastcgi_param SPRYKER_FE_HOST {{ project['_yvesEndpointMap'][endpointData['store']] }}; - fastcgi_param SPRYKER_FE_PORT {{ (project['_yvesEndpointMap'][endpointData['store']] | split(':'))[1] | default(80) }}; +{% if project['_endpointMap'][endpointData['store']]['yves'] is not empty %} + fastcgi_param SPRYKER_FE_HOST {{ project['_endpointMap'][endpointData['store']]['yves'] }}; + fastcgi_param SPRYKER_FE_PORT {{ (project['_endpointMap'][endpointData['store']]['yves'] | split(':'))[1] | default(80) }}; +{% endif %} + +{% if project['_endpointMap'][endpointData['store']]['glue'] is not empty %} + fastcgi_param SPRYKER_API_HOST {{ project['_endpointMap'][endpointData['store']]['glue'] }}; + fastcgi_param SPRYKER_API_PORT {{ (project['_endpointMap'][endpointData['store']]['glue'] | split(':'))[1] | default(80) }}; {% endif %} root /data/public/Zed; From 88f027fd662d41faefb1300c1eab47e3baa0da16 Mon Sep 17 00:00:00 2001 From: Filip Sushko Date: Fri, 26 Jul 2019 09:59:51 +0300 Subject: [PATCH 2/2] SC-1728: added idea directory to .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 91ef6cbb2..bb1ba06be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # Ignore generated files deployment/* !deployment/.gitkeep - +.idea/ generator/vendor