Skip to content

Commit de71ecf

Browse files
committed
Prep for having ability to push to AWS server
- Add definition for AWS remote - Add function for pushing to remote - TODO: Update README with instructions
1 parent 544e16c commit de71ecf

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

fabfile.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from fabric.api import run, sudo, env, require, settings, local
1+
from fabric.api import run, sudo, env, require, settings, local, put
22
from fabric.contrib.files import exists
33
import subprocess
4+
import os
45

56
### VARIABLES ###
67

@@ -17,8 +18,8 @@
1718

1819
def vagrant():
1920
"""Defines the Vagrant virtual machine's environment variables.
20-
Local development and server will us this environment."""
21-
21+
Local development and server will use this environment.
22+
"""
2223
# Configure SSH things
2324
raw_ssh_config = subprocess.Popen(['vagrant', 'ssh-config'],
2425
stdout=subprocess.PIPE).communicate()[0]
@@ -31,6 +32,18 @@ def vagrant():
3132
# Development will happen on the master branch
3233
env.repo = ('origin', 'master')
3334

35+
def remote():
36+
"""Defines a remote server on AWS running Ubuntu 14.x, ideally with >1.5GB
37+
RAM.
38+
"""
39+
# Insert values for:
40+
env.hosts = 'ec2-52-13.us-west-2.compute.amazonaws.com' # Your public DNS
41+
env.key_filename = os.path.join('/', 'my.pem') # Path to your AWS .pem key
42+
43+
# Don't change unless you know what you are doing:
44+
env.base = '/www-shiny' # Default location for Shiny Server apps
45+
env.user = 'ubuntu' # Default username for AWS SSH login
46+
3447
### ROUTINES ###
3548

3649
def setup_vagrant():
@@ -39,11 +52,28 @@ def setup_vagrant():
3952
sub_add_repos()
4053
sub_install_packages()
4154
sub_install_shiny()
55+
reload_server()
56+
57+
def bootstrap():
58+
"""Sets up the remote environment"""
59+
require('hosts', provided_by=[remote])
60+
sub_add_repos()
61+
sub_install_packages()
62+
sub_install_shiny()
63+
reload_server()
4264

43-
def reload():
44-
require('hosts', provided_by=[vagrant])
65+
def reload_server():
66+
require('hosts', provided_by=[vagrant, remote])
4567
sudo('restart shiny-server')
4668

69+
def push():
70+
"""Pushes the current folder to the remote machine's Shiny apps folder"""
71+
require('hosts', provided_by=[remote])
72+
sudo('mkdir -p /www-shiny')
73+
sudo('chown -R ubuntu:ubuntu /www-shiny')
74+
sudo('rm -rf /www-shiny/*')
75+
put('./', '/www-shiny/')
76+
4777
### SUB-ROUTINES ###
4878

4979
def sub_add_repos():
@@ -92,10 +122,6 @@ def sub_install_shiny():
92122
sub_install_rmarkdown()
93123
sub_make_writeable_project()
94124

95-
# Restart VM
96-
local('vagrant reload')
97-
run('status shiny-server')
98-
99125
def sub_make_writeable_project():
100126
"""Creates a symlink from Shiny's web server folder to a shiny:shiny
101127
writeable folder for app development.
@@ -109,7 +135,6 @@ def sub_make_writeable_project():
109135
ln -s /www-shiny-writeable/ proj ;
110136
fi''')
111137

112-
113138
def sub_install_rmarkdown():
114139
"""Installs the packages required for Shiny to serve markdown documents.
115140
Haskell is a prerequisite that should have been installed earlier. Pandoc is

0 commit comments

Comments
 (0)