Skip to content

Commit 1f035dd

Browse files
committed
add mina deployment
1 parent 4223463 commit 1f035dd

File tree

8 files changed

+115
-5
lines changed

8 files changed

+115
-5
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ gem 'swagger-docs', '0.2.9'
3030

3131
gem "redis", '3.3.0'
3232

33+
gem 'mina', '1.0.2'
34+
3335
group :development, :test do
3436
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
3537
gem 'byebug', platform: :mri

Gemfile.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ GEM
7575
mime-types (3.1)
7676
mime-types-data (~> 3.2015)
7777
mime-types-data (3.2016.0521)
78+
mina (1.0.2)
79+
open4 (~> 1.3.4)
80+
rake
7881
mini_portile2 (2.1.0)
7982
minitest (5.9.1)
8083
nio4r (1.2.1)
8184
nokogiri (1.6.8.1)
8285
mini_portile2 (~> 2.1.0)
86+
open4 (1.3.4)
8387
pg (0.19.0)
8488
puma (3.6.0)
8589
rack (2.0.1)
@@ -165,6 +169,7 @@ DEPENDENCIES
165169
byebug
166170
factory_girl_rails (= 4.7.0)
167171
listen (~> 3.0.5)
172+
mina (= 1.0.2)
168173
pg (~> 0.18)
169174
puma (~> 3.0)
170175
rack-attack (= 5.0.1)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Api::V1
2+
class HomeController < ApiController
3+
def index_public
4+
render json: { message: "Welcome to ML API. Please contact admin to use our system." }
5+
end
6+
end
7+
end

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class ApplicationController < ActionController::API
22
include ActionController::Serialization
33
include ActionController::HttpAuthentication::Token::ControllerMethods
44

5-
before_action :authenticate
5+
before_action :authenticate, except: [:index_public]
66
before_filter :throttle_token
77

88
protected

config/database.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,4 @@ test:
8585
#
8686
production:
8787
<<: *default
88-
database: filter_api_production
89-
username: filter_api
90-
password: <%= ENV['FILTER_API_DATABASE_PASSWORD'] %>
88+
database: filter_api_development

config/deploy.rb

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
require 'mina/rails'
2+
require 'mina/git'
3+
require 'mina/rbenv' # for rbenv support. (https://rbenv.org)
4+
# require 'mina/rvm' # for rvm support. (https://rvm.io)
5+
6+
# Basic settings:
7+
# domain - The hostname to SSH to.
8+
# deploy_to - Path to deploy into.
9+
# repository - Git repo to clone from. (needed by mina/git)
10+
# branch - Branch name to deploy. (needed by mina/git)
11+
12+
set :domain, 'xdev-server'
13+
set :deploy_to, '/home/tamnguyen/apps/rails_5_api'
14+
set :repository, 'git@github.com:ntamvl/rails_5_api_tutorial.git'
15+
set :branch, 'master'
16+
17+
# Optional settings:
18+
# set :user, 'foobar' # Username in the server to SSH to.
19+
# set :port, '30000' # SSH port number.
20+
# set :forward_agent, true # SSH forward_agent.
21+
22+
set :user, 'tamnguyen'
23+
set :port, '22'
24+
25+
# They will be linked in the 'deploy:link_shared_paths' step.
26+
# set :shared_dirs, fetch(:shared_dirs, []).push('config')
27+
# set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml')
28+
set :shared_dirs, fetch(:shared_dirs, []).push('config')
29+
set :shared_files, fetch(:shared_files, []).push('config/database.yml')
30+
31+
# This task is the environment that is loaded all remote run commands, such as
32+
# `mina deploy` or `mina rake`.
33+
task :environment do
34+
# If you're using rbenv, use this to load the rbenv environment.
35+
# Be sure to commit your .ruby-version or .rbenv-version to your repository.
36+
invoke :'rbenv:load'
37+
38+
# For those using RVM, use this to load an RVM version@gemset.
39+
# invoke :'rvm:use', 'ruby-1.9.3-p125@default'
40+
end
41+
42+
# Put any custom commands you need to run at setup
43+
# All paths in `shared_dirs` and `shared_paths` will be created on their own.
44+
task :setup do
45+
# command %{rbenv install 2.3.1p112}
46+
47+
# puts "\nStarting to setup app on #{fetch(:domain)}\n"
48+
# command %[mkdir -p "#{fetch(:deploy_to)}/#{fetch(:shared_path)}/tmp"]
49+
# command %[chmod g+rx,u+rwx "#{fetch(:deploy_to)}/#{fetch(:shared_path)}/tmp"]
50+
51+
# command %[mkdir -p "#{fetch(:deploy_to)}/#{fetch(:shared_path)}/tmp/pids"]
52+
# command %[chmod g+rx,u+rwx "#{fetch(:deploy_to)}/#{fetch(:shared_path)}/tmp/pids"]
53+
54+
# command %[mkdir -p "#{fetch(:deploy_to)}/#{fetch(:shared_path)}/tmp/sockets"]
55+
# command %[chmod g+rx,u+rwx "#{fetch(:deploy_to)}/#{fetch(:shared_path)}/tmp/sockets"]
56+
57+
# command %[mkdir -p "#{fetch(:deploy_to)}/#{fetch(:shared_path)}/log"]
58+
# command %[chmod g+rx,u+rwx "#{fetch(:deploy_to)}/#{fetch(:shared_path)}/log"]
59+
60+
# command %[mkdir -p "#{fetch(:deploy_to)}/#{fetch(:shared_path)}/config"]
61+
# command %[chmod g+rx,u+rwx "#{fetch(:deploy_to)}/#{fetch(:shared_path)}/config"]
62+
63+
command %[touch "#{fetch(:deploy_to)}/shared/config/database.yml"]
64+
# command %[echo "-----> Fill in information below to populate 'shared/config/database.yml'."]
65+
end
66+
67+
desc "Deploys the current version to the server."
68+
task :deploy do
69+
# uncomment this line to make sure you pushed your local branch to the remote origin
70+
# invoke :'git:ensure_pushed'
71+
deploy do
72+
# Put things that will set up an empty directory into a fully set-up
73+
# instance of your project.
74+
invoke :'git:clone'
75+
invoke :'deploy:link_shared_paths'
76+
invoke :'bundle:install'
77+
invoke :'rails:db_migrate'
78+
invoke :'rails:assets_precompile'
79+
invoke :'deploy:cleanup'
80+
81+
on :launch do
82+
in_path(fetch(:current_path)) do
83+
command %{mkdir -p tmp/}
84+
command %{touch tmp/restart.txt}
85+
end
86+
end
87+
end
88+
89+
# you can use `run :local` to run tasks on local machine before of after the deploy scripts
90+
# run :local { say 'done' }
91+
end
92+
93+
# For help in making your deploy script, see the Mina documentation:
94+
#
95+
# - https://github.com/mina-deploy/mina/docs

config/routes.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
end
1010

1111
scope module: 'api' do
12+
scope module: 'v1' do
13+
get '/' => 'home#index_public'
14+
end
1215
namespace :v1 do
1316
resources :users
1417
end

config/secrets.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ test:
1919
# Do not keep production secrets in the repository,
2020
# instead read values from the environment.
2121
production:
22-
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
22+
secret_key_base: c6a6f984a7131c589565db9f2775f7302e608acd33b72376a2b7643849306ad9f4091a4cf343885b0455ea3ce9d4c3c7dfdc6c0152e5366d1c6c83c9260300a1

0 commit comments

Comments
 (0)