Локальный хост в капсулах на Кубернетес - PullRequest
0 голосов
/ 29 июня 2018

Я пытаюсь использовать Cypress для тестирования приложения React в Kubernetes Pod. Я сделал два контейнера внутри стручка. Один для приложения React и один для> инструмента тестирования Cypress Докер спецификация приложения:

FROM node:9-slim AS app
ENV PORT 3000
EXPOSE 3000

COPY . /usr/src/app
WORKDIR /usr/src/app
RUN npm install react --save
RUN npm install ajv --save
CMD ["npm", "start"]

и для кипариса

FROM cypress/base AS cypress
COPY . /test
WORKDIR /test
RUN npm i --save-dev cypress
RUN npm install ajv --save-dev

CMD $(npm bin)/cypress run --record --key 92213f49-6b80-47d5-bbef-2422f308ebf1 -s ./cypress/integration/SystemTest.js

Кубернетес под спецификацией

apiVersion: v1
kind: Pod
metadata:
   name: productlib-pod
spec: 
  restartPolicy: Never
  containers:
     - name: app-container
       image: steinko/app-productlib:1

     - name: cypress-container
       image: steinko/cypress-productlib:1

Я выполняю команды в сценарии сборки

-  docker login -u steinko -p DavidBowie1!

    -  docker  build  -t steinko/app-productlib:1 -f Dockerfile.app .
    -  docker  push steinko/app-productlib:1

    -  docker build -t steinko/cypress-productlib:1 -f Dockerfile.cypress .
    -  docker push steinko/cypress-productlib:1

    -  kubectl apply -f pod.yaml 

я получаю ошибку, что кипарис так не находит localhost: 3000 отсутствует

It looks like this is your first time using Cypress: 3.0.1

[13:08:43]  Verifying Cypress can run /root/.cache/Cypress/3.0.1/Cypress [started] [13:08:46]  Verified Cypress!       /root/.cache/Cypress/3.0.1/Cypress [title changed] [13:08:46]  Verified Cypress!       /root/.cache/Cypress/3.0.1/Cypress [completed]

Opening Cypress...

================================================================================

  (Run Starting)



┌────────────────────────────────────────────────────────────────────────────┐  
│ Cypress:  3.0.1                                                            │  
│ Browser:  Electron 59 (headless)                                           │  
│ Specs:    1 found (SystemTest.js)                                          │  
│ Searche…  cypress/integration/SystemTest.js                                │  
│ Run URL:  https://dashboard.cypress.io/#/projects/rwxp3c/runs/609          │  
└────────────────────────────────────────────────────────────────────────────┘  



────────────────────────────────────────────────────────────────────────────────
                                                                                   Running: SystemTest.js...                                            (1 of 1) 


  Spesifies client behaivior
    1) should diapley hello world in div
    ✓ should be true (64ms)


  1 passing (1m)   1 failing

  1) Spesifies client behaivior should diapley hello world in div:
     CypressError: Timed out after waiting '60000ms' for your remote page to load.

Your page did not fire its 'load' event within '60000ms'.

You can try increasing the 'pageLoadTimeout' value in 'cypress.json' to wait longer.

Browsers will not fire the 'load' event until all stylesheets and scripts are done downloading.

When this 'load' event occurs, Cypress will continue running commands.
      at Object.cypressErr (http://localhost:42219/__cypress/runner/cypress_runner.js:67929:11)
      at Object.throwErr (http://localhost:42219/__cypress/runner/cypress_runner.js:67894:18)
      at Object.throwErrByPath (http://localhost:42219/__cypress/runner/cypress_runner.js:67921:17)
      at timedOutWaitingForPageLoad (http://localhost:42219/__cypress/runner/cypress_runner.js:58198:17)
      at http://localhost:42219/__cypress/runner/cypress_runner.js:58807:18
      at tryCatcher (http://localhost:42219/__cypress/runner/cypress_runner.js:7091:23)
      at http://localhost:42219/__cypress/runner/cypress_runner.js:2408:41
      at tryCatcher (http://localhost:42219/__cypress/runner/cypress_runner.js:7091:23)
      at Promise._settlePromiseFromHandler (http://localhost:42219/__cypress/runner/cypress_runner.js:5113:31)
      at Promise._settlePromise (http://localhost:42219/__cypress/runner/cypress_runner.js:5170:18)
      at Promise._settlePromise0 (http://localhost:42219/__cypress/runner/cypress_runner.js:5215:10)
      at Promise._settlePromises (http://localhost:42219/__cypress/runner/cypress_runner.js:5290:18)
      at Async._drainQueue (http://localhost:42219/__cypress/runner/cypress_runner.js:2023:16)
      at Async._drainQueues (http://localhost:42219/__cypress/runner/cypress_runner.js:2033:10)
      at Async.drainQueues (http://localhost:42219/__cypress/runner/cypress_runner.js:1907:14)
      at <anonymous>




  (Results)

┌───────────────────────────────────┐
│ Tests:        2                   │
│ Passing:      1                   │
│ Failing:      1                   │
│ Pending:      0                   │
│ Skipped:      0                   │
│ Screenshots:  1                   │
│ Video:        true                │
│ Duration:     1 minute, 0 seconds │
│ Spec Ran:     SystemTest.js       │
└───────────────────────────────────┘


  (Screenshots)

  - /test/cypress/screenshots/Spesifies client behaivior -- should diapley hello world in div.png (1280x720)


  (Video)

  - Started processing:   Compressing to 32 CRF
  - Compression progress:  45%
  - Compression progress:  91%
  - Finished processing:  /test/cypress/videos/SystemTest.js.mp4 (22 seconds)


  (Uploading Results)

  - Done Uploading (1/2) /test/cypress/screenshots/Spesifies client behaivior -- should diapley hello world in div.png
  - Done Uploading (2/2) /test/cypress/videos/SystemTest.js.mp4

================================================================================

  (Run Finished)


      Spec                                    Tests  Pass…  Fail…  Pend…  Skip…



┌────────────────────────────────────────────────────────────────────────────┐
│ ✖ SystemTest.js                   01:00      2      1      1      -     -  │
└────────────────────────────────────────────────────────────────────────────┘

    1 of 1 failed (100%)              01:00      2      1      1      -      -  


───────────────────────────────────────────────────────────────────────────────────   
                                                                                Recorded Run: https://dashboard.cypress.io/#/projects/rwxp3c/runs/609

Ответы [ 2 ]

0 голосов
/ 02 июля 2018

Я бы порекомендовал вам проверить работоспособность приложения.

Добавьте третий контейнер с Ubuntu в ваш модуль:

apiVersion: v1
kind: Pod
metadata:
   name: productlib-pod
spec: 
  restartPolicy: Never
  containers:
     - name: app-container
       image: steinko/app-productlib:1

     - name: cypress-container
       image: steinko/cypress-productlib:1

     - name: ubuntu
       image: ubuntu
       args: [bash, -c, 'apt-get update && apt-get -y install curl less net-tools && while true ; do sleep 1000; done']

Дождитесь установки пакетов в Ubuntu:

$ kubectl logs productlib-pod ubuntu

<skipped>
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

Выполнить bash в контейнере Ubuntu:

$ kubectl exec -ti productlib-pod -c ubuntu -- bash

Проверьте, находится ли порт 3000 в состоянии LISTEN:

root@productlib-pod# netstat -anl

Если это так, попробуйте подключиться к нему с помощью curl:

root@productlib-pod# curl http://localhost:3000

Таким образом, вы можете убедиться, что приложение может отвечать на запросы через порт 3000.

0 голосов
/ 29 июня 2018

Вы должны установить порт, отображаемый вашим контейнером, в вашем определении Pod. Что-то вроде:

    ports:
    - containerPort: 3000
      protocol: 'TCP'

Att.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...