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