Wednesday, 29 March 2017

AWS - Custom Windows AMI configured via Powershell Script in S3

This post will outline the approach to create a custom Windows AMI which can be used to serve IIS based Web applications.
The actual contents can be deployed at startup using a UserData or Custom Script loaded in S3 bucket.

The External script in S3 gives us flexibility to modify and deploy new configuration easily without touching the AMI instances.

Powershell Script to be deployed in Windows AMI
Invoke-WebRequest -Uri "https://s3.amazonaws.com/<bucketname>/<scriptname>Demo_Script.ps1" -OutFile .\S3-Script.ps1
./S3-Script.ps1 "parameter IIS_Demo_Script"

Save this file as script.ps1 and then create a Task in Windows Task Scheduler to be triggered at Startup which can execute without even a user logging in.
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File C:\bootstrap.ps1

In S3, you can create powershell script which can be used for generating let's say Index.html file or registering new IIS Site and copying content.

Following script set custom background color for instance and pick Hostname from Metadata URL, so for Autoscaling scenario, you can easily identify that data is served from which instance.

echo "<!DOCTYPE html><html lang='en'><body style='background-color:" > C:\inetpub\wwwroot\index.html
($a = "INDIANRED", "LIGHTCORAL", "SALMON", "DARKSALMON", "LIGHTSALMON", "CRIMSON", "RED", "ANTIQUEWHITE", "LINEN", "LAVENDERBLUSH", "MISTYROSE", "GAINSBORO", "LIGHTGRAY", "SILVER", "DARK
GRAY", "GRAY", "DIMGRAY", "LIGHTSLATEGRAY", "SLATEGRAY", "DARKSLATEGRAY") | Get-Random >> C:\inetpub\wwwroot\index.html
echo "'><div align='center'><h1>" >> C:\inetpub\wwwroot\index.html
invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-hostname >> C:\inetpub\wwwroot\index.html
echo "</h1><br/><br/><video width='800' height='600' <align='middle' controls><source src='https://<s3-bucket-url>/example/video.mp4' type='video/mp4'>Your browser does not support the video tag.</video></div></body></html>" >> C:\inetpub\wwwroot\index.html

Wednesday, 4 January 2017

Grails on Bluemix: Set up fully automated CI/CD Environment

Java Developers love Grails Framework and Good News is that Bluemix WAS Liberty Buildpack also supports running Grails applications.
However, most of the sample applications showcase that you need to compile WAR file locally and then has to be pushed to Bluemix.
This is not the desired option where most of the developers expect a completely automated CI/CD environment.

I have setup a Bluemix environment for Grails 3 CI/CD setup using Bluemix DevOps capabilities. As a developer, you need to just commit and push your code to Git repository either on Bluemix or Github and then the Bluemix Delivery Pipeline will perform Grails Build process to create WAR file and then can be deployed to either CloudFoundry or Docker Containers runtime on Bluemix.
Use this as a starter project to setup a delivery pipeline to develop on local environment, commit and push the changes to Git repository and then automatically build and deploy the application on Bluemix Cloud Foundry.

Bluemix Devops project:
https://hub.jazz.net/project/vtiwari4/gradle-demo-vtiwari4/overview


Github Code Repository:
https://github.com/tiwarivikas/gradle-demo-vtiwari4

This one is developed with Gradle 3, but I have used the following command to create the War file in cloud: ./gradlew clean assemble. We can try the similar approach with your existing Grails build tool as well.

Delivery Pipeline Configuration

Build Command:
./gradlew clean assemble



Tuesday, 6 December 2016

Manage Bluemix Apps in your own Code using CloudFoundry APIs – Part 2

This post is second part of first section where I outlined the business requirement and possibilities of using Cloud Foundry APIs to schedule the Auto-Start/Stop of Applications in a particular Space.

Link to first Part: Part 1

You can access the Source code of application on Github:

https://github.com/tiwarivikas/bluemix-admin

Live Demo: http://bluemix-admin.mybluemix.net/


Screenshot of Application:


Tuesday, 3 May 2016

Manage Bluemix Apps in your own Code using CloudFoundry APIs – Part 1

Bluemix provides a wonderful platform for rapidly developing innovative apps. The following series will guide how you can manage Bluemix applications from your own code.

This capability can be relevant to many UseCases like:

  • Auto-Schedule Start/Stop of Applications in Bluemix Dev Space based on team’s worktime.
  • Integrate Bluemix Application Deployment process with Organization’s Business Process.
  • Create Custom Dashboard displaying All Apps, Services, Billing Details, Usage
  • Setup Custom Notifications based on Bluemix account Usage details.

The Application provided is developed using NodeJS, Bootstrap V3 UI, CloudFoundry APIs, Cloudant Database, Bluemix SSO, Workload Scheduler service.

Following is the screenshot of Application and deployed at following URL:

https://bluemix-admin.mybluemix.net/

In next parts of the series, I’ll cover how to develop such capability.

bmxAdmin-screenshot

Tuesday, 9 February 2016

Writing Blogs On the Move – Use ‘Open Live Writer’

I was using Windows Live Writer till last year, but Microsoft stopped updating the same sometime back..

Recently, the code was OpenSourced and a new Project “Open Live Writer” has been launched in Github !

This tool is the future of Windows Live Writer and already contains Security enhancements. So, now you can connect your favourite Blogs to OLW !

I am publishing this post from Open Live Writer..

Link: http://openlivewriter.org/

image

image

Welcome to my blog !

Welcome to my blog !!

Installing Syntax Highlighting.. https://github.com/google/code-prettify

Use one of the following formats to enable highlighting code in blog post.

<!--?prettify lang=js linenums=true?-->
<pre class="prettyprint">
addEventListener('load', function() {
  var code = document.querySelector('#code');
  var worker = new Worker('worker.js');
  worker.onmessage = function(event) { code.innerHTML = event.data; }
  worker.postMessage(code.textContent);
})

<pre class="prettyprint linenums">
addEventListener('load', function() {
  var code = document.querySelector('#code');
  var worker = new Worker('worker.js');
  worker.onmessage = function(event) { code.innerHTML = event.data; }
  worker.postMessage(code.textContent);
})

Tuesday, 25 August 2015

IBM VERSE: Synchronize Recent Contacts from Notes Client to VERSE

Scenario:
Customers appreciate the new User Experience of IBM Verse, but the moment they start using it, the first problem they face is that while typing name, recent contacts are not available, which are there in Notes Client. So, customers were forced to either search customer emails or copy from Notes Client.

To avoid the same, I created a script to copy the Recent Contacts to My Contacts and Sync it to Server.

Steps are as follows: :

1.Create a Notes button using following code to Migrate Recent Contacts in Notes Client to My Contacts.

Sub Click(Source As Button)
    Dim s As New NotesSession
    Dim vw As NotesView
    Dim doc As NotesDocument
    Dim db As NotesDatabase
    Dim doc2 As NotesDocument
    On Err Goto ErrHandler
    Dim total As Integer, cnt As Integer
    msg = "Please ensure that you don't run this code multiple times, else it will create duplicates in your Addressbook. " + Chr(10) & _
    "Are you sure to run this code ?"
    If Messagebox(msg, 36, "Are you sure ? ") = 7  Then
        Msgbox "The action has been cancelled", 64, "Cancelled"
        Exit Sub
    End If
    Set db = s.GetDatabase("", "names.nsf")
    Set vw = db.GetView("RecentCollaborators")
    total = vw.AllEntries.Count
    cnt = 0
    Set doc = vw.GetFirstDocument
    While Not doc Is Nothing
        cnt = cnt + 1
        Print "Processing " & cnt & " / " & total & " document"
        Set doc2 = vw.GetNextDocument(doc)
        RCtype = doc.GetItemValue("type")
        If Lcase(RCtype(0)) = "group" Then
            'Skip the doc
        Else
            'Move to My Contacts
            Call RCReplace(doc, db)
        End If
NextDoc:
        Set doc = doc2
    Wend
    Messagebox "Migration process has completed.", 64, "Complete"
    Exit Sub
ErrHandler:
    Goto NextDoc
End Sub

Sub RCReplace(RCDoc As notesdocument, db As NotesDatabase)   
    On Error Resume Next
    Call RCDoc.replaceitemvalue("Form", "Person")  'DNT
    If Lcase(rcDoc.getitemvalue("Type")(0)) <> Lcase("PeRsOn") Then
        Call RCDoc.replaceitemvalue("Type", "Person")   'DNT
        'this code is in place for Mail-In Database records, with only  hierarchical name in Fullname item
        RCFN = rcdoc.getitemvalue("Fullname")
        If Ubound(RCFN) = 0 Then
            Dim FNname As New notesname(RCFN(0))
            CanonFN = FNname.canonical
            If CanonFN <> "" Then
                Redim NewFN(1)               
            End If
            NewFN(0) = FNname.canonical
            NewFN(1) = FNname.common
            Call RCdoc.replaceitemvalue("Fullname", NewFN)
        End If
        ' /end Mail-In Db specific code
    End If   
    Call RCdoc.replaceitemvalue("$AutoCreatedList", "")
    Call RCdoc.replaceitemvalue("$DPABState", "")
    Call RCdoc.replaceitemvalue("$DPAB_State", "")   
    Call RCDoc.save(False,False)
    Set newContact = RCdoc.CopyToDatabase( db )
    Call RCDoc.remove(True)
End Sub

Note: Click "Yes" if any prompt comes up for Trusting Code.

2. Goto Notes Client --> File Menu --> Preferences.

3. Open Contacts section and ensure "Enable Synchronize Contacts" option is enabled.

clip_image001

4. Goto Replication and Sync Tab and ensure that "Synchronize Contacts Replication is Enabled.

clip_image002

5. Once Synced, All the Recent Contacts will be available in IBM Verse as well !

For more details, refer to IBM Wiki.