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

add tests for fetch_releases pulling test images from quay.io #11

Merged
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
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,55 @@ cargo run --package graph-builder -- --address 0.0.0.0 --registry https://quay.i
cargo run --package policy-engine -- --address 0.0.0.0 &
curl --verbose --header 'Accept:application/json' http://localhost:8081/v1/graph
```

## Tests
There are several ways of testing various parts of the Cincinnati stack.

### Offline

#### Language-Level
The language-level tests can be run using `cargo --test` in the repository's root directory:

```console
cargo test
```

### Online
The online tests for the graph-builder depend on a curated set of repositories to be available on *quay.io* in the *redhat* organization.
The build instructions for (re-)populating the repositories are available at *graph-builder/tests/images/build-n-push.sh*.
The script must run be run from its directory to function:

```console
cd graph-builder/tests/images
./build-n-push.sh test-*
```

#### Language-Level
The graph-builder package currently has network dependent tests which gated behind the feature `test-net` and `test-net-private`.
The latter requires setting the environment variable `CINCINNATI_TEST_CREDENTIALS_PATH` which is equivalent to *graph-builder's* `--credentials-path`.

Assuming you have access to images under the *quay.io/redhat* organization, and have an appropriate *$HOME/.docker/config.json* in place, this might work on your machine:

```console
cd graph-builder
export CINCINNATI_TEST_CREDENTIALS_PATH="$HOME/.docker/config.json"
cargo test --features test-net,test-net-private
```

### CI/CD
The *dist/* directory contains various CI/CD related files.

#### Openshift Dev
* Uses *dist/openshift-release/Dockerfile.builder* as the build container
* Runs `dist/pr_check.sh` for PRs
* Runs `dist/pr_check.sh` for successful merges to the *master* branch

For details please see [github.com/openshift/release/(...)/openshift-cincinnati-master.yaml][1].

#### App-SRE
* Uses *dist/build/Dockerfile* as a build container
* Runs `dist/pr_check.sh` for PRs
* Runs `dist/build_deploy.sh` for successful merges to the *master* branch and pushes the result to the staging environment *(URL is not yet publicly available)*

[1]: https://github.com/openshift/release/blob/master/ci-operator/config/openshift/cincinnati/openshift-cincinnati-master.yaml

5 changes: 3 additions & 2 deletions dist/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ FROM clux/muslrust:1.31.0-stable

RUN \
mkdir -p /root/.cargo/git/ && \
find /root/ -type d -exec chmod 777 {} \; && \
find /root/ -type f -exec chmod ugo+rw {} \;
mkdir -p /root/.cargo/registry/ && \
find /root/. -type d -exec chmod 777 {} \; && \
find /root/. -type f -exec chmod ugo+rw {} \;
8 changes: 4 additions & 4 deletions dist/build_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ RELEASE_OUTPUT_DIR="${PROJECT_PARENT_DIR}/release-$(date +'%Y%m%d.%H%M%S')"

function cleanup() {
set +e
if [[ ! -n "$KEEP_CARGO_OUTPUT" ]]; then
docker_cargo cargo clean
fi
docker_cargo_stop_all
if [[ ! -n "$KEEP_RELEASE_OUTPUT" ]]; then
rm -f ${RELEASE_OUTPUT_DIR}/{graph-builder,policy-engine}
rm -f ${RELEASE_OUTPUT_DIR}/$(basename ${DOCKERFILE_DEPLOY})
rmdir ${RELEASE_OUTPUT_DIR}
fi
if [[ ! -n "$KEEP_CARGO_OUTPUT" ]]; then
docker_cargo clean
fi
}
trap cleanup EXIT

docker_cargo build --release
docker_cargo cargo build --release
mkdir $RELEASE_OUTPUT_DIR
cp ${RELEASE_DIR}/{graph-builder,policy-engine} $DOCKERFILE_DEPLOY $RELEASE_OUTPUT_DIR/

Expand Down
19 changes: 12 additions & 7 deletions dist/commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,34 @@
IMAGE_BUILD="${IMAGE_BUILD:-local/muslrust:stable_custom}"
PROJECT_PARENT_DIR="${ABSOLUTE_PATH:?need ABSOLUTE_PATH set}/../"
GIT_REV="$(git rev-parse --short=7 HEAD)"
BUILD_VOLUME="build_${GIT_REV}"
if ! 2>&1 > /dev/null docker volume inspect "${BUILD_VOLUME}"; then
docker volume create "${BUILD_VOLUME}" -d local --opt type=tmpfs --opt=device=tmpfs --opt o=uid=$UID
BUILD_VOLUME_CARGO_GIT="build_cargo_git_${GIT_REV}"
BUILD_VOLUME_CARGO_REGISTRY="build_cargo_registry_${GIT_REV}"
if ! 2>&1 > /dev/null docker volume inspect "${BUILD_VOLUME_GIT}"; then
docker volume create "${BUILD_VOLUME_CARGO_GIT}" -d local --opt type=tmpfs --opt=device=tmpfs --opt o=uid=$UID
fi
if ! 2>&1 > /dev/null docker volume inspect "${BUILD_VOLUME_REGISTRY}"; then
docker volume create "${BUILD_VOLUME_CARGO_REGISTRY}" -d local --opt type=tmpfs --opt=device=tmpfs --opt o=uid=$UID
fi

IMAGE="${IMAGE:-quay.io/app-sre/cincinnati}"
IMAGE_TAG="${IMAGE_TAG:-${GIT_REV}}"

DOCKER_CARGO_LABEL="docker-cargo-$RANDOM"
DOCKER_CARGO_LABEL="docker-cargo"
function docker_cargo () {
docker run -t --rm \
--label "${DOCKER_CARGO_LABEL}" \
--user "$UID" \
--env "HOME=/root" \
-v "${BUILD_VOLUME}":/root/.cargo/registry:z \
-v "${BUILD_VOLUME_CARGO_GIT}":/root/.cargo/git:Z \
-v "${BUILD_VOLUME_CARGO_REGISTRY}":/root/.cargo/registry:Z \
-v $PROJECT_PARENT_DIR:/volume:Z \
$IMAGE_BUILD cargo ${@}
$IMAGE_BUILD "${@}"
}

function docker_cargo_stop_all() {
containers=$(docker ps --quiet --filter "label=${DOCKER_CARGO_LABEL}")
if test "${containers}"; then
docker stop ${containers} 2>&1 >/dev/null
docker rm -f ${containers} 2>&1 >/dev/null
fi
}

Expand Down
60 changes: 48 additions & 12 deletions dist/pr_check.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
#!/usr/bin/env bash

set -e
set -ex

ABSOLUTE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${ABSOLUTE_PATH}/commons.sh"
declare -A cargo_test_flags
cargo_test_flags["cincinnati"]=""
cargo_test_flags["graph-builder"]="--features test-net"
cargo_test_flags["policy-engine"]=""

ensure_build_container
declare -A executors
executors["cargo"]="execute_native"
executors["docker"]="execute_docker"

function cleanup() {
set +e
docker_cargo_stop_all
if [[ ! -n "$KEEP_CARGO_OUTPUT" ]]; then
docker_cargo clean
fi
function run_tests() {
for directory in ${!cargo_test_flags[*]}; do
(${1} /usr/bin/env bash -c "\
cd ${directory} && \
export CARGO_TARGET_DIR="../target" && \
cargo test --release ${cargo_test_flags[${directory}]} && \
:
")
done
}
trap cleanup EXIT

docker_cargo test
function execute_native() {
run_tests
}

function execute_docker() {
ABSOLUTE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${ABSOLUTE_PATH}/commons.sh"

ensure_build_container

function cleanup() {
set +e
docker_cargo_stop_all
if [[ ! -n "$KEEP_CARGO_OUTPUT" ]]; then
docker_cargo cargo clean --release
fi
}
trap cleanup EXIT

run_tests "docker_cargo"
}

for executor in ${!executors[@]}; do
if type -f $executor; then
${executors[${executor}]}
exit 0
fi
done

echo error: could not find any of "${executors[@]}" in PATH
exit 1
4 changes: 4 additions & 0 deletions graph-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ dkregistry = { git = "https://github.com/camallo/dkregistry-rs.git", rev = "b657
tokio-core = "0.1"
tokio = "0.1"
futures = "0.1"

[features]
test-net = []
test-net-private = []
27 changes: 27 additions & 0 deletions graph-builder/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extern crate cincinnati;
extern crate dkregistry;
extern crate env_logger;
extern crate flate2;
extern crate futures;
extern crate itertools;
extern crate reqwest;
extern crate semver;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate actix_web;
extern crate serde_json;
extern crate tar;
extern crate tokio;
extern crate tokio_core;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate log;
#[macro_use]
extern crate structopt;

pub mod config;
pub mod graph;
pub mod registry;
pub mod release;
24 changes: 2 additions & 22 deletions graph-builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,12 @@
// limitations under the License.

extern crate actix_web;
extern crate cincinnati;
extern crate dkregistry;
extern crate env_logger;
extern crate itertools;
#[macro_use]
extern crate failure;
extern crate flate2;
extern crate futures;
#[macro_use]
extern crate graph_builder;
extern crate log;
extern crate reqwest;
extern crate semver;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[macro_use]
extern crate structopt;
extern crate tar;
extern crate tokio;
extern crate tokio_core;

mod config;
mod graph;
mod registry;
mod release;
use graph_builder::{config, graph};

use actix_web::{http::Method, middleware::Logger, server, App};
use failure::Error;
Expand Down
2 changes: 1 addition & 1 deletion graph-builder/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::string::String;
use tar::Archive;
use tokio_core::reactor::Core;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Release {
pub source: String,
pub metadata: Metadata,
Expand Down
8 changes: 4 additions & 4 deletions graph-builder/src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use semver::Version;
use std::collections::HashMap;
use std::fmt;

#[derive(Debug, Deserialize, Clone)]
#[derive(Debug, Deserialize, Clone, PartialEq)]
pub struct Metadata {
kind: MetadataKind,
pub kind: MetadataKind,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep this private. Nobody should be looking at this field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here is that we can't create an instance of it manually if it's private:

error[E0451]: field `kind` of struct `net::quay_io::graph_builder::release::Metadata` is private                                             
  --> graph-builder/tests/net/quay_io/mod.rs:36:17                                                                                           
   |                                                                                                                                         
36 |                 kind: V0,                                                                                                               
   |                 ^^^^^^^^ field `kind` is private

What would be the simplest way to solve this? E.g., should we make a new() method for constructing one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just be able to implement the Default trait.

Copy link
Contributor Author

@steveej steveej Jan 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried your suggestion but it seems to be effectively the same as without the Default implementation. I'm getting the error:

error[E0451]: field `kind` of struct `net::quay_io::graph_builder::release::Metadata` is private
  --> graph-builder/tests/net/quay_io/mod.rs:57:19                           
   |                                                                         
57 |                 ..Default::default()                                    
   |                   ^^^^^^^^^^^^^^^^^^ field `kind` is private            
                                                                             
error: aborting due to previous error                                        
                                                                             
For more information about this error, try `rustc --explain E0451`.          
error: Could not compile `graph-builder`.                 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I was afraid of. Oh well, it's not the end of the world to make that public.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented my previously mentioned idea with the new(..) method. PTAL at 4010c8c#diff-f0669f981e48dab0c10160890afd503bR34. I don't think it's actually much worse than the default() method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed this OOB and concluded that consumers of these objects need to be able to read this field too, so making this public is a requirement anyway.

pub version: Version,

#[serde(default)]
Expand All @@ -38,12 +38,12 @@ impl fmt::Display for Metadata {
self.version,
self.previous.iter().format(", "),
self.next.iter().format(", "),
self.metadata
self.metadata,
)
}
}

#[derive(Debug, Deserialize, Clone)]
#[derive(Debug, Deserialize, Clone, PartialEq)]
pub enum MetadataKind {
#[serde(rename = "cincinnati-metadata-v0")]
V0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch as zero
COPY EMPTY .

FROM zero as one
COPY EMPTY .
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EMPTY
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM scratch as zero
LABEL layer="0"

FROM zero as one
LABEL layer="1"

FROM one as two
LABEL layer="2"

FROM two as three
LABEL layer="3"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch as zero
COPY release-metadata_0.json release-manifests/release-metadata

FROM zero as one
COPY release-metadata_1.json release-manifests/release-metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"kind": "cincinnati-metadata-v0",
"version": "0.0.0",
"metadata": {
"kind": "ooyaeh4DiSohngoh6oiW7Eecughie3ue5bes4ooHoSei6iePhohwo3no6Izeejo3wei0iph9oJee8aimuo6Ohm2Chai3yothae8oethac7Eichae8choh3ael1aidath aech3ohph7ieSheeghal2ze3ido3leeKavau4eelohgeecuch4ai0Eivoo5eiwuoDoh8ohbieZai1Dahx4aaXaikageighiPhuemi8oci0wei1FoWoh6hietho9aiyun aenahtho0Sie8aiSh1Piemeix3eic9oemezohdai0ooBohthoos3eepiginashoyiet6hoosao8CheisohW5reel6Ae4Ohphaer6En9Eem8puvie9rahquaixo8Eijie OhLai9hooMohbeiyie7chae6oe5aiweRooshae8shieshohz3shaiT6paicae9eePeu4oVaehauPeiB7nohyei1riuyiejii6Au0Aebohgi9geig8ieveeghehus2gae Iep8shoewi0ahSheiMaew0echuyaefeimeeCoowoTh6zaeGh0loo7UPhoh5iGh9quieB2sha0ci8AhmapuYaequin8ieMumaedaeGhahG9eiKeir0ju5Shohqu9Iech2 CeeChauhei1uongaimood9athip5iekeiree4guoyaik1aivi7kahKae4xon4lai8eedeetaesh1xa9eo5Johg0ohc9desel5eiyaiph9pieshah5xoo7eeXahchie2t yaino1zool2eecheedubei2eichoh7beet7deiNg1ieraihooroh9Geequoo4thuegiesaina4Meis5chee5zengeg1looweeveide6eeNei4vohCinephuVaeghugoc chai3oupaJee8ohxo8ighah2bohPah9iip5saf6oohieb7OoK3iGhei5Oom1ohr6quohchangai9moo5Wie4raiwae6pooHeesahthi1ohrie0eJ4iSh6Aiy5fohgh8w chie5ahch9Urie3nab5quae6vae8wah7Xughova9kieh0looT4ri5Oes8einoovee7lee0ahheiN0oon9aNgeeTeesh9huloh0quohDah4bongeisha8heeshaido6di Ahh3gahngoh5odoocooth3jahgh5shee4Oojee0mierap0zichooLei5Aheilaiwo1bii2Lothou6so1riepheeteeHaemi5ieTei6OhJ0Pua7ahhusitieghooghiqu eel2sie1theRiub2oow3Eim5zoopheh1aeyooTeuBahreibae4aocai3aiD9iuz2ehe8ao4OodoshahzeeWei9aif6zie0oopee1quu7buru3eegaengah3quooNgahh vahrePu3fiNiibethahhiequieVaiTel8zei0EeyohquuJ3shaPohTa1sei5Aogo8Ohnet4saegha8ohn1Ohae5Koh1ShahsuuY8socaej1iz0aiboh5Pu5Zai1ja5oh ohthake0cohz8nii6ochuf0geeb8kahjiy4chee4Eip2aeghohfoo5Ru0De6ieShoceya6ogh3oodoh1tu1YeiZ8ahPaWi4yohsh9taipa7eiS1hoos8aup4waneo7eN peeng0seen0quoochee7aaNginei3ietaiquieJe9looziexaebaiph9Igheisho5Hei6ahThov2kaicohch9eingai5zaeb0Neijahsh6mooDaiworiequeeS9beiSu geiYoh3tie1tikahd8shaeque3Kah9gahyie0Doh4Veib5auFohquoo0eenguv4zo4uvahNahsow4bohl5LaiFieVeish7faef3eu4miBii8OoquaikaivaePheeshei eiy1xoa2uo3aege9uoNgei8losh6shi8gohyieleechit9lawaiR0ahngoh4eithoh6Oos5ooh7lahgah1quahpo2sioquui8cei4ruQu6LaebahpheeSoYai8Wiiri2 eechuPhooyohmah4eeshohP6idakeichiPhov6IeYaifabeij8aj8eng9umoophai1uYepezoh9aehua3Lai1hu4quu2vohjaleephoowai4woo6eishoo2chohphieV auy3CheehohSohthe9Quei0eigh7Heid2oochohjah2Deiph5aifeeph7ieshookoo4gaeb0con3queiph9teibeiloowae2voo6FaiheixaelaiyidaeHae6via4woo AhchooyiawaeYeequi8phofae1ooGei2Sae6tutah6ohQuai5epahloh3ookeech5EeMopheap1ohGh0ohzie5ieNg8looCh3oonooj0feochahzo1ua9iobenaesh5e ShiCeeboh8keezeisaip1oosaiNg4ChaKeej9nahFi5uhoDae4chooch2TiR0woo3ohng4aimiweth0io9nahQu0Icee2chi6Aelooqu9quuFaexaeShiesh1Hi6Aila"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"kind": "cincinnati-metadata-v0",
"version": "0.0.0",
"metadata": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM scratch
COPY release-metadata release-manifests/release-metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"kind": "cincinnati-metadata-v0",
"schema": 1,
"version": "0.0.1",
"previous": ["0.0.0"],
"metadata": {
"kind": "test"
}
}
1 change: 1 addition & 0 deletions graph-builder/tests/images/test-public-manual-0.0.0
1 change: 1 addition & 0 deletions graph-builder/tests/images/test-public-manual-0.0.1
2 changes: 2 additions & 0 deletions graph-builder/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[cfg(feature = "test-net")]
mod net;
1 change: 1 addition & 0 deletions graph-builder/tests/net/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod quay_io;
Loading