|
6 | 6 | > Deploy you apps in seconds using the webhook feature |
7 | 7 |
|
8 | 8 | ## Setup |
9 | | -1. clone this repo and open a terminal in the repo |
10 | | -2. Install dependencies `npm i` or `yarn` |
11 | | -3. Create the deployments config `cp deployment.config.json.example deployment.config.json` |
12 | | -4. Add your config and Start the server |
13 | | - |
14 | | -## Configuration |
15 | | -Your Deployment configurations live in the `deployment.config.json` file. |
16 | | -### Sample Config |
17 | | -```json |
18 | | -[ |
19 | | - { |
20 | | - "name": "Awesome-App", |
21 | | - "command": "cd path && git pull" |
22 | | - } |
23 | | -] |
24 | | -``` |
25 | | -It is basically an array. |
26 | | -If your repository is private, you may want to use [deploy keys](https://developer.github.com/v3/guides/managing-deploy-keys/) or cache your git credentials with the git credentials helper. |
27 | | -```bash |
28 | | -$ git config --global credential.helper 'cache --timeout=600' |
29 | | -``` |
30 | | -The command above would cache your credentials for 600 seconds. You might want to set-up a cron job to be doing this atleast once a day. |
31 | | -```bash |
32 | | -$ sudo crontab -e |
33 | | -$ 29 0 * * * git config --global credential.helper 'cache --timeout=31556952' |
34 | | -``` |
35 | | -The cron job above runs everyday at 12:30 AM in your server's local time. |
36 | | -#### Params |
37 | | -1. name: This is the name of your repo as it is on github. eg `opensource254/deployer` would be deployer. |
38 | | -2. Command: The bash command you want to run. This is basically a deploy command. Eg. For an Expressjs application using `pm2` this would be `cd <full path> && git pull && npm i && npm restart [process-id]`. Or you could insert the path of the script to be excecuted. |
39 | | -`bash path-to-script/script.sh` or `bash ./path-to-script/script.sh`. |
40 | | -*If you want to change the port that this app runs, create a `.env` file and add `PORT=<prefered_port>`* |
41 | | - |
42 | | -At this point, Your endpoint is ready for webhooks. It would be a great idea to run this behind a reverse proxy and give it a domain or a subdomain like. `mydomain.com` Then on the Github webhook settings, |
43 | | -1. webhook url `https://mydomain.com/<provider>` |
44 | | -2. Content Type `application/json` |
45 | | -The provider can be any of these |
46 | | -* github |
47 | | -* gitlab |
48 | | -* bitbucket |
49 | | - |
50 | | -## Security |
51 | | -* Currently only the Github security is supported. |
52 | | -* All the repos/webhooks SHOULD use on key provided in the .env |
53 | | -```env |
54 | | -SECRET=<your-secret> |
55 | | -``` |
56 | | -Add this secret to your webhook secret too. |
57 | | -* If a security check fails, the endpoint will respond with error 403 |
58 | | - |
59 | | -## Notifications |
60 | | -Two notifications channels are currently supported. |
61 | | -* Email (The current supported protocal is SMTP) |
62 | | -* Slack |
63 | | -Turning notifications on |
64 | | -```env |
65 | | -ALLOW_NOTIFICATIONS=true |
66 | | -// Notify on successful deployment |
67 | | -SUCCESS_NOTIFICATIONS=false |
68 | | -// Notify on failures/warnings |
69 | | -ERROR_NOTIFICATIONS=false |
70 | | -``` |
71 | | - |
72 | | -### Email Configuration |
73 | | -Add the config details in the .env file. |
74 | | -example |
75 | | -```env |
76 | | -SMTP_HOST=smtp.mailtrap.io |
77 | | -SMTP_PORT=2525 |
78 | | -SMTP_USERNAME= |
79 | | -SMTP_PASSWORD= |
80 | | -
|
81 | | -// The email to send notifications to |
82 | | -NOTIFICATION_EMAIL= |
83 | | -// The from address that will be shown in the email |
84 | | -NOTIFICATION_FROM= |
85 | | -``` |
86 | | -### Slack Configuration |
87 | | -Slack config is as simple as adding the webhook config. |
88 | | -Create a Slack app and add the webhook url for the app to `.env` like below |
89 | | -```env |
90 | | -SLACK_WEBHOOK_URL= |
91 | | -``` |
92 | | - |
93 | | -## Debugging |
94 | | -Configuration erros are logged in the error.log file. This file is not version controlled. |
95 | | -```log |
96 | | -Sat, 13 Jun 2020 10:00:10 GMT Config: your-awesome-config, Error: /bin/sh: 1: c: not found |
97 | | -Sat, 13 Jun 2020 10:00:18 GMT Config: your-awesome-config, Error: /bin/sh: 1: c: not found |
98 | | -Sat, 13 Jun 2020 10:01:58 GMT Config: your-awesome-config, Error: /bin/sh: 1: ks: not found |
99 | | -``` |
100 | | - |
101 | | -## TODO |
102 | | -- [x] Basic functionality |
103 | | -- [x] Refactor |
104 | | -- [x] Webhook Security |
105 | | -- [x] Notifications |
106 | | -- [ ] Web interface |
107 | | - |
108 | | -## Contributing |
109 | | -Please visit our [guidelines](https://opensource254.github.io/guidelines) |
110 | | - |
111 | | -## Disclaimer |
112 | | -This project has not been properly tested use it at your own risk. |
113 | | - |
| 9 | +1. Clone this repo and open a terminal in the repo |
| 10 | +2. Install dependencies `npm i` or `npm insall`. Or you can use yarn if you wish |
| 11 | +3. Copy `.env.example` to `.env` and edit the necessary entries |
| 12 | +4. Start your server. |
| 13 | + |
| 14 | +*All the deployment config is stored in your database so you need to login in using your client* |
| 15 | +If you don't have your own client you can use [this](https://github.com/opensource254/deployer-client). |
| 16 | +### Using the client |
| 17 | +_Docs coming soon_ |
| 18 | + |
| 19 | +<!-- // TODO update the new docs --> |
| 20 | + |
| 21 | +## Endpoints |
| 22 | +API endpoints |
| 23 | +### Authentication |
| 24 | +| Path | Method | Description | Parameters | |
| 25 | +|:-----------------|:----------------|:----------------------------------|:-----------------------| |
| 26 | +| `/api` | GET |The API root | None | |
| 27 | +| `/api/regsiter` | POST |Create a new account | `name,email, password` | |
| 28 | +| `/api/login` | POST |Authenticate a user | `email,password` | |
| 29 | +| `/api/logout` | POST |End the session of the current user| none | |
| 30 | +| `/api/user` | GET |Get the current authenticated user | none | |
| 31 | + |
| 32 | +### Config routes |
| 33 | +| Path | Method | Description | Parameters | |
| 34 | +|:-------------------|:------------|:----------------------------------|:---------------------------| |
| 35 | +| `/api/config` | GET | Get all the configs | none | |
| 36 | +| `/api/config/{id}` | GET | Get a config by database ID | none | |
| 37 | +| `/api/config` | POST | Create a config | `name,description,command` | |
| 38 | +| `/api/config/{id}` | DELETE | Delete a config from the database | none | |
| 39 | +| `/api/config/{id}` | PUT/PATH | Update a config in the database | `name,description,command` | |
| 40 | + |
| 41 | +### Webhooks |
| 42 | +| Path | Method | Description | |
| 43 | +|:-------------|:-------|:-----------------------------| |
| 44 | +| `/github` | POST | Github's webhook listener | |
| 45 | +| `/bitbucket` | POST | Bitbucket's webhook listener | |
| 46 | +| `/gitlab` | POST | Gitlab's webhook listener | |
0 commit comments