2016-11-28 03:05:23 +01:00
|
|
|
# Developing on a remote machine
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2016-11-28 03:05:23 +01:00
|
|
|
The Zulip developer environment works well on remote virtual machines. This can
|
|
|
|
be a good alternative for those with poor network connectivity or who have
|
|
|
|
limited storage/memory on their local machines.
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2016-11-29 23:16:51 +01:00
|
|
|
We recommend giving the Zulip development environment its own virtual
|
2019-06-27 00:04:40 +02:00
|
|
|
machine, running Ubuntu 16.04 or
|
|
|
|
18.04, with at least 2GB of memory. If the Zulip development
|
2016-11-29 23:16:51 +01:00
|
|
|
environment will be the only thing running on the remote virtual
|
|
|
|
machine, we recommend installing
|
2016-11-28 03:05:23 +01:00
|
|
|
[directly][install-direct]. Otherwise, we recommend the
|
2016-11-29 23:16:51 +01:00
|
|
|
[Vagrant][install-vagrant] method so you can easily uninstall if you
|
|
|
|
need to.
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2016-11-28 03:05:23 +01:00
|
|
|
## Connecting to the remote environment
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2017-01-15 05:13:22 +01:00
|
|
|
The best way to connect to your server is using the command line tool `ssh`.
|
2016-11-29 02:52:18 +01:00
|
|
|
|
|
|
|
* On macOS and Linux/UNIX, `ssh` is a part of Terminal.
|
|
|
|
* On Windows, `ssh` comes with [Bash for Git][git-bash].
|
|
|
|
|
|
|
|
Open *Terminal* or *Bash for Git*, and connect with the following:
|
|
|
|
|
|
|
|
```
|
|
|
|
$ ssh username@host
|
|
|
|
```
|
|
|
|
|
|
|
|
If you have poor internet connectivity, we recommend using
|
|
|
|
[Mosh](https://mosh.org/) as it is more reliable over slow or unreliable
|
|
|
|
networks.
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2018-10-20 05:52:38 +02:00
|
|
|
## Setting up user accounts
|
|
|
|
|
|
|
|
You will need a non-root user account with sudo privileges to setup
|
|
|
|
the Zulip development environment. If you have one already, continue
|
|
|
|
to the next section.
|
|
|
|
|
|
|
|
You can create a new user with sudo privileges by running the
|
|
|
|
following commands as root:
|
|
|
|
* You can create a `zulipdev` user by running the command `adduser
|
|
|
|
zulipdev`. Run through the prompts to assign a password and user
|
|
|
|
information. (You can pick any username you like for this user
|
|
|
|
account.)
|
|
|
|
* You can add the user to the sudo group by running the command
|
|
|
|
`usermod -aG sudo zulipdev`.
|
|
|
|
* Finally, you can switch to the user by running the command `su -
|
|
|
|
zulipdev` (or just login to that user using `ssh`).
|
|
|
|
|
2016-11-28 03:05:23 +01:00
|
|
|
## Setting up the development environment
|
2016-11-20 23:09:59 +01:00
|
|
|
|
2016-11-28 03:05:23 +01:00
|
|
|
After you have connected to your remote server, you need to install the
|
|
|
|
development environment.
|
2016-11-20 23:09:59 +01:00
|
|
|
|
2016-11-29 23:16:51 +01:00
|
|
|
If the Zulip development environment will be the only thing running on
|
|
|
|
the remote virtual machine, we recommend installing
|
|
|
|
[directly][install-direct]. Otherwise, we recommend the
|
|
|
|
[Vagrant][install-vagrant] method so you can easily uninstall if you
|
|
|
|
need to.
|
2016-11-20 23:09:59 +01:00
|
|
|
|
2018-03-13 17:44:17 +01:00
|
|
|
The main difference from the standard instructions is that for a
|
|
|
|
remote development environment, you'll need to run `export
|
|
|
|
EXTERNAL_HOST=<REMOTE_IP>:9991` in a shell before running `run-dev.py`
|
|
|
|
(and see also the `--interface=''` option documented below). If your
|
|
|
|
server has a static IP address, we recommend putting this command in
|
|
|
|
`~/.bashrc`, so you don't need to remember to run it every time. This
|
|
|
|
allows you to access Zulip running in your development environment
|
|
|
|
using a browser on another host.
|
2018-03-13 13:20:59 +01:00
|
|
|
|
2016-11-28 03:05:23 +01:00
|
|
|
## Running the development server
|
2016-11-20 23:09:59 +01:00
|
|
|
|
2016-11-29 20:13:55 +01:00
|
|
|
Once you have set up the development environment, you can start up the
|
2018-03-13 17:44:17 +01:00
|
|
|
development server with the following command in the directory where
|
2016-11-29 23:16:51 +01:00
|
|
|
you cloned Zulip:
|
2016-11-20 23:09:59 +01:00
|
|
|
|
|
|
|
```
|
2016-11-29 02:52:18 +01:00
|
|
|
./tools/run-dev.py --interface=''
|
2016-11-20 23:09:59 +01:00
|
|
|
```
|
|
|
|
|
2017-05-13 13:18:57 +02:00
|
|
|
This will start up the Zulip server on port 9991. You can then
|
|
|
|
navigate to `http://<REMOTE_IP>:9991` and you should see something like
|
|
|
|
this screenshot of the Zulip development environment:
|
2016-11-29 02:52:18 +01:00
|
|
|
|
2016-11-29 23:16:51 +01:00
|
|
|
![Image of Zulip development
|
2017-11-08 17:55:36 +01:00
|
|
|
environment](../images/zulip-dev.png)
|
2016-11-20 23:09:59 +01:00
|
|
|
|
2018-10-20 06:21:52 +02:00
|
|
|
The `--interface=''` option makes the Zulip development environment
|
|
|
|
accessible from any IP address (in contrast with the much more secure
|
2018-03-13 17:44:17 +01:00
|
|
|
default of only being accessible from localhost, which is great for
|
|
|
|
developing on your laptop).
|
|
|
|
|
2018-10-20 06:21:52 +02:00
|
|
|
To properly secure your remote development environment, you can
|
|
|
|
[port forward](https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding)
|
|
|
|
using ssh instead of running the development environment on an exposed
|
|
|
|
interface. For example, if you're running Zulip on a remote server
|
|
|
|
such as a DigitalOcean Droplet or an AWS EC2 instance, you can setup
|
|
|
|
port-forwarding to access Zulip by running the following command in
|
|
|
|
your terminal:
|
|
|
|
|
|
|
|
```
|
|
|
|
ssh -L 3000:127.0.0.1:9991 <username>@<remote_server_ip> -N
|
|
|
|
```
|
|
|
|
|
|
|
|
Now you can access Zulip by navigating to `http://127.0.0.1:3000` in
|
|
|
|
your local computer's browser.
|
2016-11-20 23:09:59 +01:00
|
|
|
|
2016-11-29 02:52:18 +01:00
|
|
|
For more information, see [Using the development
|
|
|
|
environment][rtd-using-dev-env].
|
2016-11-20 23:09:59 +01:00
|
|
|
|
2016-11-29 23:16:51 +01:00
|
|
|
## Making changes to code on your remote development server
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2016-11-29 23:16:51 +01:00
|
|
|
To see changes on your remote development server, you need to do one of the following:
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2016-11-29 21:27:00 +01:00
|
|
|
* [Edit locally](#editing-locally): Clone Zulip code to your computer and
|
|
|
|
then use your favorite editor to make changes. When you want to see changes
|
2016-11-29 23:16:51 +01:00
|
|
|
on your remote Zulip development instance, sync with Git.
|
2016-11-29 21:27:00 +01:00
|
|
|
* [Edit remotely](#editing-remotely): Edit code directly on your remote
|
2016-11-29 23:16:51 +01:00
|
|
|
Zulip development instance using a [Web-based IDE](#web-based-ide) (recommended for
|
2019-06-01 02:32:59 +02:00
|
|
|
beginners) or a [command line editor](#command-line-editors), or a
|
|
|
|
[desktop IDE](#desktop-gui-editors) using a plugin to sync your
|
|
|
|
changes to the server when you save.
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2016-11-28 03:05:23 +01:00
|
|
|
#### Editing locally
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2016-11-29 02:52:18 +01:00
|
|
|
If you want to edit code locally install your favorite text editor. If you
|
|
|
|
don't have a favorite, here are some suggestions:
|
|
|
|
|
2016-11-16 20:44:23 +01:00
|
|
|
* [atom](https://atom.io/)
|
|
|
|
* [emacs](https://www.gnu.org/software/emacs/)
|
|
|
|
* [vim](http://www.vim.org/)
|
|
|
|
* [spacemacs](https://github.com/syl20bnr/spacemacs)
|
|
|
|
* [sublime](https://www.sublimetext.com/)
|
|
|
|
|
2019-04-06 02:58:44 +02:00
|
|
|
Next, follow our [Git and GitHub Guide](../git/index.html) to clone and configure
|
2016-11-29 02:52:18 +01:00
|
|
|
your fork of zulip on your local computer.
|
|
|
|
|
|
|
|
Once you have cloned your code locally, you can get to work.
|
|
|
|
|
2016-11-29 21:27:00 +01:00
|
|
|
##### Syncing changes
|
|
|
|
|
2016-11-29 23:16:51 +01:00
|
|
|
The easiest way to see your changes on your remote development server
|
|
|
|
is to **push them to GitHub** and them **fetch and merge** them from
|
|
|
|
the remote server.
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2016-11-29 20:13:55 +01:00
|
|
|
For more detailed instructions about how to do this, see our [Git & GitHub
|
|
|
|
Guide][rtd-git-guide]. In brief, the steps are as follows.
|
|
|
|
|
|
|
|
On your **local computer**:
|
|
|
|
|
|
|
|
1. Open *Terminal* (macOS/Linux) or *Git for BASH*.
|
|
|
|
2. Change directory to where you cloned Zulip (e.g. `cd zulip`).
|
|
|
|
3. Use `git add` and `git commit` to stage and commit your changes (if you
|
|
|
|
haven't already).
|
|
|
|
4. Push your commits to GitHub with `git push origin branchname`.
|
|
|
|
|
|
|
|
Be sure to replace `branchname` with the name of your actual feature branch.
|
|
|
|
|
|
|
|
Once `git push` has completed successfully, you are ready to fetch the commits
|
2016-11-29 23:16:51 +01:00
|
|
|
from your remote development instance:
|
2016-11-29 20:13:55 +01:00
|
|
|
|
2016-11-29 23:16:51 +01:00
|
|
|
1. In *Terminal* or *Git BASH*, connect to your remote development
|
|
|
|
instance with `ssh user@host`.
|
2016-11-29 20:13:55 +01:00
|
|
|
2. Change to the zulip directory (e.g., `cd zulip`).
|
|
|
|
3. Fetch new commits from GitHub with `git fetch origin`.
|
|
|
|
4. Change to the branch you want to work on with `git checkout branchname`.
|
|
|
|
5. Merge the new commits into your branch with `git merge origin/branchname`.
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2016-11-28 03:05:23 +01:00
|
|
|
#### Editing remotely
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2019-06-01 02:32:59 +02:00
|
|
|
There are a few good ways to edit code in your remote development
|
|
|
|
environment:
|
2016-11-29 21:27:00 +01:00
|
|
|
|
2019-06-01 02:32:59 +02:00
|
|
|
* With a command-line editor like vim or emacs run over SSH.
|
|
|
|
* With a desktop GUI editor like VS Code or Atom and a plugin for
|
|
|
|
syncing your changes to the remote server.
|
|
|
|
* With a web-based IDE like CodeAnywhere.
|
2016-11-29 21:27:00 +01:00
|
|
|
|
2019-06-01 02:32:59 +02:00
|
|
|
We document these options below; we recommend using whatever editor
|
|
|
|
you prefer for development in general.
|
2016-11-29 21:27:00 +01:00
|
|
|
|
2019-06-01 02:32:59 +02:00
|
|
|
##### Desktop GUI editors
|
2016-11-29 21:27:00 +01:00
|
|
|
|
2019-06-01 02:32:59 +02:00
|
|
|
If you use [TextMate](https://macromates.com), Atom, VS Code, or a
|
|
|
|
similar GUI editor, tools like
|
|
|
|
[rmate](https://github.com/textmate/rmate) that are designed to
|
|
|
|
integrate that editor with remote development over SSH allow you to
|
|
|
|
develop remotely from the comfort of your local machine.
|
2019-05-28 17:26:05 +02:00
|
|
|
|
2019-06-01 02:32:59 +02:00
|
|
|
Similar packages/extensions exist for other popular code editors as
|
|
|
|
well; contributions of precise documentation for them are welcome!
|
2019-05-28 17:26:05 +02:00
|
|
|
|
|
|
|
To setup [rmate](https://github.com/textmate/rmate) for VS Code:
|
|
|
|
1. Install the extension
|
|
|
|
[Remote VSCode](https://marketplace.visualstudio.com/items?itemName=rafaelmaiolla.remote-vscode).
|
|
|
|
2. On your remote machine, run:
|
|
|
|
```
|
|
|
|
$ curl -Lo ~/bin/rmate https://raw.githubusercontent.com/textmate/rmate/master/bin/rmate
|
|
|
|
$ chmod a+x ~/bin/rmate
|
|
|
|
```
|
|
|
|
3. Make sure the remote server is running in VS Code (you can force-start through the Command Palette).
|
|
|
|
4. SSH to your remote machine using
|
|
|
|
```
|
|
|
|
$ ssh -R 52698:localhost:52698 user@example.org
|
|
|
|
```
|
|
|
|
5. On your remote machine, run
|
|
|
|
```
|
|
|
|
$ rmate [options] file
|
|
|
|
```
|
|
|
|
and the file should open up in VS Code. Any changes you make now will be saved remotely.
|
|
|
|
|
2016-11-29 21:27:00 +01:00
|
|
|
##### Command line editors
|
|
|
|
|
2016-11-29 23:16:51 +01:00
|
|
|
Another way to edit directly on the remote development server is with
|
|
|
|
a command line text editor on the remote machine.
|
2016-11-29 21:27:00 +01:00
|
|
|
|
|
|
|
Two editors often available by default on Linux systems are:
|
|
|
|
|
|
|
|
* **Nano**: A very simple, beginner-friendly editor. However, it lacks a lot of
|
|
|
|
features useful for programming, such as syntax highlighting, so we only
|
|
|
|
recommended it for quick edits to things like configuration files. Launch by
|
|
|
|
running command `nano <filename>`. Exit by pressing *control-X*.
|
|
|
|
|
|
|
|
* **[Vim](http://www.vim.org/)**: A very powerful editor that can take a while
|
|
|
|
to learn. Launch by running `vim <filename>`. Quit Vim by pressing *escape*,
|
|
|
|
typing `:q`, and then pressing *return*. Vim comes with a program to learn it
|
|
|
|
called `vimtutor` (just run that command to start it).
|
|
|
|
|
|
|
|
Other options include:
|
2016-11-29 02:52:18 +01:00
|
|
|
|
2016-11-16 20:44:23 +01:00
|
|
|
* [emacs](https://www.gnu.org/software/emacs/)
|
|
|
|
* [spacemacs](https://github.com/syl20bnr/spacemacs)
|
|
|
|
|
2019-06-01 02:32:59 +02:00
|
|
|
##### Web-based IDE
|
|
|
|
|
|
|
|
If you are relatively new to working on the command line, or just want to get
|
|
|
|
started working quickly, we recommend web-based IDE
|
|
|
|
[Codeanywhere][codeanywhere].
|
|
|
|
|
|
|
|
To setup Codeanywhere for Zulip:
|
|
|
|
|
|
|
|
1. Create a [Codeanywhere][codeanywhere] account and log in.
|
|
|
|
2. Create a new **SFTP-SSH** project. Use *Public key* for authentication.
|
|
|
|
3. Click **GET YOUR PUBLIC KEY** to get the new public key that
|
|
|
|
Codeanywhere generates when you create a new project. Add this public key to
|
|
|
|
`~/.ssh/authorized_keys` on your remote development instance.
|
|
|
|
4. Once you've added the new public key to your remote development instance, click
|
|
|
|
*CONNECT*.
|
|
|
|
|
|
|
|
Now your workspace should look similar this:
|
|
|
|
![Codeanywhere workspace][img-ca-workspace]
|
|
|
|
|
2016-11-28 03:05:23 +01:00
|
|
|
#### Next steps
|
2016-11-16 20:44:23 +01:00
|
|
|
|
2016-11-29 02:52:18 +01:00
|
|
|
Next, read the following to learn more about developing for Zulip:
|
|
|
|
|
|
|
|
* [Git & GitHub Guide][rtd-git-guide]
|
|
|
|
* [Using the Development Environment][rtd-using-dev-env]
|
|
|
|
* [Testing][rtd-testing]
|
2016-11-28 02:50:33 +01:00
|
|
|
|
2019-04-06 02:58:44 +02:00
|
|
|
[install-direct]: ../development/setup-advanced.html#installing-directly-on-ubuntu-debian-centos-or-fedora
|
|
|
|
[install-vagrant]: ../development/setup-vagrant.html
|
|
|
|
[rtd-git-guide]: ../git/index.html
|
|
|
|
[rtd-using-dev-env]: using.html
|
|
|
|
[rtd-testing]: ../testing/testing.html
|
2016-11-29 02:52:18 +01:00
|
|
|
[git-bash]: https://git-for-windows.github.io/
|
2016-11-29 21:27:00 +01:00
|
|
|
[codeanywhere]: https://codeanywhere.com/
|
2017-11-08 17:55:36 +01:00
|
|
|
[img-ca-settings]: ../images/codeanywhere-settings.png
|
|
|
|
[img-ca-workspace]: ../images/codeanywhere-workspace.png
|
2018-11-27 16:08:43 +01:00
|
|
|
|
|
|
|
## Using an nginx reverse proxy
|
|
|
|
|
|
|
|
For some applications (e.g. developing an OAuth2 integration for
|
|
|
|
Facebook), you may need your Zulip development to have a valid SSL
|
|
|
|
certificate. While `run-dev.py` doesn't support that, you can do this
|
|
|
|
with an `nginx` reverse proxy sitting in front of `run-dev.py.`.
|
|
|
|
|
|
|
|
The following instructions assume you have a Zulip Droplet working and
|
|
|
|
that the user is `zulipdev`; edit accordingly if the situation is
|
|
|
|
different.
|
|
|
|
|
|
|
|
1. First, get an SSL certificate; you can use
|
2019-04-06 02:58:44 +02:00
|
|
|
[our certbot wrapper script used for production](../production/ssl-certificates.html#certbot-recommended)
|
2018-11-27 16:08:43 +01:00
|
|
|
by running the following commands as root:
|
|
|
|
```
|
|
|
|
# apt install -y crudini
|
|
|
|
mkdir -p /var/lib/zulip/certbot-webroot/
|
|
|
|
# if nginx running this will fail and you need to run `service nginx stop`
|
|
|
|
/home/zulipdev/zulip/scripts/setup/setup-certbot \
|
2019-03-19 17:10:43 +01:00
|
|
|
hostname.example.com --no-zulip-conf \
|
2018-11-27 16:08:43 +01:00
|
|
|
--email=username@example.com --method=standalone
|
|
|
|
```
|
|
|
|
|
|
|
|
1. Install nginx configuration:
|
|
|
|
|
|
|
|
```
|
|
|
|
apt install -y nginx-full
|
2019-04-12 01:24:57 +02:00
|
|
|
cp -a /home/zulipdev/zulip/tools/droplets/zulipdev /etc/nginx/sites-available/
|
2018-11-27 16:08:43 +01:00
|
|
|
ln -nsf /etc/nginx/sites-available/zulipdev /etc/nginx/sites-enabled/
|
|
|
|
nginx -t # Verifies your nginx configuration
|
|
|
|
service nginx reload # Actually enabled your nginx configuration
|
|
|
|
```
|
|
|
|
|
|
|
|
1. Edit `zproject/dev_settings.py` to set `EXTERNAL_URI_SCHEME =
|
|
|
|
"https://"`, so that URLs served by the development environment
|
|
|
|
will be HTTPS.
|
|
|
|
|
|
|
|
1. Start the Zulip development environment with the following command:
|
|
|
|
```
|
|
|
|
env EXTERNAL_HOST="hostname.example.com" ./tools/run-dev.py --interface=''
|
|
|
|
```
|