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..83d82fa 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,38 @@ .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 +# +# 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 \ + down 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..fc97b5d --- /dev/null +++ b/tests/integration/README.md @@ -0,0 +1,15 @@ +# 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 + +```bash +make --directory ../.. integration-test +``` diff --git a/tests/integration/docker-compose.yml b/tests/integration/docker-compose.yml new file mode 100644 index 0000000..af18a13 --- /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..933e931 --- /dev/null +++ b/tests/integration/reach.sh @@ -0,0 +1,43 @@ +#!/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 + +# All tests +__success "All tests have passed"