[ansible] added deploy role
This commit is contained in:
@@ -1,2 +1,6 @@
|
||||
[defaults]
|
||||
hash_behaviour = merge
|
||||
host_key_checking = False
|
||||
|
||||
[ssh_connection]
|
||||
ssh_args = -o ForwardAgent=yes
|
||||
3
ansible/deploy.yml
Normal file
3
ansible/deploy.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
- hosts: all
|
||||
roles:
|
||||
- deploy
|
||||
3
ansible/group_vars/all.yml
Normal file
3
ansible/group_vars/all.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
project_name: "tankz"
|
||||
project_smartname: "Tank'z"
|
||||
project_dir: "/home/holop/{{ project_name }}"
|
||||
19
ansible/roles/deploy/tasks/main.yml
Normal file
19
ansible/roles/deploy/tasks/main.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
- import_tasks: repo.yml
|
||||
- import_tasks: npm.yml
|
||||
|
||||
- name: Copy config.json
|
||||
copy:
|
||||
src: "{{ release_dir }}/config.shmyga.ru.json"
|
||||
dest: "{{ release_dir }}/config.json"
|
||||
remote_src: true
|
||||
|
||||
- name: Gulp build
|
||||
command: "gulp default"
|
||||
args:
|
||||
chdir: "{{ release_dir }}"
|
||||
|
||||
- name: Create symlink to release
|
||||
file:
|
||||
src: "{{ release_dir }}"
|
||||
dest: "{{ project_dir }}/current"
|
||||
state: link
|
||||
21
ansible/roles/deploy/tasks/npm.yml
Normal file
21
ansible/roles/deploy/tasks/npm.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
- name: Create directory for node_modules
|
||||
file:
|
||||
path: "{{ project_dir }}/npm"
|
||||
state: directory
|
||||
|
||||
- name: Copy package.json
|
||||
copy:
|
||||
src: "{{ release_dir }}/package.json"
|
||||
dest: "{{ project_dir }}/npm/"
|
||||
remote_src: true
|
||||
|
||||
- name: npm install
|
||||
command: npm install
|
||||
args:
|
||||
chdir: "{{ project_dir }}/npm/"
|
||||
|
||||
- name: Create symlink to node_modules
|
||||
file:
|
||||
src: "{{ project_dir }}/npm/node_modules"
|
||||
dest: "{{ release_dir }}/node_modules"
|
||||
state: link
|
||||
17
ansible/roles/deploy/tasks/repo.yml
Normal file
17
ansible/roles/deploy/tasks/repo.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
- name: Update git repository
|
||||
git:
|
||||
repo: "{{ repo_url }}"
|
||||
dest: "{{ project_dir }}/repo"
|
||||
|
||||
- name: Creates directory for release
|
||||
file:
|
||||
path: "{{ release_dir }}"
|
||||
state: directory
|
||||
|
||||
- name: Copy project files
|
||||
synchronize:
|
||||
src: "{{ project_dir }}/repo/"
|
||||
dest: "{{ release_dir }}"
|
||||
rsync_opts:
|
||||
- "--exclude=.git"
|
||||
delegate_to: "{{ inventory_hostname }}"
|
||||
5
ansible/roles/deploy/vars/main.yml
Normal file
5
ansible/roles/deploy/vars/main.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
ansible_user: holop
|
||||
date_str: "{{ ansible_date_time.year }}{{ ansible_date_time.month }}{{ ansible_date_time.day }}{{ ansible_date_time.hour }}{{ ansible_date_time.minute }}{{ ansible_date_time.second }}"
|
||||
|
||||
repo_url: "git@bitbucket.org:infernalgames/{{ project_name }}.git"
|
||||
release_dir: "{{ project_dir }}/releases/{{ date_str }}"
|
||||
@@ -1,5 +0,0 @@
|
||||
- name: install tankz systemd unit file
|
||||
template: src=template/tankz.j2 dest=/etc/systemd/system/tankz.service
|
||||
|
||||
- name: start tankz
|
||||
systemd: state=started name=tankz daemon_reload=yes
|
||||
@@ -1,16 +0,0 @@
|
||||
[Unit]
|
||||
Description=Tank'z game server
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
PIDFile=/var/run/tankz.pid
|
||||
WorkingDirectory=/home/holop/repo/tankz/current/target
|
||||
User=www-data
|
||||
Group=www-data
|
||||
ExecStart=/usr/bin/neko /home/holop/repo/tankz/current/target/tankz.n
|
||||
TimeoutSec=300
|
||||
Restart=always
|
||||
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,3 +0,0 @@
|
||||
ansible_become: yes
|
||||
ansible_user: barin
|
||||
ansible_become_pass: 1234!QAZ
|
||||
10
ansible/roles/setup/tasks/apt.yml
Normal file
10
ansible/roles/setup/tasks/apt.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
- name: Install the package "Neko"
|
||||
apt:
|
||||
name: 'neko'
|
||||
|
||||
- name: Install the package "Node"
|
||||
apt:
|
||||
name: '{{ item }}'
|
||||
with_items:
|
||||
- nodejs
|
||||
- npm
|
||||
6
ansible/roles/setup/tasks/main.yml
Normal file
6
ansible/roles/setup/tasks/main.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
- import_tasks: apt.yml
|
||||
when: ansible_distribution|lower == 'ubuntu'
|
||||
|
||||
- import_tasks: npm.yml
|
||||
|
||||
- import_tasks: service.yml
|
||||
4
ansible/roles/setup/tasks/npm.yml
Normal file
4
ansible/roles/setup/tasks/npm.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- name: Install "gulp-cli" node.js package globally.
|
||||
npm:
|
||||
name: gulp-cli
|
||||
global: yes
|
||||
10
ansible/roles/setup/tasks/service.yml
Normal file
10
ansible/roles/setup/tasks/service.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
- name: "install {{ service_name }} systemd unit file"
|
||||
template:
|
||||
src: "template/service.j2"
|
||||
dest: "/etc/systemd/system/{{ service_name }}.service"
|
||||
|
||||
- name: "start {{ service_name }} service"
|
||||
systemd:
|
||||
state: started
|
||||
name: "{{ service_name }}"
|
||||
daemon_reload: yes
|
||||
15
ansible/roles/setup/template/service.j2
Normal file
15
ansible/roles/setup/template/service.j2
Normal file
@@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description={{ service_description }}
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
PIDFile=/var/run/{{ service_name }}.pid
|
||||
WorkingDirectory={{ service_work_dir }}
|
||||
User={{ service_user }}
|
||||
Group={{ service_user }}
|
||||
ExecStart={{ service_command }}
|
||||
TimeoutSec=300
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
9
ansible/roles/setup/vars/main.yml
Normal file
9
ansible/roles/setup/vars/main.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
ansible_become: yes
|
||||
ansible_user: barin
|
||||
ansible_become_pass: 1234!QAZ
|
||||
|
||||
service_name: "{{ project_name }}"
|
||||
service_description: "{{ project_smartname }} server"
|
||||
service_work_dir: "{{ project_dir }}/current/target"
|
||||
service_command: "/usr/bin/neko {{ project_dir }}/current/target/{{ project_name }}.n"
|
||||
service_user: www-data
|
||||
@@ -1,3 +1,3 @@
|
||||
- hosts: all
|
||||
roles:
|
||||
- service
|
||||
- setup
|
||||
|
||||
@@ -46,4 +46,4 @@ const test = (build) => function test() {
|
||||
|
||||
|
||||
exports['server'] = gulp.series(prepare(Haxe.ID), generate(), build());
|
||||
exports['server:test'] = gulp.series(prepare(Haxe.ID, FlashPlayer.ID), generate(), test(build()));
|
||||
exports['server:test'] = gulp.series(prepare(Haxe.ID), generate(), test(build()));
|
||||
|
||||
11
capfile
11
capfile
@@ -1,11 +0,0 @@
|
||||
require 'capistrano/setup'
|
||||
require 'capistrano/deploy'
|
||||
require 'capistrano/scm/git'
|
||||
install_plugin Capistrano::SCM::Git
|
||||
require 'capistrano/scm/git-with-submodules'
|
||||
install_plugin Capistrano::SCM::Git::WithSubmodules
|
||||
require 'capistrano/npm'
|
||||
require 'capistrano/gulp'
|
||||
require 'airbrussh/capistrano'
|
||||
|
||||
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
|
||||
@@ -1,16 +0,0 @@
|
||||
set :config_role, :app
|
||||
set :config_path, -> { release_path }
|
||||
set :config_type, 'json'
|
||||
|
||||
|
||||
namespace :config do
|
||||
task :setup do
|
||||
config_role = fetch(:config_role)
|
||||
config_path = fetch(:config_path)
|
||||
config_type = fetch(:config_type)
|
||||
on roles(config_role) do |server|
|
||||
# stage = fetch(:stage)
|
||||
execute "cd #{config_path} && cp config.#{server.hostname}.#{config_type} config.#{config_type}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,31 +0,0 @@
|
||||
require_relative 'npm'
|
||||
require_relative 'config'
|
||||
|
||||
app = 'tankz'
|
||||
user = 'holop'
|
||||
|
||||
# git
|
||||
set :application, app
|
||||
set :repo_url, "git@bitbucket.org:infernalgames/#{app}.git"
|
||||
set :user, user
|
||||
set :deploy_to, "/home/#{user}/repo/#{app}"
|
||||
|
||||
# airbrussh
|
||||
set :format, :airbrussh
|
||||
set :format_options, command_output: false
|
||||
|
||||
# config
|
||||
before 'deploy:updated', 'config:setup'
|
||||
|
||||
# npm
|
||||
set :npm_target_path, -> { "/home/#{fetch(:user)}/npm" }
|
||||
set :npm_flags, '--silent --no-spin'
|
||||
set :npm_roles, :web
|
||||
set :npm_env_variables, {}
|
||||
|
||||
# gulp
|
||||
set :gulp_target_path, -> { release_path }
|
||||
set :gulp_tasks, 'default'
|
||||
set :gulp_flags, '--no-color'
|
||||
set :gulp_roles, :web
|
||||
before 'deploy:updated', 'gulp'
|
||||
@@ -1,11 +0,0 @@
|
||||
role :app, %w{localhost}
|
||||
role :web, %w{localhost}
|
||||
role :db, %w{localhost}
|
||||
|
||||
#set :user, ENV['USER']
|
||||
user = fetch(:user)
|
||||
|
||||
server 'localhost', ssh_options: { port: 22, user: user, forward_agent: true }
|
||||
|
||||
set :tmp_dir, "/home/#{user}/tmp"
|
||||
set :branch, 'master'
|
||||
@@ -1,13 +0,0 @@
|
||||
# host = '94.130.110.9'
|
||||
host = 'shmyga.ru'
|
||||
|
||||
role :app, host
|
||||
role :web, host
|
||||
role :db, host
|
||||
|
||||
user = fetch(:user)
|
||||
|
||||
server host, ssh_options: { port: 22, user: user, forward_agent: true }
|
||||
|
||||
set :tmp_dir, "/home/#{user}/tmp"
|
||||
set :branch, 'master'
|
||||
@@ -1,24 +0,0 @@
|
||||
set :npm_path, -> { release_path }
|
||||
|
||||
namespace :npm do
|
||||
task :prepare do
|
||||
npm_roles = fetch(:npm_roles)
|
||||
on roles(npm_roles) do
|
||||
npm_target_path = fetch(:npm_target_path)
|
||||
npm_path = fetch(:npm_path)
|
||||
execute "mkdir -p #{npm_target_path}"
|
||||
execute "cp #{npm_path}/package.json #{npm_target_path}"
|
||||
end
|
||||
end
|
||||
task :link do
|
||||
npm_roles = fetch(:npm_roles)
|
||||
on roles(npm_roles) do
|
||||
npm_target_path = fetch(:npm_target_path)
|
||||
npm_path = fetch(:npm_path)
|
||||
execute "ln -s #{npm_target_path}/node_modules #{npm_path}/"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
before 'npm:install', 'npm:prepare'
|
||||
after 'npm:install', 'npm:link'
|
||||
6
gemfile
6
gemfile
@@ -1,6 +0,0 @@
|
||||
source 'https://rubygems.org'
|
||||
gem 'capistrano', '~> 3.7.0'
|
||||
gem 'capistrano-git-with-submodules', '~> 2.0'
|
||||
gem 'capistrano-npm'
|
||||
gem 'capistrano-gulp'
|
||||
gem 'airbrussh', :require => false
|
||||
@@ -33,4 +33,4 @@ merge('./build/editor');
|
||||
merge('./build/server');
|
||||
|
||||
|
||||
exports.default = gulp.series(exports.clean, exports.client);
|
||||
exports.default = gulp.series(exports.clean, exports.client, exports.server);
|
||||
Reference in New Issue
Block a user