Skip to content

Instantly share code, notes, and snippets.

@milosgajdos
Last active December 18, 2019 10:43
Show Gist options
  • Save milosgajdos/b953462536dd52dedcdc to your computer and use it in GitHub Desktop.
Save milosgajdos/b953462536dd52dedcdc to your computer and use it in GitHub Desktop.
Chef recipe to deploy .NET applications
# Used for search
tag('msapp')
# Install AWS ruby libraries
include_recipe "aws"
# Load Encrypted data bag secrets
msapp_secrets = Chef::EncryptedDataBagItem.load("msapp", "secrets")
# Build artifact vars using get_version() library function
artifact_version = get_version(node['msapp']['artifacts_s3_bucket'], msapp_secrets['aws'])
artifact_name = "msapp-#{artifact_version}.zip"
artifact_path = "#{node['msapp']['download_path']}\\#{artifact_name}"
already_deployed = "((dir #{node['msapp']['deploy_path']}\\bin\\MsApp.dll).VersionInfo.FileVersion -eq
\'#{artifact_version}\')"
# Download protect artifact
aws_s3_file artifact_path do
bucket node['msapp']['artifacts_s3_bucket']
remote_path "packages/#{artifact_name}"
aws_access_key_id msapp_secrets['aws']['access_key']
aws_secret_access_key msapp_secrets['aws']['secret']
end
# Unzip downloaded artifact
windows_zipfile node['msapp']['extract_path']} do
source artifact_path
action :unzip
not_if { File.directory?("#{node['msapp']['extract_path']}\\MsApp.deploy.cmd") }
end
# Populate MsApp parameters
template "#{node['msapp']['extract_path']}\\MsApp.SetParameters.xml" do
source "MsApp.SetParameters.xml.erb"
variables({
:airbrake_key => msapp_secrets['airbrake_key']
})
end
# Web.config contains DATABASE SETTINGS
template "#{node['msapp']['extract_path']}\\Web.config" do
source "Web.config.erb"
variables({
:db_passwd => msapp_secrets['db_passwd']
})
end
# Create Protect API IIS site
iis_site node['msapp']['iis']['site'] do
protocol :http
port 80
path node['msapp']['deploy_path']
action [ :add, :start ]
end
# Create IIS app in the above created pool
iis_app node['msapp']['iis']['site'] do
application_pool node['msapp']['iis']['pool_name']
action :config
end
# Don't deploy again if correct version is already deployed
windows_batch "Deploy-MsApp" do
code <<-EOH
"#{node['msapp']['extract_path']}\\MsApp.deploy.cmd" /y
EOH
guard_interpreter :powershell_script
notifies :restart, "iis_site[#{node['msapp']['iis']['site']}]"
not_if "#{already_deployed}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment