-
Notifications
You must be signed in to change notification settings - Fork 15
/
dev-env-setup.html
66 lines (66 loc) · 9.05 KB
/
dev-env-setup.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title>Development Environment Setup</title>
<style type="text/css">code{white-space: pre;}</style>
<link rel="stylesheet" href="../markdown.css" type="text/css" />
</head>
<body>
<h1 id="development-environment-setup">Development Environment Setup</h1>
<p><a href="index.html">Go up to the main SLP documents page</a> (<a href="index.md">md</a>)</p>
<p>This page is meant to help you get your local development environment up and running. The assumption is that you are developing on the provided Linux VirtualBox image. Mac OS X will work somewhat similarly, but you are on your own for configuring this on Windows.</p>
<p>In the directions below, your "local machine" is whatever account you are doing the development on; this will often be the VirtualBox image, but could be other things as well. On the course server, <code>team</code> is the tag of your team (which is the same as the account name).</p>
<h3 id="automatic-mysql-login">Automatic MySQL login</h3>
<p>To make it easier to automatically log into MySQL, you should edit a file named <code>~/.my.cnf</code>. It should contain exactly two lines:</p>
<pre><code>[client]
password=foobar</code></pre>
<p>Set <code>foobar</code> to your password. When you enter <code>mysql</code>, it will attempt to log you in as the same user you are already logged into Linux as (your UVa userid, or your team account), and the provided password. You will want to do this on both your local machine and the group account on the course server.</p>
<p>If you want to create mysql users or databases, or grant permissions to them for mysql users to access certain databases, see the <a href="mysql-intro.html">MySQL introduction</a> (<a href="mysql-intro.md">md</a>) and <a href="mysql-reference.html">MySQL reference</a> (<a href="mysql-reference.md">md</a>) pages.</p>
<h3 id="automatic-ssh-login">Automatic SSH login</h3>
<p>If you want to gain a command prompt on another machine, you can enter <code>ssh [email protected]</code>, which will attempt to log you in to the bar.edu server as the <code>foo</code> user. It will prompt you for a password each time. To prevent this, you can use ssh authentication keys.</p>
<p>To do so, enter <code>ssh-keygen</code> on your local machine; you will likely not want to enter a password. This will create two files: <code>~/.ssh/id_rsa.pub</code> and <code>~/.ssh/id_rsa</code>. These are your public and private keys, respectively, for logging in to places.</p>
<p>Log into the team account on the course server. Edit <code>~/.ssh/authorized_keys</code> (on the course server), creating the file if it does not exist. Copy and paste the contents of your <code>~/.ssh/id_rsa.pub</code> into that file, save, and exit.</p>
<p>Now when you attempt to log into the team account, it should not ask you for a password.</p>
<h3 id="automatic-github-login">Automatic Github login</h3>
<p>From the <a href="https://github.com/settings/ssh">Github :: profile :: SSH keys</a> page, you can enter your public key (the contents of the <code>~/.ssh/id_rsa.pub</code> file) as an SSH key. This will allow you to automatically log into github. Note that you will want to clone a repo via <code>git clone [email protected]:org/repo</code>, and <em>not</em> via the https URL.</p>
<h3 id="download-of-the-team-database">Download of the team database</h3>
<p>This section will describe how to automatically download the team database from the course server to your local machine. A number of things need to be set up first:</p>
<ul>
<li>You need to be able to automatically log in, via ssh, to the course server as the team account (see "automatic ssh login", above)</li>
<li>You need to be able to log in, without a password, to mysql as the team user on the course server</li>
<li>You need to be able to log in, without a password, to mysql as the team user on your <em>local</em> machine</li>
<li>If you use the team username and password on your local machine, then you don't have to change any of the configuration settings</li>
</ul>
<p>You can then execute the following command to download the database contents from the course server. Note that this will <strong><em>ERASE</em></strong> the local database!</p>
<pre><code>ssh team@server 'mysqldump database | gzip -9c -' | gzip -dc | mysql database</code></pre>
<p>Make sure the format is exactly as shown, including the location of the single quotes! You will need to change <code>team</code>, <code>server</code>, and <code>database</code> in that command. This command does a mysqldump on the server, and compresses it, and downloads that -- which is then uncompressed and restored to the local database.</p>
<p>This is a lot to remember -- and get right -- so you can put it into a Makefile:</p>
<pre><code>syncdb:
@echo Downloading the DB from the course server...
@ssh team@server 'mysqldump database | gzip -9c -' | gzip -dc | mysql database</code></pre>
<p>Remember that indented lines in a Makefile MUST be tabbed, and not spaces. You then only have to type <code>make syncdb</code>, and it will perform the download for you. The <code>@</code> before the various commands causes it to only display the results of that command, and not the command itself.</p>
<h3 id="deployment-options">Deployment options</h3>
<p>There are two ways to easily deploy your project to the team account. They don't work well with each other, so you should likely choose one or the other. They two options are rsync and github.</p>
<p>The rsync version allows you to deploy the current version you are working on, and you do not need to commit it (and push to github) to deploy a version to test. The github is easier, but you have to do a push to have any changes pushed to the server. Either one can be used, but the entire team will have to use the same method.</p>
<h3 id="rsync-deployment">Rsync deployment</h3>
<p>To configure rsync deployment, we are assuming that you can automatically log in, via ssh, to the course server as the team account (see "automatic ssh login", above).</p>
<p>What you are going to do here is enter an rsync command to upload the files to the course server. Rsync is tricky to get right, but it's a very powerful tool. Rsync is described in a bit more detail on the "uploading files to the server" section of the <a href="hw-frameworks.html">framework homework</a> (<a href="framework-hw.md">md</a>).</p>
<p>One you are in your project root's directory, you will enter a command similar to:</p>
<pre><code>rsync -C --del --progress -a ./ team@server:~/html/</code></pre>
<p>There are a lot of things that need to be changed on that line to make it work for you: <code>team</code>, <code>server</code>, and the directory (only the CakePHP projects will go into <code>~/html</code>). Furthermore, you may want to exclude certain files, such as your .htaccess files (for CakePHP), or the settings (for all projects). You can do this via the <code>--exclude file</code> flag.</p>
<p>The other issue with this command is that it MUST be executed from the <code>~/html/</code> (or equivalent) directory. It, too, is tricky to get right. So you can put it as a Makefile target:</p>
<pre><code>deploy:
rsync -C --del --progress -a --exclude foo/settings.py ./ team@server:~/html/</code></pre>
<p>Then, you only have to type <code>make publish</code> to publish it to the course server.</p>
<p>One can also deploy to localhost (the machine you are using). This will be of most use for the CakePHP projects, as the Rails and Django folks view the app differently. You can create a user on your local machine that has the same name as the team account on the course server, and do a publish there -- that command would look similar to the rsync of the previous section, but the course server is replaced with <code>localhost</code>. This works well as a <code>local</code> target, meaning you enter <code>make local</code> to publish it to the local machine. You will have to set up automatic ssh login. And note that any files that you exclude still have to be uploaded the very first time (and possibly edited).</p>
<h3 id="github-webhook-deployment">Github webhook deployment</h3>
<p>This information has moved to the <a href="github-webhook.html">Github webhook setup page</a> (<a href="github-webhook.md">md</a>).</p>
<h3 id="hybrid-approach">Hybrid approach</h3>
<p>ALternatively, you should set up a hybrid approach. You can use a deployment key to clone the git repo in the project account, but rather than have that updated automatically via a web hook, you instead only update it manually. This can be done via a single ssh command -- which, with auto-login set up, can easily be put into a Makefile:</p>
<pre><code>ssh project@server 'cd ~/html; git pull`</code></pre>
<p>Obviously, you will have to change the directory (and user and server host) as necessary.</p>
</body>
</html>