citrusframework / yaks

YAKS is a platform to enable Cloud Native BDD testing on Kubernetes
Apache License 2.0
83 stars 27 forks source link

How to run Yaks tests from CI ? #399

Open themathmagician opened 2 years ago

themathmagician commented 2 years ago

Hello yaks team I am trying to figure out how to use yaks in CI. My project team is developing microservices that work with Kafka, everything installed as pods in an Openshift cluster. We use Azure pipelines for CI.

My idea is to use a docker container with yaks installed towards our Openshift installation from a pipeline worker (Azure). I have found a Docker container with yaks that seems official on DockerHub: https://hub.docker.com/r/citrusframework/yaks However, it has no documentation, link to sources or similar. It doesnt have any instructions for how to run it. No kubectl installed inside.
I tried to execute yaks list inside the container, but it fails with an error:

Error: cannot get command client: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

I am missing instructions for how to run the helloworld.feature could you help to point me in the right direction?

christophd commented 2 years ago

You should install the YAKS operator and add the test in form of custom resource to let the operator create the YAKS runtime and run the test for you.

You can create the custom resource on your own or maybe you can leverage the YAKS CLI within the build pipeline.

Maybe have a look at how things are done in the GutHub workflow CI.

e.g. https://github.com/openshift-integration/kamelet-catalog/blob/kamelet-catalog-1.6/.github/workflows/kubernetes.yml

This might give you some ideas.

Please let me know if this is of much help to you.

themathmagician commented 2 years ago

We have the Yaks operator installed in our Openshift cluster.

I am trying to enable running the integration tests in the CI pipeline. Instead of installing the yaks CLI in the CI pipeline worker, I thought of using the Docker image provided by your project. The main motivation - team members can run things locally and experience same results as what will happen in the pipeline ✨.

I am mounting my test files and .kube/config folder. Here is my docker-compose file:

version: "3.9"
services:
  demo:
    build: .
    ports:
      - "8080:8080"
  bdd:
    image: citrusframework/yaks:0.9.0
    volumes:
      - ./src/test/resources/bdd:/bdd
      - ~/.kube/config:/root/.kube/config

I am starting the container with :

docker compose run bdd bash   

From inside the container

I have no name!@03f7d671cd72:/bdd$ yaks version
YAKS 0.9.0
I have no name!@03f7d671cd72:/bdd$ yaks list
NAME    PHASE   TOTAL   PASSED  FAILED  SKIPPED ERRORS
hello           0       0       0       0       0
I have no name!@03f7d671cd72:/bdd$ yaks -n bdd-demo run hello.feature --logger root=INFO
Test 'hello' updated

... after this the process hangs, and has to be interrupted by ctr-c ... so not usable for a CI setup.

After reading your reply, @christophd , I am thinking - can I just install the tests using a simple kubernetes template?

christophd commented 2 years ago

Yes, you can add the test using a simple Kubernetes template

Here is a sample one with embedded test feature:

apiVersion: yaks.citrusframework.org/v1alpha1
kind: Test
metadata:
  name: example-test
spec:
  source:
    name: example.feature
    language: feature
    content: |-
      Feature: hello world

        Scenario: print slogan
          Given YAKS does Cloud-Native BDD testing
          Then YAKS rocks!
christophd commented 2 years ago

So just to answer to your previous approach by directly using the Docker image and mounting the test resource.

You do not have to run YAKS CLI inside the Docker container then. This will fail as the YAKS runtime container lacks some required privileges to create resources on the cluster.

So instead you have to run the Maven runtime inside the container. The command used by default to run YAKS tests inside the container would be something like:

mvn -B -q --no-snapshot-updates --no-transfer-progress -f /deployments/data/yaks-runtime-maven -s /deployments/artifacts/settings.xml verify -Dmaven.repo.local=/deployments/artifacts/m2

Test resources need to be mounted to /ect/yaks/tests by the way

themathmagician commented 2 years ago

Ok, I have still trouble using the Docker image. It seems that it can't find the test feature to run. Here is the output from running bash inside the container (mounting my hello.feature to /ect/yaks/tests ):

I have no name!@b2951a675567:/ect/yaks/tests$ pwd
/ect/yaks/tests
I have no name!@b2951a675567:/ect/yaks/tests$ ls
hello.feature  _output
I have no name!@b2951a675567:/ect/yaks/tests$ mvn -B -q --no-snapshot-updates --no-transfer-progress -f /deployments/data/yaks-runtime-maven -s /deployments/artifacts/settings.xml verify -Dmaven.repo.local=/deployments/artifacts/m2
Apr 06, 2022 9:47:57 AM io.cucumber.core.runtime.FeaturePathFeatureSupplier get
WARNING: No features found at classpath:/org/citrusframework/yaks
INFO    | ------------------------------------------------------------------------
INFO    | 
INFO    | CITRUS TEST RESULTS
INFO    | 
INFO    | 
INFO    | TOTAL:        0
INFO    | FAILED:       0 (0.0%)
INFO    | SUCCESS:      0 (0.0%)
INFO    | 
INFO    | ------------------------------------------------------------------------

0 Scenarios
0 Steps
0m0.005s

I have no name!@b2951a675567:/ect/yaks/tests$ yaks list
NAME    PHASE   TOTAL   PASSED  FAILED  SKIPPED ERRORS
hello           0       0       0       0       0
I have no name!@b2951a675567:/ect/yaks/tests$ 

Can you provide a link to the Dockerfile, that generates this image?

Regarding the approach of using a template without the yaks-cli: what if I want to use a k8s template, but without inlining the features, I would prefer to have them in regular feature files?