vagrant and chef install everything

This commit is contained in:
2019-09-02 16:48:23 -04:00
parent 4fb554add5
commit f1809bef83
268 changed files with 16021 additions and 7 deletions

View File

@ -0,0 +1,52 @@
[
'apache2',
'apache2-dev',
'libapache2-mod-wsgi-py3',
].each do |pkg|
apt_package pkg
end
file '/etc/apache2/sites-enabled/000-default.conf' do
action :delete
end
execute 'enable apache mods' do
command 'a2enmod expires'
end
if node['web']['do_ssl']
apt_repository 'certbot apt repo' do
uri 'ppa:certbot/certbot'
repo_name 'ppa-certbot'
deb_src true
action :add
end
apt_update
[
'software-properties-common',
'certbot',
'python-certbot-apache',
].each do |pkg|
apt_package pkg
end
execute 'apache certbot' do
command "sudo certbot certonly --standalone -d #{node['app']['domain']} --non-interactive --agree-tos --email #{node['web']['admin_email']}"
end
end
if node['web']['socket.io']
execute 'enable apache mods' do
command 'a2enmod rewrite; a2enmod proxy_wstunnel; a2enmod proxy_http'
end
end
template '/etc/apache2/sites-enabled/000-server.conf' do
source 'apache/vhost.conf.erb'
end
systemd_unit 'apache2.service' do
action :restart
end

View File

@ -0,0 +1,21 @@
mysql_service node['app']['name'] do
# version '5.7'
bind_address node['db']['bind_address']
port node['db']['port']
# data_dir '/data'
initial_root_password node['db']['root_password']
action [:create, :start]
end
bash 'Make mysql Database and User' do
code <<~EOH
mysql -h 127.0.0.1 -uroot -p"#{node['db']['root_password']}" -e "CREATE DATABASE '#{node['db']['name']}' /*\!40100 DEFAULT CHARACTER SET utf8 */;"
mysql -h 127.0.0.1 -uroot -p"#{node['db']['root_password']}" -e "CREATE USER '#{node['db']['user']}'@localhost IDENTIFIED BY '#{node['db']['password']}';"
mysql -h 127.0.0.1 -uroot -p"#{node['db']['root_password']}" -e "GRANT ALL PRIVILEGES ON '#{node['db']['name']}'.* TO '#{node['db']['user']}'@'%';"
mysql -h 127.0.0.1 -uroot -p"#{node['db']['root_password']}" -e "FLUSH PRIVILEGES;"
EOH
not_if "mysql -h 127.0.0.1 -uroot -p\"#{node['db']['root_password']}\" -e 'use #{node['db']['name']}'"
end

View File

@ -0,0 +1,66 @@
version_map = {
8 => {
'version' => '8.16.1',
'url' => 'https://nodejs.org/dist/v8.16.1/node-v8.16.1-linux-x64.tar.gz',
'checksum' => '8ef575b64edbb6c04e506d8c8e0c5f92b90f4752841892c5adbb3a1e02863f46'
},
10 => {
'version' => '10.16.3',
'url' => 'https://nodejs.org/dist/v10.16.3/node-v10.16.3-linux-x64.tar.gz',
'checksum' => '2f0397bb81c1d0c9901b9aff82a933257bf60f3992227b86107111a75b9030d9'
},
12 => {
'version' => '12.9.1',
'url' => 'https://nodejs.org/dist/v12.9.1/node-v12.9.1-linux-x64.tar.gz',
'checksum' => '5488e9d9e860eb344726aabdc8f90d09e36602da38da3d16a7ee852fd9fbd91f'
}
}
unless node['nodejs']['working-dir'][0] == '/'
node.override['nodejs']['working-dir'] = "#{node['working-dir']}/#{node['nodejs']['working-dir']}"
end
unless version_map.key?(node['nodejs']['install_version'])
raise <<~EOH
Unsupported NodeJS version #{node['nodejs']['install_version']}.
Supports #{version_map.keys}.
EOH
end
set_version = version_map[node['nodejs']['install_version']]
node.default['nodejs']['install_method'] = 'binary'
node.default['nodejs']['version'] = set_version['version'].to_str
node.default['nodejs']['binary']['url'] = set_version['url']
node.default['nodejs']['binary']['checksum'] = set_version['checksum']
node.default['nodejs']['env_path'] = "/home/#{node['app']['run_user']}/app/#{node['app']['name']}/env/node"
include_recipe "nodejs"
directory node['nodejs']['env_path'] do
owner node['app']['run_user']
group node['app']['run_user']
mode 0755
recursive true
end
file "#{node['nodejs']['env_path']}/package.json" do
owner node['app']['run_user']
group node['app']['run_user']
mode 0755
content ::File.open("#{node['nodejs']['working-dir']}/package.json").read
action :create
end
execute 'Install NPM package.json' do
cwd node['nodejs']['env_path']
user node['app']['run_user']
group node['app']['run_user']
environment ({'HOME' => "/home/#{node['app']['run_user']}"})
command "npm --prefix #{node['nodejs']['env_path']} --python=\"`which python2.7`\" install #{node['nodejs']['env_path']}"
end
directory "/var/log/node/#{node['app']['name']}" do
recursive true
end

View File

@ -0,0 +1,64 @@
# apt_repository 'open resty repo' do
# uri 'http://openresty.org/package/ubuntu'
# key 'https://openresty.org/package/pubkey.gpg'
# components ['main']
# end
apt_package 'software-properties-common'
execute 'add key' do
command 'wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -'
end
execute 'add repo' do
command 'add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main"; apt update'
end
apt_package 'openresty'
if node['web']['do_ssl']
apt_package 'luarocks'
execute 'install lua-resty-auto-ssl' do
command 'luarocks install lua-resty-auto-ssl'
end
directory '/etc/ssl' do
mode '0755'
action :create
end
execute 'defualt ssl' do
command "openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -subj '/CN=sni-support-required-for-valid-ssl' -keyout /etc/ssl/resty-auto-ssl-fallback.key -out /etc/ssl/resty-auto-ssl-fallback.crt"
end
execute 'defualt ssl' do
command "openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -subj '/CN=sni-support-required-for-valid-ssl' -keyout /etc/ssl/resty-auto-ssl-fallback.key -out /etc/ssl/resty-auto-ssl-fallback.crt"
end
template '/etc/openresty/autossl.conf' do
source 'autossl.conf.erb'
end
end
template '/etc/openresty/nginx.conf' do
source 'nginx.conf.erb'
end
directory '/etc/openresty/sites-enabled' do
mode '0755'
action :create
end
directory '/var/log/nginx/' do
mode '0775'
action :create
end
template '/etc/openresty/sites-enabled/host.conf' do
source 'host.conf.erb'
end
systemd_unit 'openresty' do
action :reload
end

View File

@ -0,0 +1,14 @@
unless node['php']['working-dir'][0] == '/'
node.override['php']['working-dir'] = "#{node['working-dir']}/#{node['php']['working-dir']}"
end
[
'php',
'libapache2-mod-php',
].each do |pkg|
apt_package pkg
end
systemd_unit 'apache2.service' do
action :restart
end

View File

@ -0,0 +1,49 @@
execute 'add key' do
command 'wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -'
end
execute 'add repo' do
command 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
end
apt_update 'update' do
end.run_action(:update) if platform_family?('debian')
postgresql_server_install 'My PostgreSQL Server install' do
initdb_locale 'en_US.utf8'
action :install
end
postgresql_server_install 'Setup my PostgreSQL 9.6 server' do
initdb_locale 'en_US.utf8'
action :create
end
postgresql_access 'local_postgres_superuser' do
comment 'Local postgres superuser access'
access_type 'local'
access_db 'all'
access_user 'postgres'
access_addr nil
access_method 'ident'
end
postgresql_user 'DB user' do
create_user node['db']['user']
password node['db']['password']
createrole true
end
# Hack for creating a database, this cook book is broken with debian...
execute 'add database' do
command "createdb #{node['db']['name']}"
user 'postgres'
not_if "psql -lqt | grep -w \"#{node['db']['name']}\"", :user => 'postgres'
end
execute 'Grant DB user' do
command "echo \"grant all privileges on database #{node['db']['name']} to #{node['db']['user']} ;\" | psql"
user 'postgres'
end

View File

@ -0,0 +1,40 @@
apt_repository 'Python apt repo' do
uri 'ppa:deadsnakes/ppa'
repo_name 'ppa-deadsnakes'
deb_src true
action :add
end
apt_update
pip_version = node['python']['version'][0] == 2 ? '' : '3'
[
"python#{node['python']['version']}",
"python#{node['python']['version']}-dev",
"python#{pip_version}-pip",
].each do |pkg|
apt_package pkg
end
if node['python']['working-dir']
unless node['python']['working-dir'][0] == '/'
node.override['python']['working-dir'] = "#{node['working-dir']}/#{node['python']['working-dir']}"
end
execute 'Install virtual' do
command "pip#{node['python']['version'][0]} install virtualenv"
end
bash 'Install python requirements file' do
# user 'root'
# cwd '/mydir'
code <<~EOH
virtualenv #{node['python']['env_path']}
source #{node['python']['env_path']}/bin/activate
pip install -r #{node['python']['working-dir']}/#{node['python']['pip_requirements_path']}
EOH
end
end

View File

@ -0,0 +1,19 @@
apt_package 'redis-server'
template '/etc/redis/local.conf' do
source 'redis/local.conf'
end
if node['redis']['unix']['perm']
bash 'append_to_config' do
user 'root'
code <<~EOF
echo "include /etc/redis/local.conf" >> /etc/redis/redis.conf
EOF
not_if 'grep -q "/etc/redis/local.conf" /etc/redis/redis.conf'
end
end
systemd_unit 'redis-server.service' do
action :restart
end