deployer/docs/getting-started.md

139 lines
3.2 KiB
Markdown
Raw Normal View History

2019-07-02 08:05:15 +03:00
# Getting Started
2021-11-05 14:13:17 +01:00
What are we going to do in this tutorial:
2021-11-05 15:18:02 +01:00
- Provision a new server.
2021-11-05 14:13:17 +01:00
- Configure a deployment.
- Automate deployment via GitHub Actions.
2021-04-18 22:01:23 +02:00
2021-11-05 14:13:17 +01:00
Tutorial duration: **10 min**
2021-11-05 15:18:02 +01:00
2021-11-10 23:25:39 +01:00
First, [install the Deployer](installation.md):
2021-11-05 15:18:02 +01:00
2021-11-10 23:25:39 +01:00
```sh
curl -LO https://deployer.org/deployer.phar
mv deployer.phar /usr/local/bin/dep
chmod +x /usr/local/bin/dep
```
Now lets cd into the project repo and run following command:
2021-11-05 15:18:02 +01:00
2021-11-10 23:20:32 +01:00
```
2021-11-05 15:18:02 +01:00
dep init
```
Deployer will ask you a few question and after finishing you will have a
2021-11-10 23:25:39 +01:00
**deploy.php** or **deploy.yaml** file.
2021-11-05 15:18:02 +01:00
2021-11-05 16:09:34 +01:00
All framework recipes based on [common](recipe/common.md) recipe.
2021-11-10 23:25:39 +01:00
## Provision
2021-11-05 15:18:02 +01:00
:::note
If you already have configured webserver you may skip to
2021-11-10 23:25:39 +01:00
[deployment](#deploy).
2021-11-05 15:18:02 +01:00
:::
2021-11-10 23:25:39 +01:00
Now let's create a new VPS on Linode, DigitalOcean, Vultr, AWS, GCP, etc.
Make sure what image is **Ubuntu 20.04 LTS** as this version is supported via
2021-11-05 15:18:02 +01:00
Deployer [provision](recipe/provision.md) recipe.
2021-11-05 16:09:34 +01:00
Configure Reverse DNS or RDNS on your server, this will allow you to ssh into
2021-11-10 23:25:39 +01:00
server using domain name instead of IP address.
2021-11-05 15:18:02 +01:00
Now let's provision our server.
2021-11-10 23:20:32 +01:00
```
2021-11-05 15:18:02 +01:00
dep provision -o remote_user=root
```
2021-11-10 23:25:39 +01:00
We added `-o remote_user=root` to make Deployer use root user to connect to host
for provisioning.
2021-11-05 15:18:02 +01:00
2021-11-10 23:25:39 +01:00
Deployer will ask you a few questions during provisioning like php version,
2021-11-05 15:18:02 +01:00
database type, etc.
2021-11-05 16:09:34 +01:00
Provision will take around **~5min** and install everything we need to run a
site. Also, it will configure `deployer` user what we need to use to ssh to our
host and a new website was configured at [deploy_path](recipe/common.md#deploy_path).
2021-11-05 15:18:02 +01:00
2021-11-10 23:25:39 +01:00
After we have configured webserver let's deploy the project.
2021-11-05 15:18:02 +01:00
2021-11-10 23:25:39 +01:00
## Deploy
2021-11-05 15:18:02 +01:00
2021-11-10 23:25:39 +01:00
To deploy the project:
2021-11-10 23:20:32 +01:00
```
2021-11-05 15:18:02 +01:00
dep deploy
```
2021-11-10 23:25:39 +01:00
Ssh to host, for example, for editing _.env_ file.
2021-11-05 15:18:02 +01:00
2021-11-10 23:20:32 +01:00
```
2021-11-05 15:18:02 +01:00
dep ssh
```
2021-11-10 23:25:39 +01:00
Let's add a build step on our host:
```php
2021-11-05 16:09:34 +01:00
task('build', function () {
cd('{{release_path}}');
run('npm install');
run('npm run prod');
});
after('deploy:update_code', 'build');
```
2021-11-10 23:25:39 +01:00
Deployer has a useful task for examine what is currently deployed.
2021-11-10 23:20:32 +01:00
```
2021-11-05 16:09:34 +01:00
$ dep releases
task releases
2021-11-05 16:18:42 +01:00
+---------------------+--------- deployer.org -------+--------+-----------+
2021-11-05 16:09:34 +01:00
| Date (UTC) | Release | Author | Target | Commit |
+---------------------+-------------+----------------+--------+-----------+
| 2021-11-05 14:00:22 | 1 (current) | Anton Medvedev | HEAD | 943ded2be |
+---------------------+-------------+----------------+--------+-----------+
```
:::tip
During development [dep push](recipe/deploy/push.md) task maybe useful.
:::
2021-11-05 15:18:02 +01:00
## Deploy on push
2021-11-05 16:09:34 +01:00
Not let's use [GitHub Action for Deployer](https://github.com/deployphp/action).
Create `.github/workflows/deploy.yml` file with following content:
```yaml
name: deploy
on:
push:
branches: [ master ]
concurrency: production_environment
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
- name: Deploy
uses: deployphp/action@v1
with:
private-key: ${{ secrets.PRIVATE_KEY }}
dep: deploy
```
:::warning
The `concurrency: production_environment` is important as it prevents concurrent
deploys.
:::