From 89c0232455a8f08e41cdd3431fd429df57005cef Mon Sep 17 00:00:00 2001 From: Marco Micera Date: Wed, 13 Jan 2021 19:52:14 +0100 Subject: [PATCH 1/4] Checking DGraph addresses --- Dockerfile | 8 ++++ Makefile | 11 +++++ README.md | 6 +++ tests/integration/README.md | 17 ++++++++ tests/integration/docker-compose.yml | 60 ++++++++++++++++++++++++++++ tests/integration/qmstr-config.yaml | 15 +++++++ tests/integration/reach.sh | 40 +++++++++++++++++++ 7 files changed, 157 insertions(+) create mode 100644 tests/integration/README.md create mode 100644 tests/integration/docker-compose.yml create mode 100644 tests/integration/qmstr-config.yaml create mode 100755 tests/integration/reach.sh diff --git a/Dockerfile b/Dockerfile index 8e00bda..23c2db1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,9 @@ FROM alpine:20201218 + +# Adding bash +RUN apk --no-cache add \ + bash=5.1.0-r0 \ + && \ + rm -rf /var/cache/apk/* + +ENTRYPOINT [ "bash" ] diff --git a/Makefile b/Makefile index 5aa0581..2825dd3 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,24 @@ .PHONY: build run linters +# Including all other Makefiles +include $(shell find . -name "Makefile.common") + +# Builds the module Docker image build: docker-compose build module +# Runs an interactive shell into the module Docker image run: docker-compose run module +# Runs linters locally linters: docker run \ -e RUN_LOCAL=true \ -v $(shell pwd -P):/tmp/lint \ github/super-linter + +integration-test: build + docker-compose \ + --file tests/integration/docker-compose.yml \ + up diff --git a/README.md b/README.md index 7aa104d..afb9366 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,12 @@ make build make run ``` +## Run integration tests + +```bash +make integration-test +``` + ## Run linters locally ```bash diff --git a/tests/integration/README.md b/tests/integration/README.md new file mode 100644 index 0000000..8485c86 --- /dev/null +++ b/tests/integration/README.md @@ -0,0 +1,17 @@ +# Integration test + +Simple experiment that lets the `module` image try to +reach out to services directly connected to it, +e.g., +RabbitMQ, +DGraph, +and +the Quartermaster Orchestrator. + +## How to run + +From the [root directory](../..): + +```bash +make integration-test +``` diff --git a/tests/integration/docker-compose.yml b/tests/integration/docker-compose.yml new file mode 100644 index 0000000..571412f --- /dev/null +++ b/tests/integration/docker-compose.yml @@ -0,0 +1,60 @@ +version: '3.3' +services: + + # DGraph + # From: https://github.com/dgraph-io/dgraph/blob/master/contrib/config/docker/docker-compose.yml + zero: + image: dgraph/dgraph:latest + volumes: + - /tmp/data:/dgraph + ports: + - 5080:5080 + - 6080:6080 + restart: on-failure + command: dgraph zero --my=zero:5080 + logging: + driver: none + alpha: + image: dgraph/dgraph:latest + volumes: + - /tmp/data:/dgraph + ports: + - 8080:8080 + - 9080:9080 + restart: on-failure + command: dgraph alpha --my=alpha:7080 --zero=zero:5080 + logging: + driver: none + ratel: + image: dgraph/dgraph:latest + ports: + - 8000:8000 + command: dgraph-ratel + logging: + driver: none + + # Orchestrator (former `qmstr-master`) + master: + image: endocodeci/qmstr-master:sha-6f14b29 + entrypoint: "/usr/local/bin/qmstr-master" + command: "--config /home/qmstr/config/qmstr.yaml" + depends_on: + - zero + - alpha + - ratel + ports: + - 50051:50051 + environment: + SERVER_BUILDPATH: "/var/qmstr/buildroot" + volumes: + - ./qmstr-config.yaml:/home/qmstr/config/qmstr.yaml + + # Module + module: + image: endocodeci/module + working_dir: /home/module + volumes: + - ./reach.sh:/home/module/reach.sh + # entrypoint: ./reach.sh + depends_on: + - master diff --git a/tests/integration/qmstr-config.yaml b/tests/integration/qmstr-config.yaml new file mode 100644 index 0000000..4a98381 --- /dev/null +++ b/tests/integration/qmstr-config.yaml @@ -0,0 +1,15 @@ +project: + name: "CI" + metadata: + message: "Hello World!" + # Using docker-compsoe service names + # https://docs.docker.com/compose/networking/ + server: + dbAddress: "alpha:9080" + rpcAddress: "master:50051" + analysis: + - analyzer: scancode-analyzer + name: "Scancode Analyzer" + config: + workdir: "/var/qmstr/buildroot" + resultfile: "/var/qmstr/buildroot/scancode.json" diff --git a/tests/integration/reach.sh b/tests/integration/reach.sh new file mode 100755 index 0000000..f34beb9 --- /dev/null +++ b/tests/integration/reach.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +set -e + +# Logging function +function __log() { + echo "[$1] $2" +} + +function __success() { + __log "OK" "$1" +} + +function __fail() { + __log "FAIL" "$1" + exit "$2" +} + +# Test address connectivity +function __check_connectivity() { + wget --spider -q "$1" # check + local wgetreturn=$? # retrieving wget's return code + if [[ $wgetreturn -eq 0 ]]; then + __success "$1 is reachable" + else + __fail "$1 is not reachable" ${wgetreturn} + fi +} + +# All DGraph exposed addresses +dgraph_addresses=( + alpha:8080 + ratel:8000 +) + +# Checking DGraph addresses +echo "Checking DGraph addresses: " "${dgraph_addresses[@]}" +for dgraph_address in "${dgraph_addresses[@]}"; do + __check_connectivity "${dgraph_address}" +done From bed1c078f3a42d7e91a3ff1ed38f128d2167f323 Mon Sep 17 00:00:00 2001 From: Marco Micera Date: Thu, 14 Jan 2021 10:38:47 +0100 Subject: [PATCH 2/4] Updated int. tests command from its folder --- tests/integration/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/integration/README.md b/tests/integration/README.md index 8485c86..fc97b5d 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -10,8 +10,6 @@ the Quartermaster Orchestrator. ## How to run -From the [root directory](../..): - ```bash -make integration-test +make --directory ../.. integration-test ``` From 8376b06a2f0d7ed013243617946e64e4c6110616 Mon Sep 17 00:00:00 2001 From: Marco Micera Date: Thu, 14 Jan 2021 10:41:57 +0100 Subject: [PATCH 3/4] Run int. test to completion --- tests/integration/docker-compose.yml | 2 +- tests/integration/reach.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/integration/docker-compose.yml b/tests/integration/docker-compose.yml index 571412f..af18a13 100644 --- a/tests/integration/docker-compose.yml +++ b/tests/integration/docker-compose.yml @@ -55,6 +55,6 @@ services: working_dir: /home/module volumes: - ./reach.sh:/home/module/reach.sh - # entrypoint: ./reach.sh + entrypoint: ./reach.sh depends_on: - master diff --git a/tests/integration/reach.sh b/tests/integration/reach.sh index f34beb9..933e931 100755 --- a/tests/integration/reach.sh +++ b/tests/integration/reach.sh @@ -38,3 +38,6 @@ echo "Checking DGraph addresses: " "${dgraph_addresses[@]}" for dgraph_address in "${dgraph_addresses[@]}"; do __check_connectivity "${dgraph_address}" done + +# All tests +__success "All tests have passed" From 2078e9b66907c1adf3b8fc847f3857d73355a4aa Mon Sep 17 00:00:00 2001 From: Marco Micera Date: Thu, 14 Jan 2021 10:57:26 +0100 Subject: [PATCH 4/4] Retrieving return code, manual cleanup --- Makefile | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2825dd3..83d82fa 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,21 @@ linters: -v $(shell pwd -P):/tmp/lint \ github/super-linter +# Integration test +# +# The module should be able to reach all the other components integration-test: build + + # Running the test + # + # Retrieves `module`'s return code, and terminates + # the test as soon as it returns + docker-compose \ + --file tests/integration/docker-compose.yml \ + up \ + --exit-code-from module + + # Manually removing containers on fail docker-compose \ --file tests/integration/docker-compose.yml \ - up + down