From 5f6a254ce9426a9939e46d8c9576e14a82a2a5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Mass=C3=A9?= Date: Tue, 18 Jun 2019 16:59:45 +0200 Subject: [PATCH] improve the pipeline --- README.md | 14 +++- testcase-01/Jenkinsfile | 26 ++++--- testcase-01/setup.yaml | 10 ++- testcase-01/swagger.json | 158 --------------------------------------- testcase-01/swagger.yaml | 108 ++++++++++++++++++++++++++ 5 files changed, 144 insertions(+), 172 deletions(-) delete mode 100644 testcase-01/swagger.json create mode 100644 testcase-01/swagger.yaml diff --git a/README.md b/README.md index ef11f89..78f18e3 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,21 @@ ```sh 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 ``` +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 -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 @@ -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 | | [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 | - diff --git a/testcase-01/Jenkinsfile b/testcase-01/Jenkinsfile index 2fbe5aa..50745ad 100644 --- a/testcase-01/Jenkinsfile +++ b/testcase-01/Jenkinsfile @@ -1,10 +1,12 @@ #!groovy -library identifier: '3scale-toolbox-jenkins@master', +library identifier: '3scale-toolbox-jenkins@add-features', 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 testApplicationCredentials = null node() { stage('Checkout Source') { @@ -14,7 +16,8 @@ node() { stage("Prepare") { service = toolbox.prepareThreescaleService( 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], service: [:], applicationPlans: [ @@ -39,21 +42,24 @@ node() { stage("Create an Application") { def testApplication = [ 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) } stage("Run integration tests") { // To run the integration tests when using APIcast SaaS instances, we need // to fetch the proxy definition to extract the staging public url - def proxy = service.readProxy() - sh '''set -xe - curl ${proxy.sandbox_endpoint}/beers - # TODO - ''' + def proxy = service.readProxy("sandbox") + sh """set -e +x + curl -f -w "ListBeers: %{http_code}\n" -o /dev/null -s ${proxy.sandbox_endpoint}/api/beer -H 'api-key: ${testApplicationCredentials.userKey}' + 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") { diff --git a/testcase-01/setup.yaml b/testcase-01/setup.yaml index 44d2642..79bbb74 100644 --- a/testcase-01/setup.yaml +++ b/testcase-01/setup.yaml @@ -23,12 +23,20 @@ objects: value: ${NAMESPACE} - name: TARGET_INSTANCE value: ${TARGET_INSTANCE} + - name: DEVELOPER_ACCOUNT_ID + value: ${DEVELOPER_ACCOUNT_ID} + - name: PRIVATE_BASE_URL + value: ${PRIVATE_BASE_URL} parameters: - name: SECRET_NAME value: 3scale-toolbox - name: NAMESPACE value: api-lifecycle - name: TARGET_INSTANCE - value: nmasse-redhat + value: 3scale-saas - name: GIT_REPO value: https://github.com/nmasse-itix/API-Lifecycle-Mockup.git +- name: DEVELOPER_ACCOUNT_ID + required: true +- name: PRIVATE_BASE_URL + required: true diff --git a/testcase-01/swagger.json b/testcase-01/swagger.json deleted file mode 100644 index 2e3dd02..0000000 --- a/testcase-01/swagger.json +++ /dev/null @@ -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": [] - } - ] -} diff --git a/testcase-01/swagger.yaml b/testcase-01/swagger.yaml new file mode 100644 index 0000000..88db39a --- /dev/null +++ b/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: []