From 9d6c99351331cadc2e33b205a9ed031049128b3f Mon Sep 17 00:00:00 2001 From: Amol Ghatol Date: Tue, 19 Dec 2017 17:42:41 +0530 Subject: [PATCH] Issue #24 chore:Sunbird auth package build --- .../ansible/roles/keycloak/tasks/build.yml | 44 ++ .../ansible/roles/keycloak/tasks/main.yml | 4 + .../keycloak/templates/Msg91Creds.json.j2 | 7 + .../roles/keycloak/templates/module.xml.j2 | 10 + .../keycloak/templates/standalone-ha.xml | 571 ++++++++++++++++++ .../keycloak/templates/standalone-ha.xml-old | 556 +++++++++++++++++ .../ansible/roles/keycloak/vars/build.yml | 4 + .../pipelines/keycloak-build/Jenkinsfile.dev | 70 +++ .../pipelines/keycloak-build/deploy.sh | 27 + .../pipelines/keycloak-build/installDeps.sh | 1 + 10 files changed, 1294 insertions(+) create mode 100644 keycloak/scripts/ansible/roles/keycloak/tasks/build.yml create mode 100644 keycloak/scripts/ansible/roles/keycloak/tasks/main.yml create mode 100644 keycloak/scripts/ansible/roles/keycloak/templates/Msg91Creds.json.j2 create mode 100644 keycloak/scripts/ansible/roles/keycloak/templates/module.xml.j2 create mode 100644 keycloak/scripts/ansible/roles/keycloak/templates/standalone-ha.xml create mode 100644 keycloak/scripts/ansible/roles/keycloak/templates/standalone-ha.xml-old create mode 100644 keycloak/scripts/ansible/roles/keycloak/vars/build.yml create mode 100644 keycloak/scripts/pipelines/keycloak-build/Jenkinsfile.dev create mode 100644 keycloak/scripts/pipelines/keycloak-build/deploy.sh create mode 100644 keycloak/scripts/pipelines/keycloak-build/installDeps.sh diff --git a/keycloak/scripts/ansible/roles/keycloak/tasks/build.yml b/keycloak/scripts/ansible/roles/keycloak/tasks/build.yml new file mode 100644 index 00000000..01efff08 --- /dev/null +++ b/keycloak/scripts/ansible/roles/keycloak/tasks/build.yml @@ -0,0 +1,44 @@ +- name: Create sunbird auth directory + file: + path: sunbird_auth_{{sunbird_auth_version}} + state: directory + mode: 0755 + +- name: get the keycloak tarball + get_url: url={{keycloak_pkg_src}} dest=sunbird_auth_{{sunbird_auth_version}} force=no owner={{wildfly_user}} group={{wildfly_group}} + +- name: get the postgresql driver + get_url: url={{postgresql_driver_src}} dest=sunbird_auth_{{sunbird_auth_version}}/modules/system/layers/keycloak/org/postgresql/main force=no owner={{wildfly_user}} group={{wildfly_group}} + +- name: Clone sunbird auth repo + git: + repo: https://github.com/project-sunbird/sunbird-auth.git + dest: sunbird-auth + refspec: refs/heads/master + +- name: Build provider package + shell: cd sunbird-auth/keycloak/sms-provider && mvn package + +- name: Copy SMS OTP jar file to providers dir + copy: src=sunbird-auth/keycloak/sms-provider/target/keycloak-email-phone-autthenticator-1.0-SNAPSHOT.jar dest="sunbird_auth_{{sunbird_auth_version}}/providers" + +- name: Copy Custom Validation theme html to sunbird login theme + copy: src=sunbird-auth/keycloak/sms-provider/templates dest=sunbird_auth_{{sunbird_auth_version}}/themes/sunbird/login + +- name: Copy configuration templates to Keycloak + copy: src=sunbird-auth/keycloak/scripts/ansible/roles/keycloak/templates/ dest="sunbird_auth_{{sunbird_auth_version}}/standalone/configuration/standalone-ha.xml" + +- name: XML file + template: + src: sunbird-auth/keycloak/scripts/ansible/roles/keycloak/templates/standalone-ha.xml + dest: "sunbird_auth_{{sunbird_auth_version}}/standalone/configuration/standalone-ha.xml" + +- name: Copy module.xml + template: + src: sunbird-auth/keycloak/scripts/ansible/roles/keycloak/templates/module.xml.j2 + dest: "sunbird_auth_{{sunbird_auth_version}}/modules/system/layers/keycloak/org/postgresql/main/module.xml" + +- name: Create SMS provider configuration file + template: + src: "sunbird-auth/keycloak/scripts/ansible/roles/keycloak/Msg91Creds.json.j2" + dest: "sunbird_auth_{{sunbird_auth_version}}/bin/sms-provider/Msg91Creds.json" diff --git a/keycloak/scripts/ansible/roles/keycloak/tasks/main.yml b/keycloak/scripts/ansible/roles/keycloak/tasks/main.yml new file mode 100644 index 00000000..5a0d0c00 --- /dev/null +++ b/keycloak/scripts/ansible/roles/keycloak/tasks/main.yml @@ -0,0 +1,4 @@ +- include: build.yml + tags: + - build + diff --git a/keycloak/scripts/ansible/roles/keycloak/templates/Msg91Creds.json.j2 b/keycloak/scripts/ansible/roles/keycloak/templates/Msg91Creds.json.j2 new file mode 100644 index 00000000..d584b8be --- /dev/null +++ b/keycloak/scripts/ansible/roles/keycloak/templates/Msg91Creds.json.j2 @@ -0,0 +1,7 @@ +{ + "auth_key": "{{vault_auth_key}}", + "sender": "{{vault_sender}}", + "country": "{{vault_country}}", + "route": "{{vault_route}}", + "sms_method_type": "{{vault_sms_method_type}}" +} diff --git a/keycloak/scripts/ansible/roles/keycloak/templates/module.xml.j2 b/keycloak/scripts/ansible/roles/keycloak/templates/module.xml.j2 new file mode 100644 index 00000000..bcfe36a4 --- /dev/null +++ b/keycloak/scripts/ansible/roles/keycloak/templates/module.xml.j2 @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/keycloak/scripts/ansible/roles/keycloak/templates/standalone-ha.xml b/keycloak/scripts/ansible/roles/keycloak/templates/standalone-ha.xml new file mode 100644 index 00000000..c774e2c0 --- /dev/null +++ b/keycloak/scripts/ansible/roles/keycloak/templates/standalone-ha.xml @@ -0,0 +1,571 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + h2 + + sa + sa + + + + jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE + h2 + + sa + sa + + + + + jdbc:postgresql://thisnotwork:5432/keycloak + jdbc:postgresql://{{keycloak_postgres_host}}:5432/{{ keycloak_postgres_database }}?sslmode=require + postgresql + + 20 + + + {{ keycloak_postgres_user }} + {{ keycloak_postgres_password }} + + + true + 10000 + + + + + + + org.h2.jdbcx.JdbcDataSource + + + org.postgresql.xa.PGXADataSource + org.postgresql.ds.PGPoolingDataSource + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{groups['keycloak']|join('[7600],')}}[7600] + + 10 + 3000 + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + auth + + classpath:${jboss.home.dir}/providers/* + + master + 900 + + 2592000 + true + true + ${jboss.home.dir}/themes + + + + + + + + + + + + + jpa + + + basic + + + + + + + + + + + + + + + + + + + default + + + + + + + + ${keycloak.jta.lookup.provider:jboss} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/keycloak/scripts/ansible/roles/keycloak/templates/standalone-ha.xml-old b/keycloak/scripts/ansible/roles/keycloak/templates/standalone-ha.xml-old new file mode 100644 index 00000000..3822c71b --- /dev/null +++ b/keycloak/scripts/ansible/roles/keycloak/templates/standalone-ha.xml-old @@ -0,0 +1,556 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + h2 + + sa + sa + + + + jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE + h2 + + sa + sa + + + + + jdbc:postgresql://11.0.0.6:5432/keycloak + jdbc:postgresql://11.0.0.6:5432/keycloak + postgresql + + 20 + + + keycloak + KeyCloaK#2 + + + + true + + + + + + org.h2.jdbcx.JdbcDataSource + + + org.postgresql.xa.PGXADataSource + org.postgresql.ds.PGPoolingDataSource + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 11.0.0.4[7600],11.0.0.5[7600] + 10 + 3000 + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + auth + + classpath:${jboss.home.dir}/providers/* + + master + 900 + + 2592000 + true + true + ${jboss.home.dir}/themes + + + + + + + + + + + + + jpa + + + basic + + + + + + + + + + + + + + + + + + + default + + + + + + + + ${keycloak.jta.lookup.provider:jboss} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/keycloak/scripts/ansible/roles/keycloak/vars/build.yml b/keycloak/scripts/ansible/roles/keycloak/vars/build.yml new file mode 100644 index 00000000..7e0c487d --- /dev/null +++ b/keycloak/scripts/ansible/roles/keycloak/vars/build.yml @@ -0,0 +1,4 @@ +--- +sunbird_auth_version: 1.0v +keycloak_pkg_src: https://downloads.jboss.org/keycloak/3.2.0.Final/keycloak-3.2.0.Final.tar.gz +postgresql_driver_src: https://jdbc.postgresql.org/download/postgresql-9.4.1212.jar diff --git a/keycloak/scripts/pipelines/keycloak-build/Jenkinsfile.dev b/keycloak/scripts/pipelines/keycloak-build/Jenkinsfile.dev new file mode 100644 index 00000000..da1702bc --- /dev/null +++ b/keycloak/scripts/pipelines/keycloak-build/Jenkinsfile.dev @@ -0,0 +1,70 @@ +#!groovy + +node('build-slave') { + + currentBuild.result = "SUCCESS" + + try { + + stage('Cleanup'){ + sh('rm -rf sunbird-auth') + sh('rm -rf project-sunbird-devops') + sh('rm -rf keycloak-3.2.0.Final.tar.gz') + sh('rm -rf keycloak_build/login.tar.gz') + sh('rm -rf ansible/artifacts/sunbird/login.tar.gz') + sh('rm -rf keycloak_build') + } + + stage('Checkout'){ + checkout scm + sh('git clone https://github.com/project-sunbird/sunbird-auth.git') + + // @Todo Update the URL + // sh('git clone https://github.com/ahghatol/sunbird-devops-1.git project-sunbird-devops') + + sh('git clone https://github.com/project-sunbird/sunbird-devops project-sunbird-devops') + + // Download keycloak package and driver + sh('wget https://downloads.jboss.org/keycloak/3.2.0.Final/keycloak-3.2.0.Final.tar.gz') + sh('wget https://jdbc.postgresql.org/download/postgresql-9.4.1212.jar') + } + + stage('Build'){ + sh('mkdir -p sunbird-auth-0.1v'); + + // Login theme build + sh('cd ansible/artifacts/sunbird && tar -zcvf login.tar.gz *') + + // Sms plugin build + sh('cd sunbird-auth/keycloak/sms-provider && mvn package') + + + sh('cp keycloak-3.2.0.Final.tar.gz keycloak_build') + sh('cp postgresql-9.4.1212.jar keycloak_build') + + // Copy file to keycloak_build directory + sh('cp sunbird-auth/keycloak/sms-provider/target/keycloak-email-phone-autthenticator-1.0-SNAPSHOT.jar keycloak_build') + + // Create zip and Copy file to keycloak_build directory + sh('cd sunbird-auth/keycloak/sms-provider/templates && tar -zcvf templates.tar.gz *') + sh('cp sunbird-auth/keycloak/sms-provider/templates/templates.tar.gz keycloak_build') + + // Copy ansible template for Provider config and keycloak configuration + sh('mkdir -p keycloak_build/ansible-templates'); + + sh('cp project-sunbird-devops/ansible/roles/keycloak/templates/* keycloak_build/ansible-templates') + + sh('cp ansible/artifacts/sunbird/login.tar.gz keycloak_build') + sh('tar -zcvf keycloak_build.tar.gz keycloak_build') + } + + stage('Archive'){ + archiveArtifacts 'keycloak_build/login.tar.gz' + archiveArtifacts 'keycloak_build.tar.gz' + } + } + catch (err) { + currentBuild.result = "FAILURE" + throw err + } +} diff --git a/keycloak/scripts/pipelines/keycloak-build/deploy.sh b/keycloak/scripts/pipelines/keycloak-build/deploy.sh new file mode 100644 index 00000000..49fa3949 --- /dev/null +++ b/keycloak/scripts/pipelines/keycloak-build/deploy.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Build script +# set -o errexit + +#!/bin/sh +# Build script +# set -o errexit +set -e +e () { + echo $( echo ${1} | jq ".${2}" | sed 's/\"//g') +} +m=$(cat $METADATA_FILE) + +org=$(e "${m}" "org") +name=$(e "${m}" "name") +version=$(e "${m}" "version") + +artifactLabel=${ARTIFACT_LABEL:-bronze} +env=${ENV:-null} + +echo "artifactLabel: ${artifactLabel}" +echo "env: ${env}" +echo "org: ${org}" +echo "name: ${name}" +echo "version: ${version}" +echo "ANSIBLE_PATH: $ANSIBLE_PATH" + \ No newline at end of file diff --git a/keycloak/scripts/pipelines/keycloak-build/installDeps.sh b/keycloak/scripts/pipelines/keycloak-build/installDeps.sh new file mode 100644 index 00000000..49a927e6 --- /dev/null +++ b/keycloak/scripts/pipelines/keycloak-build/installDeps.sh @@ -0,0 +1 @@ +apk -v add ansible=2.3.0.0-r1