diff --git a/ansible/roles/offline-installer/tasks/main.yml b/ansible/roles/offline-installer/tasks/main.yml index c24130f0417ad729933357cd581284cd85dd2424..31bc47f6272eecbe98c751fbf309448bce5288e7 100644 --- a/ansible/roles/offline-installer/tasks/main.yml +++ b/ansible/roles/offline-installer/tasks/main.yml @@ -19,7 +19,6 @@ dest: "{{offline_repo_location}}/offline-installer-repo/{{item}}" mode: '0755' with_items: - - setupOfflineInstaller.sh - build.sh - envfile - 32-bit-prerequisite.sh @@ -32,6 +31,15 @@ recurse: yes when: uploadInstaller is not defined +- name: copy the installer script file and build script for building offline installer + template: + src: "{{item}}.j2" + dest: "{{offline_repo_location}}/offline-installer-repo/{{item}}" + mode: '0755' + with_items: + - setupOfflineInstaller.sh + when: uploadInstaller is not defined + - name: upload to azure include: uploadToAzure.yml when: uploadInstaller is defined @@ -39,3 +47,4 @@ - name: Delete offline installer folder if any issue include: remove.yml when: removeOfflineInstallerFolder is defined + diff --git a/ansible/roles/offline-installer/tasks/uploadToAzure.yml b/ansible/roles/offline-installer/tasks/uploadToAzure.yml index 0e3323837da8999cc3f838d518e166e2afd01826..8ffa232eac000a8b0ed5e43ee7b247d788647a84 100644 --- a/ansible/roles/offline-installer/tasks/uploadToAzure.yml +++ b/ansible/roles/offline-installer/tasks/uploadToAzure.yml @@ -4,6 +4,58 @@ AZURE_STORAGE_ACCOUNT: "{{sunbird_offline_azure_storage_account}}" AZURE_STORAGE_KEY: "{{sunbird_offline_azure_storage_key}}" +- name: Get the environment name for the artifact name + shell: "cat {{offline_repo_location}}/offline-installer-repo/src/env.json | jq -r '.APP_NAME'" + register: env_name + +- name: Display the environment name of the installer + debug: + msg: "{{env_name.stdout}}" + +- name: Create a variable to inject environment name to upload to azure blob + set_fact: + environment_name: "{{ env_name.stdout }}" + +- name: Get the version from the package.json file + shell: "cat {{offline_repo_location}}/offline-installer-repo/src/package.json | jq -r '.version'" + register: version + +- name: Display the version number of the installer + debug: + msg: "{{version.stdout}}" + +- name: Create a variable to inject version in the template + set_fact: + installer_version: "{{ version.stdout }}" + +- name: get the directory name + shell: "ls {{offline_repo_location}}/offline-installer-repo/offline_artifacts/" + register: folderName + +- debug: + msg: "{{folderName.stdout}}" + +- name: set the folder name to copy the artifacts + set_fact: + time: "{{folderName.stdout}}" + +- name: copy the installer artifacts and metadata files to upload it to azure blob and generate latest.json file + template: + src: "{{item}}.j2" + dest: "{{offline_repo_location}}/offline-installer-repo/{{item}}" + mode: '0755' + with_items: + - artifacts.sh + - metadata.sh + +- name: copy the artifacts and generate the metadata file + shell: "bash {{offline_repo_location}}/offline-installer-repo/{{item}}" + args: + chdir: "{{offline_repo_location}}/offline-installer-repo/" + with_items: + - artifacts.sh + - metadata.sh + - name: Upload to azure blob storage command: az storage blob upload-batch --destination {{offline_installer_container_name}} --source "offline_artifacts" args: @@ -14,17 +66,38 @@ async: 60 poll: 10 -- name: get the directory name - shell: "ls {{offline_repo_location}}/offline-installer-repo/offline_artifacts/" - register: folderName - -- debug: - msg: "{{folderName.stdout}}" +- name: Upload to latest.json file to blob + command: az storage blob upload-batch --destination "{{offline_installer_container_name}}/latest" --source "{{folderName.stdout}}" + args: + chdir: "{{offline_repo_location}}/offline-installer-repo/offline_artifacts/" + environment: + AZURE_STORAGE_ACCOUNT: "{{sunbird_offline_azure_storage_account}}" + AZURE_STORAGE_KEY: "{{sunbird_offline_azure_storage_key}}" + async: 60 + poll: 10 - name: Create a zip of the folder to archieve the artifact archive: path: - "{{offline_repo_location}}/offline-installer-repo/offline_artifacts/{{folderName.stdout}}" dest: "{{offline_repo_location}}/{{offline_installer_type}}.zip" + owner: jenkins + group: jenkins format: zip +- name: copy latest.json file to archieve it in jenkins + copy: + src: "{{offline_repo_location}}/offline-installer-repo/offline_artifacts/{{folderName.stdout}}/latest.json" + dest: "{{offline_repo_location}}/latest.json" + owner: jenkins + group: jenkins + remote_src: yes + +- name: change the ownership of the directory to jenkins user + file: + path: "{{offline_repo_location}}" + state: directory + recurse: yes + owner: jenkins + group: jenkins + diff --git a/ansible/roles/offline-installer/templates/artifacts.sh.j2 b/ansible/roles/offline-installer/templates/artifacts.sh.j2 new file mode 100644 index 0000000000000000000000000000000000000000..ed3fa51a18bc1c59b0123fb9f2ea24b797764ef2 --- /dev/null +++ b/ansible/roles/offline-installer/templates/artifacts.sh.j2 @@ -0,0 +1,15 @@ +#!/bin/bash + + +if [ "{{offline_installer_type}}" == "windows32bit" ]; +then + cp '{{offline_repo_location}}/offline-installer-repo/src/dist/1.0.0/win/ia32/{{environment_name}} Setup 1.0.0.exe' offline_artifacts/{{time}}/{{environment_name}}_{{installer_version}}_windows32bit.exe +elif [ "{{offline_installer_type}}" == "windows64bit" ]; +then + cp '{{offline_repo_location}}/offline-installer-repo/src/dist/1.0.0/win/x64/{{environment_name}} Setup 1.0.0.exe' offline_artifacts/{{time}}/{{environment_name}}_{{installer_version}}_windows64bit.exe +elif [ "{{offline_installer_type}}" == "linux64bit" ]; +then + cp '{{offline_repo_location}}/offline-installer-repo/src/dist/1.0.0/linux/x64/{{environment_name}}_1.0.0_amd64.deb' offline_artifacts/{{time}}/{{environment_name}}_{{installer_version}}_linux64bit.deb +fi + + diff --git a/ansible/roles/offline-installer/templates/build.sh.j2 b/ansible/roles/offline-installer/templates/build.sh.j2 index be33e2a59127c3708896ecfba63c060aa7870943..720b64b8c6685ca5d305a4c12d09aee74cdbf59e 100644 --- a/ansible/roles/offline-installer/templates/build.sh.j2 +++ b/ansible/roles/offline-installer/templates/build.sh.j2 @@ -5,7 +5,7 @@ echo "Offline Installer for Sunbird" # Build script set -eo pipefail -if [ "{{offline_installer_type}}" == "windows32" ]; +if [ "{{offline_installer_type}}" == "windows32bit" ]; then docker run --rm -v ${PWD}:/private/ i386/node:8.16.2-stretch bash -x /private/32-bit-prerequisite.sh diff --git a/ansible/roles/offline-installer/templates/metadata.sh.j2 b/ansible/roles/offline-installer/templates/metadata.sh.j2 new file mode 100644 index 0000000000000000000000000000000000000000..9d7e7a0dd78848a7a9cfd477998fe30cdbe57969 --- /dev/null +++ b/ansible/roles/offline-installer/templates/metadata.sh.j2 @@ -0,0 +1,8 @@ +#!/bin/bash + +env_name={{environment_name}} +version={{installer_version}} +artifactFolder=$(find offline_artifacts/* -type d) + +# constructing the latest.json file +echo "{\"version\":\"${version}\",\"windows\":{\"32bit\":\"${env_name}_${version}_windows32bit.exe\",\"64bit\":\"${env_name}_${version}_windows64bit.exe\"},\"linux\":{\"64bit\":\"${env_name}_${version}_linux64bit.deb\"}}" | jq '.' | tee -a {{offline_repo_location}}/offline-installer-repo/${artifactFolder}/latest.json diff --git a/ansible/roles/offline-installer/templates/setupOfflineInstaller.sh.j2 b/ansible/roles/offline-installer/templates/setupOfflineInstaller.sh.j2 index a7d0c718c01c6cd0be017a1d5454be53c72cc810..64b5a019b85c6e2f6e6fdc2c8c9dc714519edead 100644 --- a/ansible/roles/offline-installer/templates/setupOfflineInstaller.sh.j2 +++ b/ansible/roles/offline-installer/templates/setupOfflineInstaller.sh.j2 @@ -5,24 +5,21 @@ npm install -g n n 8.16 cd /project/src -if [ "{{offline_installer_type}}" != "windows32" ]; +if [ "{{offline_installer_type}}" != "windows32bit" ]; then #Build the offline installer - npm install - npm run dist + npm install + npm run dist fi -if [ "{{offline_installer_type}}" == "windows32" ]; +if [ "{{offline_installer_type}}" == "windows32bit" ]; then -# npm run dist - npm run dist-win32 - cp '/project/src/dist/1.0.0/win/ia32/DIKSHA Setup 1.0.0.exe' ../offline_artifacts/{{time}}/ -elif [ "{{offline_installer_type}}" == "windows64" ]; +# npm run dist + npm run dist-win32 +elif [ "{{offline_installer_type}}" == "windows64bit" ]; then - npm run dist-win64 - cp '/project/src/dist/1.0.0/win/x64/DIKSHA Setup 1.0.0.exe' ../offline_artifacts/{{time}}/ -elif [ "{{offline_installer_type}}" == "debian" ]; + npm run dist-win64 +elif [ "{{offline_installer_type}}" == "linux64bit" ]; then - npm run dist-linux - cp '/project/src/dist/1.0.0/linux/x64/DIKSHA_1.0.0_amd64.deb' ../offline_artifacts/{{time}}/ + npm run dist-linux fi diff --git a/pipelines/offlineinstaller/Jenkinsfile b/pipelines/offlineinstaller/Jenkinsfile index c24ee78c228b2b0258d9f7e105e26cc4c6e519aa..1f5bda8075f4807a429d4aaa45953e6f8a0e2039 100644 --- a/pipelines/offlineinstaller/Jenkinsfile +++ b/pipelines/offlineinstaller/Jenkinsfile @@ -52,6 +52,7 @@ node() { println values ansible_playbook_run(values) archiveArtifacts artifacts: '*.zip', onlyIfSuccessful: true + archiveArtifacts artifacts: 'latest.json', onlyIfSuccessful: true } } catch (err) {