<commit_before># Create the Wordpress config file wp-config.php with corresponding values
node[:deploy].each do |app_name, deploy|

    template "#{deploy[:deploy_to]}/shared/.env" do
        source "env.erb"
        mode 0660
        group deploy[:group]

        owner "apache"
        
        variables(
            :database   => (deploy[:database][:database] rescue nil),
            :user       => (deploy[:database][:username] rescue nil),
            :password   => (deploy[:database][:password] rescue nil),
            :host       => (deploy[:database][:host] rescue nil),
            :keys       => (keys rescue nil)
        )
    end	
end<commit_msg>Deploy script.<commit_after>app = search("aws_opsworks_app").first
user = search("aws_opsworks_user").first

site_root = "#{node['web_root']}#{app['environment']['THEME_NAME']}/"
current_link = "#{site_root}current"
time =  Time.new.strftime("%Y%m%d%H%M%S")
release_dir = "#{site_root}releases/#{time}/"
shared_upload_dir = "#{site_root}shared/web/app/uploads/"

count_command = "ls -l #{site_root}releases/ | grep ^d | wc -l"
directory_count = shell_out(count_command)

if directory_count.stdout.to_i > 4
  execute "delete-oldest-release" do
    command "find #{site_root}releases/* -maxdepth 0 -type d -print | sort | head -n 1 | xargs rm -rf"
  end
end

directory "#{release_dir}" do
  owner "www-data"
  group "www-data"
  mode "2775"
  action :create
  recursive true
end

execute "ssh-git-clone" do
  command "ssh-agent sh -c 'ssh-add /home/#{user['username']}/.ssh/id_rsa; git clone #{app['app_source']['url']} #{release_dir}'"
end

directory "#{release_dir}web/app/uploads" do
  recursive true
  action :delete
end

link "#{current_link}" do
  action :delete
end

link "#{current_link}" do
  to "#{release_dir}"
end

link "#{release_dir}web/app/uploads" do
  to "#{shared_upload_dir}"
end

execute "change-directory-permissions" do
  command "find #{release_dir} -type d -exec chmod 2775 {} +"
end

execute "change-file-permissions" do
  command "find #{release_dir} -type f -exec chmod 0664 {} +"
end

execute "change-ownership" do
  command "chown -R www-data:www-data #{release_dir}"
end
{'fraction_non_alphanumeric': 0.15270708005552985, 'fraction_numerical': 0.008792225821378992, 'mean_word_length': 3.6394849785407724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '490312', 'n_tokens_mistral': 762, 'n_tokens_neox': 726, 'n_words': 182}