diff --git a/support/docker/Dockerfile b/support/docker/Dockerfile new file mode 100644 index 0000000..f9eed6c --- /dev/null +++ b/support/docker/Dockerfile @@ -0,0 +1,26 @@ +FROM centos:7 + +MAINTAINER Nicolas Masse + +LABEL io.k8s.display-name="Ansible role nmasse-itix.threescale-cicd" \ + io.k8s.description="Deploys an API to 3scale API Management." \ + io.openshift.tags="ansible,api,3scale" + +ARG GIT_REPOSITORY=https://github.com/nmasse-itix/threescale-cicd.git +ARG GIT_BRANCH=master + +RUN yum install -y centos-release-scl && \ + yum-config-manager --enable rhel-server-rhscl-7-rpms && \ + yum install -y ansible git python27-python-pip && \ + scl enable python27 "pip install --install-option='--install-purelib=/usr/lib/python2.7/site-packages/' jinja2" && \ + yum clean all && \ + rm -rf /var/cache/yum && \ + mkdir -p /opt/ansible/threescale-cicd && \ + git clone -b ${GIT_BRANCH} -- ${GIT_REPOSITORY} /opt/ansible/threescale-cicd && \ + cd /opt/ansible/threescale-cicd/support/docker && \ + ansible-playbook install.yaml + +WORKDIR /opt/ansible/threescale-cicd/support/docker + +ENTRYPOINT [ "/usr/bin/ansible-playbook", "deploy-api.yaml" ] +CMD [ ] diff --git a/support/docker/ansible.cfg b/support/docker/ansible.cfg new file mode 120000 index 0000000..5495ae5 --- /dev/null +++ b/support/docker/ansible.cfg @@ -0,0 +1 @@ +../../ansible.cfg \ No newline at end of file diff --git a/support/docker/deploy-api.yaml b/support/docker/deploy-api.yaml new file mode 120000 index 0000000..e272666 --- /dev/null +++ b/support/docker/deploy-api.yaml @@ -0,0 +1 @@ +../jenkins/deploy-api.yaml \ No newline at end of file diff --git a/support/docker/install.yaml b/support/docker/install.yaml new file mode 100644 index 0000000..3e50a5b --- /dev/null +++ b/support/docker/install.yaml @@ -0,0 +1,10 @@ + +- name: Install the pre-requisites + hosts: localhost + gather_facts: no + vars: + ansible_connection: local + tasks: + - import_role: + name: 'nmasse-itix.threescale-cicd' + tasks_from: 'install_prerequisites' diff --git a/support/docker/roles/nmasse-itix.threescale-cicd b/support/docker/roles/nmasse-itix.threescale-cicd new file mode 120000 index 0000000..a8a4f8c --- /dev/null +++ b/support/docker/roles/nmasse-itix.threescale-cicd @@ -0,0 +1 @@ +../../.. \ No newline at end of file diff --git a/support/openshift/Dockerfile b/support/openshift/Dockerfile new file mode 100644 index 0000000..fd342a5 --- /dev/null +++ b/support/openshift/Dockerfile @@ -0,0 +1,26 @@ +FROM openshift/origin-base:v3.11 + +MAINTAINER Nicolas Masse + +LABEL io.k8s.display-name="OpenShift Custom builder for Ansible role nmasse-itix.threescale-cicd" \ + io.k8s.description="Deploys an API to 3scale API Management." \ + io.openshift.tags="builder,3scale" + +ARG THREESCALE_CICD_GIT_REPOSITORY=https://github.com/nmasse-itix/threescale-cicd.git +ARG THREESCALE_CICD_GIT_BRANCH=master + +RUN yum install -y centos-release-scl && \ + yum-config-manager --enable rhel-server-rhscl-7-rpms && \ + yum install -y ansible git python27-python-pip && \ + scl enable python27 "pip install --install-option='--install-purelib=/usr/lib/python2.7/site-packages/' jinja2" && \ + yum clean all && \ + rm -rf /var/cache/yum && \ + mkdir -p /opt/ansible/threescale-cicd && \ + git clone -b ${THREESCALE_CICD_GIT_BRANCH} -- ${THREESCALE_CICD_GIT_REPOSITORY} /opt/ansible/threescale-cicd && \ + cd /opt/ansible/threescale-cicd/support/openshift && \ + ansible-playbook install.yaml + +WORKDIR /opt/ansible/threescale-cicd/support/openshift + +ENTRYPOINT [ "/usr/bin/ansible-playbook", "deploy-api.yaml" ] +CMD [ ] diff --git a/support/openshift/ansible.cfg b/support/openshift/ansible.cfg new file mode 120000 index 0000000..5495ae5 --- /dev/null +++ b/support/openshift/ansible.cfg @@ -0,0 +1 @@ +../../ansible.cfg \ No newline at end of file diff --git a/support/openshift/deploy-api.yaml b/support/openshift/deploy-api.yaml new file mode 100644 index 0000000..2ab503d --- /dev/null +++ b/support/openshift/deploy-api.yaml @@ -0,0 +1,74 @@ +--- + +- name: Prepare the Ansible inventory + hosts: localhost + gather_facts: no + vars: + threescale_portal_hostname: 'lookup(''file'', ''/tmp/secrets/hostname'')' + threescale_cicd_access_token: 'lookup(''file'', ''/tmp/secrets/access_token'')' + tasks: + - assert: + that: threescale_portal_hostname is defined + msg: > + Please pass the hostname of your 3scale Admin Portal in "hostname" key of the + "3scale-admin-portal" secret. + + - assert: + that: threescale_cicd_access_token is defined + msg: > + Please pass the access token of your 3scale Admin Portal in "access_token" key of the + "3scale-admin-portal" secret. + + # Generate dynamically a one host inventory + - add_host: + hostname: '{{ threescale_portal_hostname }}' + groups: + - threescale + threescale_cicd_access_token: '{{ threescale_cicd_access_token }}' + +- name: Deploy an API to 3scale + hosts: threescale + gather_facts: no + vars: + build: '{{ lookup(''env'', ''BUILD'')|from_json }}' + git_repository: '{{ build.spec.source.git.uri }}' + git_context_dir: '{{ build.spec.source.git.contextDir|default('''') }}' + git_ref: '{{ build.spec.source.git.ref|default(''master'') }}' + ansible_connection: local + parameter_whitelist: + - threescale_cicd_openapi_file + - threescale_cicd_openapi_file_format + - threescale_cicd_api_system_name + - threescale_cicd_api_base_system_name + - threescale_cicd_wildcard_domain + - threescale_cicd_api_basepath + - threescale_cicd_api_backend_hostname + - threescale_cicd_api_backend_scheme + - threescale_cicd_private_base_url + - threescale_cicd_apicast_policies_cors + - threescale_cicd_openapi_smoketest_operation + - threescale_cicd_api_environment_name + - threescale_cicd_validate_openapi + - threescale_cicd_apicast_sandbox_endpoint + - threescale_cicd_apicast_production_endpoint + threescale_cicd_sso_issuer_endpoint: 'lookup(''file'', ''/tmp/secrets/sso_issuer_endpoint'')' + pre_tasks: + + - name: Clone the git repo containing the API Definition + git: + repo: '{{ git_repository }}' + dest: '{{ playbook_dir }}/api' + version: '{{ git_ref }}' + + - name: Accept threescale_cicd_* variables from environment variables + set_fact: + '{{ item|lower }}': '{{ lookup(''env'', item|upper) }}' + with_items: '{{ parameter_whitelist }}' + when: 'lookup(''env'', item|upper)|length > 0' + + - name: Add the contextDir to the OpenAPI file path + set_fact: + threescale_cicd_openapi_file: '{{ playbook_dir }}/api/{{ git_context_dir }}/{{ threescale_cicd_openapi_file }}' + + roles: + - nmasse-itix.threescale-cicd diff --git a/support/openshift/install.yaml b/support/openshift/install.yaml new file mode 120000 index 0000000..4e7bb63 --- /dev/null +++ b/support/openshift/install.yaml @@ -0,0 +1 @@ +../docker/install.yaml \ No newline at end of file diff --git a/support/openshift/roles/nmasse-itix.threescale-cicd b/support/openshift/roles/nmasse-itix.threescale-cicd new file mode 120000 index 0000000..a8a4f8c --- /dev/null +++ b/support/openshift/roles/nmasse-itix.threescale-cicd @@ -0,0 +1 @@ +../../.. \ No newline at end of file