Skip to content

Commit 09da535

Browse files
committed
[Doc] Add tutorial "Cloning the Application Code on Remote Servers"
1 parent a7cc075 commit 09da535

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ EasyDeployBundle
3030

3131
* [Creating a Local SSH Configuration File](doc/tutorials/local-ssh-config.md)
3232
* [Troubleshooting Connection Issues to Remote SSH Servers](doc/tutorials/remote-ssh-config.md)
33+
* [Cloning the Application Code on Remote Servers](doc/tutorials/remote-code-cloning.md)
3334

3435
> **NOTE**
3536
> EasyDeploy does not "provision" servers (like installing a web server and the

Diff for: doc/default-deployer.md

+7
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ common for all deployers:
9898
* `->deployDir(string $path = '...')` (the directory in the remote server where
9999
the application is deployed)
100100

101+
> **NOTE**
102+
>
103+
> Depending on your local and remote configuration, cloning the repository code
104+
> in the remote servers may fail. Read [this tutorial][4] to learn about the
105+
> most common ways to clone code on remote servers.
106+
101107
### Symfony Application Options
102108

103109
The Symfony environment must be chosen carefully because, by default, commands
@@ -308,3 +314,4 @@ return new class extends DefaultDeployer
308314
[1]: http://capistranorb.com/
309315
[2]: https://github.com/everzet/capifony
310316
[3]: https://github.com/symfony/symfony-demo
317+
[4]: tutorials/remote-code-cloning.md

Diff for: doc/tutorials/remote-code-cloning.md

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
Cloning the Application Code on Remote Servers
2+
==============================================
3+
4+
Some deployment strategies clone on the remote servers the application code
5+
hosted on an external repository (e.g. GitHub). Depending on your local and
6+
remote configuration, this process may fail.
7+
8+
This article explains the most common solutions for those problems. The examples
9+
below use GitHub.com, but you can translate those ideas to other Git services,
10+
such as BitBucket and GitLab.
11+
12+
SSH Agent Forwarding
13+
--------------------
14+
15+
**Agent forwarding** is the strategy recommended by this bundle and used by
16+
default. If enabled, remote servers can use your local SSH keys to access other
17+
external services. First, execute this command in your local machine, to verify
18+
that you can access to GitHub web site using SSH:
19+
20+
```bash
21+
22+
23+
Hi <your-name-here>! You've successfully authenticated, but GitHub does not
24+
provide shell access.
25+
```
26+
27+
Now log in any of your remote servers and execute the same command:
28+
29+
* If you see the same output, agent forwarding is working and you can use it
30+
to deploy the applications. This option is enabled by default and can be
31+
changed with the `useSshAgentForwarding` option in your deployer.
32+
* If you encounter the error **Permission denied (publickey)**, check that:
33+
* The local SSH config file has not disabled agent forwarding for that host
34+
(see [this tutorial][1] for more details).
35+
* The remote SSH server hasn't disabled agent forwarding (see [this tutorial][2]
36+
for more details).
37+
* Read [this GitHub guide][3] to troubleshoot agent forwarding issues.
38+
39+
Deploy Keys
40+
-----------
41+
42+
If you can't or don't want to use SSH agent forwarding, the other simple way to
43+
clone the code on remote servers is using **deploy keys**. They are SSH keys
44+
stored on your remote servers and they grant access to a single GitHub
45+
repository. The key is attached to a given repository instead of to a personal
46+
user account. Follow these steps:
47+
48+
1. Log in into one of your remote servers.
49+
2. Execute this command to generate a new key:
50+
51+
```bash
52+
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
53+
```
54+
55+
Press `<Enter>` for all questions asked to use the default answers. This
56+
makes your key to not have a "passphrase", but don't worry because your
57+
key will still be safe.
58+
3. The command generates two files, one of the private key and the other one
59+
for the public key. The deploy key is the public key. Display its contents
60+
so you can copy them. For example: `cat ~/.ssh/id_rsa.pub` (you'll see some
61+
random characters that start with `ssh-rsa` and end with your own email).
62+
4. Go to the page of your code repository on GitHub and click on the **Settings**
63+
option (the URL is `https://github.com/<user-name>/<repo-name>/settings`).
64+
5. Click on the **Deploy keys** option on the sidebar menu.
65+
6. Click on the **Add deploy key** button, give it a name (e.g. `server-1`)
66+
and paste the contents of the public key that you copied earlier.
67+
7. Click on the **Add key** button to add the key and your remote server will
68+
now be able to clone that specific repository.
69+
8. If the same server needs access to other repositories, repeat the process
70+
to add the same public key in other repositories.
71+
9. If other servers need access to this repository, repeat the process to
72+
generate keys on those servers and add them in this repository.
73+
74+
Read this guide if you any problem generating the SSH keys:
75+
[Connecting to GitHub with SSH][4].
76+
77+
Other Cloning Techniques
78+
------------------------
79+
80+
If you can't or don't want to use SSH Agent Forwarding or Deploy Keys, you can
81+
use HTTPS Oauth Tokens and even create Machine Users and add them as
82+
collaborators in your GitHub repositories. Read [this guide][5] to learn more
83+
about those techniques.
84+
85+
[1]: local-ssh-config.md
86+
[2]: remote-ssh-config.md
87+
[3]: https://developer.github.com/v3/guides/using-ssh-agent-forwarding/
88+
[4]: https://help.github.com/articles/connecting-to-github-with-ssh/
89+
[5]: https://developer.github.com/v3/guides/managing-deploy-keys/

0 commit comments

Comments
 (0)