Replace application cookbook with git resource
This commit is contained in:
parent
3a5a038f7e
commit
54098a450c
@ -6,6 +6,5 @@ description 'Installs/Configures kredits-github'
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version '0.1.0'
|
||||
|
||||
depends 'application_javascript'
|
||||
depends 'kosmos-nodejs'
|
||||
depends 'kosmos-nginx'
|
||||
|
@ -1,28 +1,6 @@
|
||||
#
|
||||
# Cookbook Name:: kredits-github
|
||||
# Recipe:: default
|
||||
#
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright:: 2019, Kosmos Developers
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
include_recipe 'kosmos-nodejs'
|
||||
|
||||
@ -40,56 +18,55 @@ user deploy_user do
|
||||
comment "deploy user"
|
||||
end
|
||||
|
||||
path_to_deploy = "/opt/#{app_name}"
|
||||
application path_to_deploy do
|
||||
owner deploy_user
|
||||
group deploy_group
|
||||
|
||||
git do
|
||||
app_path = "/opt/#{app_name}"
|
||||
git app_path do
|
||||
user deploy_user
|
||||
group deploy_group
|
||||
repository "https://github.com/67P/#{app_name}.git"
|
||||
revision node[app_name]['revision']
|
||||
notifies :restart, "systemd_unit[#{app_name}.service]", :delayed
|
||||
end
|
||||
|
||||
npm_install do
|
||||
execute "npm install" do
|
||||
cwd app_path
|
||||
environment "HOME" => app_path
|
||||
user deploy_user
|
||||
end
|
||||
|
||||
execute "systemctl daemon-reload" do
|
||||
command "systemctl daemon-reload"
|
||||
action :nothing
|
||||
end
|
||||
|
||||
file "#{path_to_deploy}/github_app_key.pem" do
|
||||
file "#{app_path}/github_app_key.pem" do
|
||||
content credentials['private_key']
|
||||
owner deploy_user
|
||||
group deploy_group
|
||||
mode '0440'
|
||||
end
|
||||
|
||||
template "/lib/systemd/system/#{app_name}.service" do
|
||||
source 'nodejs.systemd.service.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0640'
|
||||
variables(
|
||||
user: deploy_user,
|
||||
group: deploy_group,
|
||||
app_dir: path_to_deploy,
|
||||
entry: "/usr/bin/node /usr/bin/npm start",
|
||||
environment: {
|
||||
'LOG_LEVEL' => "info",
|
||||
'APP_ID' => credentials['app_id'],
|
||||
'PRIVATE_KEY_PATH' => "#{path_to_deploy}/github_app_key.pem",
|
||||
'WEBHOOK_SECRET' => credentials['webhook_secret'],
|
||||
service_env = {
|
||||
"LOG_LEVEL" => 'info',
|
||||
"APP_ID" => credentials["app_id"],
|
||||
"PRIVATE_KEY_PATH" => "#{app_path}/github_app_key.pem",
|
||||
"WEBHOOK_SECRET" => credentials["webhook_secret"]
|
||||
}
|
||||
)
|
||||
notifies :run, "execute[systemctl daemon-reload]", :delayed
|
||||
notifies :restart, "service[#{app_name}]", :delayed
|
||||
end
|
||||
|
||||
service app_name do
|
||||
action [:enable, :start]
|
||||
end
|
||||
systemd_unit "#{app_name}.service" do
|
||||
content({
|
||||
Unit: {
|
||||
Description: app_name
|
||||
},
|
||||
|
||||
Service: {
|
||||
ExecStart: "/usr/bin/node /usr/bin/npm start",
|
||||
WorkingDirectory: app_path,
|
||||
User: deploy_user,
|
||||
Group: deploy_group,
|
||||
Environment: service_env.map { |k, v| "'#{k}=#{v}'" },
|
||||
Restart: 'always'
|
||||
},
|
||||
|
||||
Install: {
|
||||
WantedBy: 'multi-user.target'
|
||||
}
|
||||
})
|
||||
verify false
|
||||
triggers_reload true
|
||||
action [:create, :enable, :start]
|
||||
end
|
||||
|
@ -1,15 +0,0 @@
|
||||
[Unit]
|
||||
Description=Start nodejs app
|
||||
|
||||
[Service]
|
||||
ExecStart=<%= @entry %>
|
||||
WorkingDirectory=<%= @app_dir %>
|
||||
User=<%= @user %>
|
||||
Group=<%= @group %>
|
||||
<% unless @environment.empty? -%>
|
||||
Environment=<% @environment.each do |key, value| -%>'<%= key %>=<%= value %>' <% end %>
|
||||
<% end -%>
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
x
Reference in New Issue
Block a user