Skip to content

Commit 569b555

Browse files
Merge branch 'dev' into master
2 parents 52ef651 + 3086b19 commit 569b555

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+5672
-518
lines changed

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
NODE_ENV=dev
12
PORT=3232
23
SECRET_TOKEN=
34
SLACK_WEBHOOK_URL=
@@ -13,3 +14,9 @@ NOTIFICATION_FROM=
1314
ALLOW_NOTIFICATIONS=true
1415
SUCCESS_NOTIFICATIONS=false
1516
ERROR_NOTIFICATIONS=false
17+
18+
DATABASE_HOST=
19+
DATABASE_USER=
20+
DATABASE_PASSWORD=
21+
DATABASE_NAME=
22+
DATABASE_CLIENT=

.eslintrc.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"parser": "babel-eslint",
3+
"env": {
4+
"commonjs": true,
5+
"es2020": true,
6+
"node": true
7+
},
8+
"extends": "eslint:recommended",
9+
"parserOptions": {
10+
"ecmaVersion": 11
11+
},
12+
"rules": {
13+
"complexity":["warn", 4],
14+
"arrow-parens": 2,
15+
"no-mixed-spaces-and-tabs": 0,
16+
"no-console": 2,
17+
"indent": [
18+
"error",
19+
4
20+
],
21+
"linebreak-style": [
22+
"error",
23+
"unix"
24+
],
25+
"quotes": [
26+
"error",
27+
"single"
28+
],
29+
"semi": [
30+
"error",
31+
"never"
32+
]
33+
}
34+
}

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ _config.yml export-ignore
33
.gitignore export-ignore
44
CODE_OF_CONDUCT.md export-ignore
55
SECURITY.md export-ignore
6+
test export-ignore
7+
test.sh export-ignore
8+
precommit.sh export-ignore
9+
docs export-ignore

.github/workflows/node.js.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
node-version: [10.x, 12.x, 14.x]
19+
node-version: [12.x, 14.x]
2020

2121
steps:
2222
- uses: actions/checkout@v2
@@ -26,4 +26,8 @@ jobs:
2626
node-version: ${{ matrix.node-version }}
2727
- run: npm ci
2828
- run: npm run build --if-present
29+
- run: cp deployment.config.json.example deployment.config.json
30+
- run: cp .env.example .env
31+
- run: npm run migrate:dev
32+
- run: npm run seed:dev
2933
- run: npm test --if-present

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,8 @@ typings/
6161
.next
6262

6363
# Deployment config
64-
deployment.config.json
64+
deployment.config.json
65+
66+
# SQLITE
67+
*.sqlite
68+
*.sqlite3

README.md

Lines changed: 38 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -6,108 +6,41 @@
66
> Deploy you apps in seconds using the webhook feature
77
88
## 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 |

SECURITY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## Supported Versions
44
| Version | Supported |
55
| ------- | ------------------ |
6-
| 1.x.x | :white_check_mark: |
6+
| 1.3.x | :white_check_mark: |
7+
| 2.x.x | :white_check_mark: |
78

89

910
## Reporting a Vulnerability

app.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
require('dotenv').config()
22
const express = require('express')
3-
const cookieParser = require('cookie-parser')
43
const logger = require('morgan')
54

65
const githubRouter = require('./routes/github')
76
const bitbucketRouter = require('./routes/bitbucket')
87
const gitlabRouter = require('./routes/gitlab')
9-
// const verifyHostName = require('./middleware/verifyHostName')
8+
const web = require('./web/web')
109

11-
const app = express();
10+
const app = express()
1211

1312
app.use(logger('dev'))
1413
app.use(express.json())
1514
app.use(express.urlencoded({ extended: false }))
16-
app.use(cookieParser())
17-
// TODO This middleware does not work correctly app.use(verifyHostName())
1815

1916
app.use('/github', githubRouter)
2017
app.use('/bitbucket', bitbucketRouter)
2118
app.use('/gitlab', gitlabRouter)
19+
app.use('/api', web)
2220
app.all('*', (req, res) => {
23-
res.status(404).json({ error: `Sorry you cannot ${req.method} ${req.path}.` })
21+
res.status(404).json({ type: 'Error', message: `Sorry ${req.method} ${req.path} is not available` })
2422
})
2523

26-
module.exports = app;
24+
module.exports = app

config/mail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const mail = {
2-
/**The email host */
2+
/** The email host */
33
SMTP_HOST: process.env.SMTP_HOST || 'smtp.mailtrap.io',
44
SMTP_PORT: process.env.SMTP_PORT || 25,
55
SMTP_USERNAME: process.env.SMTP_USERNAME || '',

config/notifications.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
/**
22
* -------------------------------------------------------------------
3-
* This is where th notification config lives.
3+
* This is where th notification config lives.
44
* All these values can be overwritten by the environment variables
55
* -------------------------------------------------------------------
66
*/
77
const notificationConfig = {
8-
/**This is used to determine if notifications are enabled */
8+
/** This is used to determine if notifications are enabled */
99
allowNotifications: process.env.ALLOW_NOTIFICATIONS || false,
1010

11-
12-
/**
13-
* Your Slack webhook URL. If empty Slack notifications will be off
11+
/**
12+
* Your Slack webhook URL. If empty Slack notifications will be off
1413
* This is the URL you received when creating a Slack APP
1514
* Slack is ignored if this is null or false
16-
*
15+
*
1716
*/
1817
slackWebhookURL: process.env.SLACK_WEBHOOK_URL,
1918

20-
21-
/**
22-
* Notification Email
23-
* An email will be send to this email(s) according to
19+
/**
20+
* Notification Email
21+
* An email will be send to this email(s) according to
2422
* Your config
2523
* */
2624
notificationEmail: process.env.NOTIFICATION_EMAIL,
@@ -31,15 +29,14 @@ const notificationConfig = {
3129
*/
3230
notificationFrom: process.env.NOTIFICATION_FROM,
3331

34-
3532
/**
36-
* Get notifications on errors that occour
33+
* Get notifications on errors that occour
3734
* during deployment
3835
*/
3936
notifyOnErrors: process.env.ERROR_NOTIFICATIONS || true,
4037

4138
/**
42-
*
39+
*
4340
* This is used to set notification on successful deployments
4441
*/
4542
notifyOnSucess: process.env.SUCCESS_NOTIFICATIONS || true

0 commit comments

Comments
 (0)