Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few verification tests with GitHub Actions workflow #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
BROKER_NAME=activemq-artemis
BUNDLE_PACKAGE=$BROKER_NAME

TARGET_IMAGE=$BROKER_NAME-operator-bundle

REGISTRY=quay.io/artemiscloud_scratch

VERSION="0.15"
ARCHITECTURE="amd64"

BROKER=$BROKER_NAME-openshift-image
BROKER_VERSION=2.13
BROKER_IMAGE=$REGISTRY/$BROKER:$BROKER_VERSION

OPERATOR=$BROKER_NAME-operator
OPERATOR_VERSION=0.15.0
OPERATOR_IMAGE=$REGISTRY/$OPERATOR:$OPERATOR_VERSION
OPERATOR_PACKAGE=$BROKER_NAME

GROUP=broker.amq.io
NAME="artemiscloud/$BROKER_NAME-operator-bundle"
DESCRIPTION="ActiveMQ Artemis $BROKER_VERSION Operator Bundle"
SUMMARY=$DESCRIPTION

REDHAT_OPENSHIFT_VERSION="v4.5"
REDHAT_COMPONENT="activemq-artemis-operator-bundle-container"
OPENSHIFT_TAGS="messaging,artemis,integration,operator,golang"

K8S_DISPLAY_NAME=$DESCRIPTION
K8S_DESCRIPTION="An associated operator bundle of metadata."
29 changes: 29 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'PR/Push to master'

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout the repo
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo curl -L https://github.com/aelsabbahy/goss/releases/latest/download/goss-linux-amd64 -o /usr/local/bin/goss
sudo chmod +rx /usr/local/bin/goss

- name: Build the image
run: "make all-ci"

- uses: actions/upload-artifact@v2
with:
name: Test results (JUnit)
path: validate_results.junit.xml
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!make

SHELL := /bin/sh -x

all: clean build prepare-image-check validate
verify-image: clean pull prepare-image-check validate

all-ci: clean build prepare-image-check validate-ci
verify-image-ci: clean prepare-image-check validate-ci

build:
@set -a; . ./.env; \
docker build . -f bundle.Dockerfile -t $${TARGET_IMAGE}

pull:
@set -a; . ./.env; \
docker pull $${TARGET_IMAGE}

prepare-image-check:
@set -a; . ./.env; \
tests/scripts/prepare.sh $${TARGET_IMAGE}

validate:
@set -a; . ./.env; \
goss validate

validate-ci:
@set -a; . ./.env; \
goss validate --format documentation --format-options verbose; \
goss validate --format junit --format-options verbose > validate_results.junit.xml; \
tests/scripts/junit.sh validate_results.junit.xml

clean:
@rm -rf tests/verify
44 changes: 44 additions & 0 deletions goss.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
file:
tests/verify/layer/manifests/{{getEnv "OPERATOR"}}.v{{getEnv "OPERATOR_VERSION"}}.clusterserviceversion.yaml:
exists: true
contains:
- {{getEnv "BROKER_IMAGE"}}
- 'containerImage: {{getEnv "OPERATOR_IMAGE"}}'
- 'operated-by: {{getEnv "OPERATOR"}}.v{{getEnv "OPERATOR_VERSION"}}'
tests/verify/layer/manifests/broker_activemqartemis_crd.yaml:
exists: true
contains:
- 'name: activemqartemises.{{getEnv "GROUP"}}'
- 'group: {{getEnv "GROUP"}}'
tests/verify/layer/manifests/broker_activemqartemisaddress_crd.yaml:
exists: true
contains:
- 'name: activemqartemisaddresses.{{getEnv "GROUP"}}'
tests/verify/layer/manifests/broker_activemqartemisscaledown_crd.yaml:
exists: true
contains:
- 'name: activemqartemisscaledowns.{{getEnv "GROUP"}}'
tests/verify/layer/metadata/annotations.yaml:
exists: true
contains:
- 'operators.operatorframework.io.bundle.package.v1: {{getEnv "BROKER_NAME"}}'
tests/verify/image/config.json:
exists: true
contains:
- '"architecture":"{{getEnv "ARCHITECTURE"}}"'
- '"com.redhat.component":"{{getEnv "REDHAT_COMPONENT"}}"'
- '"com.redhat.delivery.operator.bundle":"true"'
- '"com.redhat.openshift.versions":"{{getEnv "REDHAT_OPENSHIFT_VERSION"}}"'
- '"description":"{{getEnv "DESCRIPTION"}}"'
- '"io.k8s.description":"{{getEnv "K8S_DESCRIPTION"}}"'
- '"io.k8s.display-name":"{{getEnv "K8S_DISPLAY_NAME"}}"'
- '"io.openshift.tags":"{{getEnv "OPENSHIFT_TAGS"}}"'
- '"name":"{{getEnv "NAME"}}"'
- '"operators.operatorframework.io.bundle.channel.default.v1":"current"'
- '"operators.operatorframework.io.bundle.channels.v1":"current"'
- '"operators.operatorframework.io.bundle.manifests.v1":"manifests/"'
- '"operators.operatorframework.io.bundle.mediatype.v1":"registry+v1"'
- '"operators.operatorframework.io.bundle.metadata.v1":"metadata/"'
- '"operators.operatorframework.io.bundle.package.v1":"{{getEnv "BUNDLE_PACKAGE"}}"'
- '"summary":"{{getEnv "SUMMARY"}}"'
- '"version":"{{getEnv "VERSION"}}"'
43 changes: 43 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Testing bundle images

## Dependency

- [goss](https://github.com/aelsabbahy/goss)

## Configuration

1. Check all variables in [/bundle.env](../blob/master/.env)
2. Tests are located in [/goss.yaml](../blob/master/goss.yaml)
3. For running test check first also [/Makefile](../blob/master/Makefile)

## Run tests

By passing this command at the command line:

```shell
make all
```

1. Build the image
2. Unpack image
3. Unpacked files from image is tested by goss

## Add test

### Files

All files related to the image will be available under `/tests/verify/`

Start with `make all` to get these files.

Now you can add more test by running [goss](https://github.com/aelsabbahy/goss). `goss add --help`

Or by editing [/goss.yaml](../blob/master/goss.yaml) file.

## Validate existing image

Make sure [/bundle.env](../blob/master/.env) `TARGET_IMAGE=activemq-artemis-operator-bundle`

```shell
make verify-image
```
3 changes: 3 additions & 0 deletions tests/scripts/junit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

sed -i -e 's/tests\/verify\/layer//g' $1
15 changes: 15 additions & 0 deletions tests/scripts/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

mkdir -p tests/verify/{image,layer}
docker save $1 > tests/verify/image.tar
tar -xf tests/verify/image.tar -C tests/verify/image
find tests/verify/image -type f -name "layer.tar" -exec tar -xf {} -C tests/verify/layer \;
find tests/verify/layer -type f -name ".wh..wh..opq" -delete

# Predicable image config name
CONFIG_FILE="tests/verify/image/$(grep -o '"Config":"[^"]*' tests/verify/image/manifest.json | grep -o '[^"]*$')"
cp $CONFIG_FILE tests/verify/image/pre_config.json

# Encode unicode chars
echo -e $(cat tests/verify/image/pre_config.json) > tests/verify/image/config.json
rm tests/verify/image/pre_config.json