Chef Recipe - deploy.rb
#
# Cookbook Name:: tf_scms
# Recipe:: deploy
# Author: ThermoFisher
# # Copyright (c) 2017 Thermofisher Scientific, All Rights Reserved.

app = search('aws_opsworks_app').first

Chef::Log.info("********** The app build number is '#{app['environment']['app_version']}' **********")
Chef::Log.info("********** The app s3 bucket name is '#{app['environment']['s3_resource_bucket']}' **********")
Chef::Log.info("********** The app's s3 region is '#{app['environment']['s3_region']}' **********")

s3_bucket_name = (app['environment']['s3_resource_bucket']).to_s
s3_region = (app['environment']['s3_region']).to_s

log 'scms file name priniting. ' do

    message "********************* scms file name priniting.... scms_mainline *************************"     level :info
end
# #defining Shared Static file path and name variables
scms_file_name = 'scms_mainline.zip'
local_scms_file_path = "#{node['tf_scms']['web_home']}\\#{scms_file_name}"
s3_path = "deploy/#{app['environment']['app_version']}/#{scms_file_name}"

Chef::Log.info('*** start cfstop deploy')

#stop cf windows services
include_recipe 'tf_scms::_cfstop'
Chef::Log.info('*** stop cfstop deploy')

##Chef::Log.info('*** start delete D:/web/scms')
## delete the scms directory
##directory "D:\\web\\scms" do
  ##recursive true
  ##action :delete
##end
##Chef::Log.info('*** stop delete D:/web/scms')

##Chef::Log.info('*** start create D:/web/scms')

##directory "D:\\web\\scms" do
  ##rights :full_control, "COMMERCE-1-QA2\\Administrator"
  ##inherits false
  ##action :create
##end

##Chef::Log.info('*** stop create D:/web/scms')

##delete previous zip file
Chef::Log.info('*** start delete previous zip file')

file 'D:\\web\\scms\\#{scms_file_name}' do
  action :delete
end

Chef::Log.info('*** stop delete previous zip file')

## download the shared-static file from S3
  aws_s3_file "D:\\web\\scms\\#{scms_file_name}" do
    bucket s3_bucket_name
    remote_path s3_path
    regions3_region
end

Chef::Log.info('*** start unzip')
## unzip the scms
windows_zipfile "D:\\web\\scms" do
  source local_scms_file_path
  #source 'https://github.com/chef-cookbooks/windows/archive/master.zip'
  action :unzip
  overwrite true
end
Chef::Log.info('*** stop unzip')

Chef::Log.info('*** start cfstart deploy')

#stop cf windows services
include_recipe 'tf_scms::_cfstart'

Chef::Log.info('*** stop cfstart deploy')