Browse Source

improve the pipeline

master
Nicolas Massé 7 years ago
parent
commit
5f6a254ce9
  1. 14
      README.md
  2. 26
      testcase-01/Jenkinsfile
  3. 10
      testcase-01/setup.yaml
  4. 158
      testcase-01/swagger.json
  5. 108
      testcase-01/swagger.yaml

14
README.md

@ -4,12 +4,21 @@
```sh ```sh
oc project api-lifecycle oc project api-lifecycle
3scale remote add $NAME https://$TOKEN@$TENANT.3scale.net/ 3scale remote add 3scale-saas https://$TOKEN@$TENANT.3scale.net/
3scale remote add 3scale-onprem https://$TOKEN@$TENANT.$DOMAIN/
oc create secret generic 3scale-toolbox --from-file=$HOME/.3scalerc.yaml oc create secret generic 3scale-toolbox --from-file=$HOME/.3scalerc.yaml
``` ```
Deploy the API Backend:
```sh
oc project api-lifecycle
oc new-app -i openshift/redhat-openjdk18-openshift:1.4 https://github.com/microcks/api-lifecycle.git --context-dir=/beer-catalog-demo/api-implementation --name=beer-catalog
oc expose svc/beer-catalog --hostname=beer-catalog.app.itix.fr
```
```sh ```sh
oc process -f testcase-01/setup.yaml |oc create -f - oc process -f testcase-01/setup.yaml -p DEVELOPER_ACCOUNT_ID=2445582535751 -p PRIVATE_BASE_URL=http://beer-catalog.app.itix.fr |oc create -f -
``` ```
## Testcases ## Testcases
@ -23,4 +32,3 @@ oc process -f testcase-01/setup.yaml |oc create -f -
| [05](testcase-05/) | YAML | API Key | Self-Managed, on-premises | URL rewriting | | [05](testcase-05/) | YAML | API Key | Self-Managed, on-premises | URL rewriting |
| [06](testcase-06/) | YAML | API Key | 3 envs on 1 tenant, Self-managed | - | | [06](testcase-06/) | YAML | API Key | 3 envs on 1 tenant, Self-managed | - |
| [07](testcase-07/) | JSON | OIDC | 3 envs on 3 tenants, on-premises | CORS, URL rewriting | | [07](testcase-07/) | JSON | OIDC | 3 envs on 3 tenants, on-premises | CORS, URL rewriting |

26
testcase-01/Jenkinsfile

@ -1,10 +1,12 @@
#!groovy #!groovy
library identifier: '3scale-toolbox-jenkins@master', library identifier: '3scale-toolbox-jenkins@add-features',
retriever: modernSCM([$class: 'GitSCMSource', retriever: modernSCM([$class: 'GitSCMSource',
remote: 'https://github.com/nmasse-itix/3scale-toolbox-jenkins.git']) remote: 'https://github.com/rh-integration/3scale-toolbox-jenkins.git'
traits: [[$class: 'jenkins.plugins.git.traits.BranchDiscoveryTrait']]])
def service = null def service = null
def testApplicationCredentials = null
node() { node() {
stage('Checkout Source') { stage('Checkout Source') {
@ -14,7 +16,8 @@ node() {
stage("Prepare") { stage("Prepare") {
service = toolbox.prepareThreescaleService( service = toolbox.prepareThreescaleService(
openapi: [filename: "testcase-01/swagger.json"], openapi: [filename: "testcase-01/swagger.json"],
environment: [baseSystemName: toolbox.generateRandomBaseSystemName()], environment: [ baseSystemName: toolbox.generateRandomBaseSystemName(),
privateBaseUrl: params.PRIVATE_BASE_URL ],
toolbox: [openshiftProject: params.NAMESPACE, destination: params.TARGET_INSTANCE, secretName: params.SECRET_NAME], toolbox: [openshiftProject: params.NAMESPACE, destination: params.TARGET_INSTANCE, secretName: params.SECRET_NAME],
service: [:], service: [:],
applicationPlans: [ applicationPlans: [
@ -39,21 +42,24 @@ node() {
stage("Create an Application") { stage("Create an Application") {
def testApplication = [ def testApplication = [
name: "my-test-app", name: "my-test-app",
description: "This is used for tests" description: "This is used for tests",
applicationPlan: "test",
accountId: params.DEVELOPER_ACCOUNT_ID
] ]
def testApplicationCredentials = toolbox.getDefaultApplicationCredentials(service, testApplication.name) testApplicationCredentials = toolbox.getDefaultApplicationCredentials(service, testApplication.name)
service.applyApplication(testApplication + testApplicationCredentials) service.applyApplication(testApplication + testApplicationCredentials)
} }
stage("Run integration tests") { stage("Run integration tests") {
// To run the integration tests when using APIcast SaaS instances, we need // To run the integration tests when using APIcast SaaS instances, we need
// to fetch the proxy definition to extract the staging public url // to fetch the proxy definition to extract the staging public url
def proxy = service.readProxy() def proxy = service.readProxy("sandbox")
sh '''set -xe sh """set -e +x
curl ${proxy.sandbox_endpoint}/beers curl -f -w "ListBeers: %{http_code}\n" -o /dev/null -s ${proxy.sandbox_endpoint}/api/beer -H 'api-key: ${testApplicationCredentials.userKey}'
# TODO curl -f -w "GetBeer: %{http_code}\n" -o /dev/null -s ${proxy.sandbox_endpoint}/api/beer/Weissbier -H 'api-key: ${testApplicationCredentials.userKey}'
''' curl -f -w "GetBeer: %{http_code}\n" -o /dev/null -s ${proxy.sandbox_endpoint}/api/beer/findByStatus/available -H 'api-key: ${testApplicationCredentials.userKey}'
"""
} }
stage("Promote to production") { stage("Promote to production") {

10
testcase-01/setup.yaml

@ -23,12 +23,20 @@ objects:
value: ${NAMESPACE} value: ${NAMESPACE}
- name: TARGET_INSTANCE - name: TARGET_INSTANCE
value: ${TARGET_INSTANCE} value: ${TARGET_INSTANCE}
- name: DEVELOPER_ACCOUNT_ID
value: ${DEVELOPER_ACCOUNT_ID}
- name: PRIVATE_BASE_URL
value: ${PRIVATE_BASE_URL}
parameters: parameters:
- name: SECRET_NAME - name: SECRET_NAME
value: 3scale-toolbox value: 3scale-toolbox
- name: NAMESPACE - name: NAMESPACE
value: api-lifecycle value: api-lifecycle
- name: TARGET_INSTANCE - name: TARGET_INSTANCE
value: nmasse-redhat value: 3scale-saas
- name: GIT_REPO - name: GIT_REPO
value: https://github.com/nmasse-itix/API-Lifecycle-Mockup.git value: https://github.com/nmasse-itix/API-Lifecycle-Mockup.git
- name: DEVELOPER_ACCOUNT_ID
required: true
- name: PRIVATE_BASE_URL
required: true

158
testcase-01/swagger.json

@ -1,158 +0,0 @@
{
"swagger": "2.0",
"info": {
"title": "Beer Catalog API",
"description": "An API for querying beer catalog of Acme Inc.",
"contact": {
"name": "Laurent Broudoux",
"url": "http://github.com/lbroudoux",
"email": "laurent.broudoux@gmail.com"
},
"license": {
"name": "MIT License",
"url": "https://opensource.org/licenses/MIT"
},
"version": "0.9"
},
"host": "beer-catalog.app.itix.fr",
"schemes": [ "http" ],
"basePath": "/api",
"paths": {
"/beer/{name}": {
"get": {
"tags": [
"beer"
],
"summary": "Get beer having name",
"description": "Get beer having name",
"operationId": "GetBeer",
"responses": {
"200": {
"description": "Beer having requested name",
"schema": {
"$ref": "#/definitions/Beer"
}
}
}
},
"parameters": [
{
"name": "name",
"in": "path",
"description": "Name of beer to retrieve",
"required": true,
"type": "string"
}
]
},
"/beer/findByStatus/{status}": {
"get": {
"tags": [
"beer"
],
"summary": "Get beers having status",
"description": "Get beers having status",
"operationId": "FindBeersByStatus",
"responses": {
"200": {
"description": "List of beers having requested status",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Beer"
}
}
}
}
},
"parameters": [
{
"name": "status",
"in": "path",
"description": "Status of beers to retrieve",
"required": true,
"type": "string"
},
{
"name": "page",
"in": "query",
"description": "Number of page to retrieve",
"type": "number"
}
]
},
"/beer": {
"get": {
"tags": [
"beer"
],
"summary": "List beers within catalog",
"description": "List beers within catalog",
"operationId": "ListBeers",
"responses": {
"200": {
"description": "Array of beers",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Beer"
}
}
}
}
},
"parameters": [
{
"name": "page",
"in": "query",
"description": "Number of page to retrieve",
"type": "number"
}
]
}
},
"tags": [
{
"name": "beer",
"description": "Beer resource"
}
],
"definitions": {
"Beer": {
"properties": {
"name": {
"description": "Name of Beer",
"type": "string"
},
"country": {
"description": "Origin country of Beer",
"type": "string"
},
"type": {
"description": "Type of Beer",
"type": "string"
},
"rating": {
"description": "Rating from customers",
"type": "number"
},
"status": {
"description": "Stock status",
"type": "string"
}
}
}
},
"securityDefinitions": {
"api-key": {
"type": "apiKey",
"name": "api-key",
"in": "header"
}
},
"security": [
{
"api-key": []
}
]
}

108
testcase-01/swagger.yaml

@ -0,0 +1,108 @@
swagger: '2.0'
info:
title: 'Beer Catalog API'
description: 'An API for querying beer catalog of Acme Inc.'
contact:
name: 'Laurent Broudoux'
url: 'http://github.com/lbroudoux'
email: laurent.broudoux@gmail.com
license:
name: 'MIT License'
url: 'https://opensource.org/licenses/MIT'
version: '0.9'
paths:
'/beer/{name}':
get:
tags:
- beer
summary: 'Get beer having name'
description: 'Get beer having name'
operationId: GetBeer
responses:
'200':
description: 'Beer having requested name'
schema:
$ref: '#/definitions/Beer'
parameters:
-
name: name
in: path
description: 'Name of beer to retrieve'
required: true
type: string
'/beer/findByStatus/{status}':
get:
tags:
- beer
summary: 'Get beers having status'
description: 'Get beers having status'
operationId: FindBeersByStatus
responses:
'200':
description: 'List of beers having requested status'
schema:
type: array
items:
$ref: '#/definitions/Beer'
parameters:
-
name: status
in: path
description: 'Status of beers to retrieve'
required: true
type: string
-
name: page
in: query
description: 'Number of page to retrieve'
type: number
/beer:
get:
tags:
- beer
summary: 'List beers within catalog'
description: 'List beers within catalog'
operationId: ListBeers
responses:
'200':
description: 'Array of beers'
schema:
type: array
items:
$ref: '#/definitions/Beer'
parameters:
-
name: page
in: query
description: 'Number of page to retrieve'
type: number
tags:
-
name: beer
description: 'Beer resource'
definitions:
Beer:
properties:
name:
description: 'Name of Beer'
type: string
country:
description: 'Origin country of Beer'
type: string
type:
description: 'Type of Beer'
type: string
rating:
description: 'Rating from customers'
type: number
status:
description: 'Stock status'
type: string
securityDefinitions:
api-key:
type: apiKey
name: api-key
in: header
security:
-
api-key: []
Loading…
Cancel
Save