-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
101 changed files
with
1,628 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
namespace: jenkins-slaves | ||
repository_url: https://github.com/redhat-cop/containers-quickstarts.git | ||
slave_repo_ref: master | ||
templates_repo_ref: v1.4.8 | ||
|
||
jenkins_slaves: | ||
build: | ||
ansible: | ||
BUILDER_IMAGE_NAME: quay.io/openshift/origin-jenkins-agent-base:4.1 | ||
DOCKERFILE_PATH: Dockerfile | ||
NAME: jenkins-slave-ansible | ||
SOURCE_CONTEXT_DIR: jenkins-slaves/jenkins-slave-ansible | ||
SOURCE_REPOSITORY_REF: "{{ slave_repo_ref }}" | ||
SOURCE_REPOSITORY_URL: "{{ repository_url }}" | ||
arachni: {} | ||
python: {} | ||
golang: {} | ||
gradle: {} | ||
mongodb: {} | ||
mvn: {} | ||
npm: | ||
BUILDER_IMAGE_NAME: openshift/jenkins-slave-base-centos7:v3.11 | ||
zap: | ||
BUILDER_IMAGE_NAME: centos:centos7 | ||
|
||
test_pipelines: | ||
deploy: | ||
ansible: | ||
NAME: jenkins-slave-ansible | ||
PIPELINE_CONTEXT_DIR: jenkins-slaves/jenkins-slave-ansible | ||
PIPELINE_FILENAME: "Jenkinsfile.test" | ||
PIPELINE_SOURCE_REPOSITORY_REF: "{{ slave_repo_ref }}" | ||
PIPELINE_SOURCE_REPOSITORY_URL: "{{ repository_url }}" | ||
golang: | ||
NAME: jenkins-slave-golang | ||
PIPELINE_CONTEXT_DIR: jenkins-slaves/jenkins-slave-golang | ||
PIPELINE_FILENAME: "Jenkinsfile.test" | ||
PIPELINE_SOURCE_REPOSITORY_REF: "{{ slave_repo_ref }}" | ||
PIPELINE_SOURCE_REPOSITORY_URL: "{{ repository_url }}" | ||
|
||
openshift_cluster_content: | ||
- object: Environment Setup | ||
content: | ||
- name: Create Projects | ||
template: "https://raw.githubusercontent.com/redhat-cop/cluster-lifecycle/v3.9.0/files/projectrequest/template.yml" | ||
action: create | ||
params_from_vars: | ||
NAMESPACE: "{{ namespace }}" | ||
NAMESPACE_DISPLAY_NAME: "{{ namespace }}" | ||
tags: | ||
- project | ||
- object: jenkins-ephemeral | ||
content: | ||
- name: jenkins-ephemeral | ||
template: 'openshift//jenkins-ephemeral' | ||
namespace: "{{ namespace }}" | ||
tags: | ||
- jenkins-ephemeral | ||
- object: jenkins-slave-nodes | ||
content: | ||
- name: jenkins-slaves | ||
template: "{{ inventory_dir }}/../.openshift/templates/jenkins-slave-generic-template.j2" | ||
params_from_vars: "{{ jenkins_slaves.build }}" | ||
namespace: "{{ namespace }}" | ||
tags: | ||
- jenkins-slaves | ||
- object: test-pipelines | ||
content: | ||
- name: Deploy ansible-slave test pipelines | ||
template: "https://raw.githubusercontent.com/redhat-cop/openshift-templates/{{ templates_repo_ref }}/jenkins-pipelines/jenkins-pipeline-template-no-ocp-triggers.yml" | ||
params_from_vars: "{{ test_pipelines.deploy.ansible }}" | ||
namespace: "{{ namespace }}" | ||
tags: | ||
- test-pipelines | ||
- ansible-slave-pipeline | ||
- name: Deploy golang-slave test pipelines | ||
template: "https://raw.githubusercontent.com/redhat-cop/openshift-templates/{{ templates_repo_ref }}/jenkins-pipelines/jenkins-pipeline-template-no-ocp-triggers.yml" | ||
params_from_vars: "{{ test_pipelines.deploy.golang }}" | ||
namespace: "{{ namespace }}" | ||
tags: | ||
- test-pipelines | ||
- golang-slave-pipeline |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.DS_Store | ||
.idea | ||
**/galaxy/ | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
kind: Template | ||
apiVersion: v1 | ||
metadata: | ||
name: Generic Jenkins Agent Template | ||
annotations: | ||
openshift.io/display-name: Generic Jenkins Agent Build Template | ||
description: "Generic build pod template pre-configured to use a jenkins agent in the | ||
same project/namespace" | ||
objects: | ||
{% if jenkins_slaves is defined %} | ||
{% for agent, params in jenkins_slaves.build.items() %} | ||
- apiVersion: v1 | ||
kind: ImageStream | ||
metadata: | ||
labels: | ||
build: {{ params.NAME | d('jenkins-slave-' + agent) }} | ||
role: jenkins-slave | ||
name: {{ params.NAME | d('jenkins-slave-' + agent) }} | ||
- apiVersion: v1 | ||
kind: BuildConfig | ||
metadata: | ||
labels: | ||
build: {{ params.NAME | d('jenkins-slave-' + agent) }} | ||
type: image | ||
name: {{ params.NAME | d('jenkins-slave-' + agent) }} | ||
spec: | ||
nodeSelector: | ||
output: | ||
to: | ||
kind: ImageStreamTag | ||
name: {{ params.NAME | d('jenkins-slave-' + agent) }}:{{ params.SLAVE_IMAGE_TAG | d('latest') }} | ||
postCommit: {} | ||
resources: {} | ||
runPolicy: Serial | ||
source: | ||
contextDir: {{ params.SOURCE_CONTEXT_DIR | d('jenkins-slaves/jenkins-slave-' + agent) }} | ||
git: | ||
ref: {{ params.SOURCE_REPOSITORY_REF | d(slave_repo_ref) | d('master') }} | ||
uri: {{ params.SOURCE_REPOSITORY_URL | d(repository_url) | d('https://github.com/redhat-cop/containers-quickstarts') }} | ||
type: Git | ||
strategy: | ||
dockerStrategy: | ||
dockerfilePath: {{ params.DOCKERFILE_PATH | d('Dockerfile') }} | ||
from: | ||
kind: DockerImage | ||
name: {{ params.BUILDER_IMAGE_NAME | d('quay.io/openshift/origin-jenkins-agent-base:4.1') }} | ||
imagePullPolicy: Always | ||
type: Docker | ||
triggers: | ||
- type: ConfigChange | ||
- type: ImageChange | ||
{% endfor %} | ||
{% endif %} | ||
... |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
dist: xenial | ||
language: python | ||
python: | ||
- "3.7" | ||
|
||
addons: | ||
apt: | ||
packages: | ||
- nodejs | ||
- npm | ||
|
||
cache: | ||
directories: | ||
- $HOME/.cache/pip | ||
|
||
env: | ||
global: | ||
- ANSIBLE_HOST_KEY_CHECKING=False | ||
- PIP_DOWNLOAD_CACHE=$HOME/.cache/pip | ||
- OC_BINARY_URL=https://mirror.openshift.com/pub/openshift-v3/clients/3.10.45/linux/oc.tar.gz | ||
- ANSIBLE_VERSION="2.7" | ||
|
||
before_install: | ||
- sudo apt-get update -qq | ||
|
||
install: | ||
- pip install -U pip | ||
- if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible; else pip install ansible~=$ANSIBLE_VERSION; fi | ||
#- pip install "ansible-lint<4.0" yamllint flake8 molecule docker "pytest<3.10" "testinfra==3.0.4" | ||
# Configure OpenShift Binary | ||
- sudo wget -qO- ${OC_BINARY_URL} | sudo tar -xvz -C /bin | ||
# Install hyperlink checker | ||
- npm install -g markdown-link-check | ||
|
||
before_script: | ||
# Check for dead-links in the docs | ||
- find . -type f -name "*.md" -exec markdown-link-check --quiet --config linkcheck-config.json {} \; | ||
# Configure Docker | ||
- sudo service docker stop | ||
- sudo mkdir -p /etc/docker | ||
- echo '{"insecure-registries":["172.30.0.0/16"]}' | sudo tee /etc/docker/daemon.json | ||
- sudo service docker start | ||
# Launch OpenShift Environment | ||
- _test/setup.sh cluster_up | ||
# Run Applier to provision all of the builds | ||
- _test/setup.sh applier cqci-${TRAVIS_JOB_ID} ${TRAVIS_REPO_SLUG} ${TRAVIS_BRANCH} | ||
|
||
script: | ||
# Test to ensure that builds all succeed | ||
- _test/setup.sh test cqci-${TRAVIS_JOB_ID} ${TRAVIS_REPO_SLUG} ${TRAVIS_BRANCH} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Testing this Repository | ||
|
||
Containers-quickstarts is outfitted with a set of automated tests. This document deals with writing and running tests for your contributions. | ||
|
||
## Tesing Architecture | ||
|
||
We use Travis-CI to test this repo. You can start to examine how we set up and invoke tests by examining the [.travis.yml](.travis.yml) file. | ||
|
||
We have split the architect of the tests up into 4 phases: | ||
|
||
1. Environment setup and prereqs | ||
2. Launching an openshift test cluster, using `oc cluster up` | ||
3. Running [openshift-applier](https://github.com/redhat-cop/openshift-applier) to deploy a set of builds | ||
4. Checking `.status.phase` in each build to validate all builds end with in a `Completed` state. | ||
|
||
The 3 phases of testing are captured in a [script](_test/setup.sh) that is executed by travis, but can also be run locally in order to validate your changes before committing code. | ||
|
||
## Writing Tests | ||
|
||
Adding a new test to our CI is as simple as adding one or more `BuildConfig`s to the [global Applier inventory](.applier). Currently we deploy all assets into a single namespace to make all builds "discoverable" by our test scripts. | ||
|
||
Every build that gets created will then be executed, and the test script will wait until all builds complete, and ensure that none of them fail. | ||
|
||
## Running the tests locally. | ||
|
||
For convenience, a script is provided that allows users to run tests locally. The script usage is as follows: | ||
|
||
``` | ||
./_test/setup.sh <applier|test> [project name] [repo slug] [branch name] | ||
``` | ||
|
||
For example, to test against master: | ||
|
||
``` | ||
oc login ... && \ | ||
./_test/setup.sh applier && \ | ||
./_test/setup.sh test | ||
``` | ||
|
||
To test against an alternate fork/branch: | ||
|
||
``` | ||
oc login ... && \ | ||
./_test/setup.sh applier etsauer-feature123 etsauer/containers-quickstarts feature123 && \ | ||
./_test/setup.sh test etsauer-feature123 etsauer/containers-quickstarts feature123 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/bin/bash | ||
trap "exit 1" TERM | ||
export TOP_PID=$$ | ||
NAMESPACE="${2:-containers-quickstarts-tests}" | ||
TRAVIS_REPO_SLUG="${3:-redhat-cop/containers-quickstarts}" | ||
TRAVIS_BRANCH="${4:-master}" | ||
|
||
cluster_up() { | ||
set +e | ||
built=false | ||
while true; do | ||
if [ -z $IP_ADDR ]; then | ||
DEV=$(ip link | awk '/state UP/{ gsub(":", ""); print $2}') | ||
IP_ADDR=$(ip addr show $DEV | awk '/inet /{ gsub("/.*", ""); print $2}') | ||
fi | ||
oc cluster up --public-hostname=${IP_ADDR} --routing-suffix=${IP_ADDR}.nip.io --base-dir=$HOME/ocp | ||
if [ "$?" -eq 0 ]; then | ||
built=true | ||
break | ||
fi | ||
echo "Retrying oc cluster up after failure" | ||
oc cluster down | ||
sleep 5 | ||
done | ||
echo "OpenShift Cluster Running" | ||
} | ||
|
||
applier() { | ||
echo "${TRAVIS_BRANCH}" | ||
echo "${TRAVIS_REPO_SLUG}" | ||
ansible-galaxy install -r requirements.yml -p galaxy --force | ||
ansible-playbook -i .applier/ galaxy/openshift-applier/playbooks/openshift-cluster-seed.yml -e namespace=${NAMESPACE} -e slave_repo_ref=${TRAVIS_BRANCH} -e repository_url=https://github.com/${TRAVIS_REPO_SLUG}.git | ||
} | ||
|
||
get_build_phases() { | ||
phase=$1 | ||
result=$(oc get builds -o jsonpath="{.items[?(@.status.phase==\"${phase}\")].metadata.name}" -n $NAMESPACE) || kill -s TERM $TOP_PID | ||
echo ${result} | wc -w | ||
} | ||
|
||
test() { | ||
# Make sure we're logged in, and we've found at least one build to test. | ||
oc status > /dev/null || echo "Please log in before running tests." || exit 1 | ||
if [ $(oc get builds -n ${NAMESPACE} --no-headers | grep -c .) -lt 1 ]; then | ||
echo "Did not find any builds, make sure you've passed the proper arguments." | ||
exit 1 | ||
fi | ||
|
||
echo "Ensure all Builds are executed..." | ||
for pipeline in $(oc get bc -n ${NAMESPACE} -o jsonpath='{.items[*].metadata.name}'); do | ||
if [ "$(oc get build -n ${NAMESPACE} -o jsonpath="{.items[?(@.metadata.annotations.openshift\.io/build-config\.name==\"${pipeline}\")].metadata.name}")" == "" ]; then | ||
oc start-build ${pipeline} -n ${NAMESPACE} | ||
fi | ||
done | ||
|
||
echo "Waiting for all builds to start..." | ||
while [[ "$(get_build_phases "New")" -ne 0 || $(get_build_phases "Pending") -ne 0 ]]; do | ||
echo -ne "New Builds: $(get_build_phases "New"), Pending Builds: $(get_build_phases "Pending")\r" | ||
sleep 1 | ||
done | ||
|
||
echo "Waiting for all builds to complete..." | ||
while [ $(get_build_phases "Running") -ne 0 ]; do | ||
echo -ne "Running Builds: $(get_build_phases "Running")\r" | ||
sleep 1 | ||
done | ||
|
||
echo "Check to see how many builds Failed" | ||
if [ $(get_build_phases "Failed") -ne 0 ]; then | ||
echo "Some builds failed. Printing Report" | ||
oc get builds -n $NAMESPACE -o custom-columns=NAME:.metadata.name,TYPE:.spec.strategy.type,FROM:.spec.source.type,STATUS:.status.phase,REASON:.status.reason | ||
exit 1 | ||
fi | ||
|
||
echo "Tests Completed Successfully!" | ||
} | ||
|
||
# Process arguments | ||
case $1 in | ||
cluster_up) | ||
cluster_up | ||
;; | ||
applier) | ||
applier | ||
;; | ||
test) | ||
test | ||
;; | ||
*) | ||
echo "Not an option" | ||
exit 1 | ||
esac |
Oops, something went wrong.