Shashank Kaul
5 years ago
commit
c43b403d1a
3 changed files with 85 additions and 0 deletions
@ -0,0 +1,4 @@ |
|||||
|
FROM node:latest |
||||
|
COPY deploy.js . |
||||
|
RUN npm install -g caprover |
||||
|
CMD ["node", "deploy.js"] |
@ -0,0 +1,46 @@ |
|||||
|
# drone-caprover-deploy |
||||
|
|
||||
|
Drone plugin to deploy to a caprover app using a tar of the required files. |
||||
|
|
||||
|
**Note**: You must have a captain-definition file present in the root of your repository. |
||||
|
|
||||
|
## Configuration |
||||
|
|
||||
|
A sample configuration which includes all settings will look like this |
||||
|
|
||||
|
```yaml |
||||
|
{ |
||||
|
name: "deploy", |
||||
|
image: "drone-caprover-deploy", |
||||
|
settings: { |
||||
|
app_name: "core", # Required: Caprover application name |
||||
|
password: { # Required: Caprover root password |
||||
|
from_secret: "cap_password" |
||||
|
}, |
||||
|
host: { # Required: Caprover url |
||||
|
from_secret: "cap_url" |
||||
|
}, |
||||
|
tar_include: [ # Optional: Items to include in the tar file. Will zip the entire repo if not specified. |
||||
|
"file1", |
||||
|
"file2" |
||||
|
], |
||||
|
suffixes: { # Optional: If provided, when the current branch for the job matches some "branch_name" key, the "suffix field" will be appended to the "app_name" value. This is useful if you want to condense your repo deploys into a single CI step. |
||||
|
"branch_name": "suffix field", |
||||
|
"develop": "-staging", |
||||
|
... |
||||
|
}, |
||||
|
}, |
||||
|
when: { |
||||
|
status: [ |
||||
|
"success" |
||||
|
], |
||||
|
... |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
What the above example will do: |
||||
|
|
||||
|
- Build a tar file which contains 'file1' and 'file2' |
||||
|
- Once built, will deploy to the host specified in the 'cap_url' secret using the 'cap_password' secret. |
||||
|
- When running on branch 'develop' it will deploy to the 'core-staging' application. |
@ -0,0 +1,35 @@ |
|||||
|
const { execSync } = require("child_process"); |
||||
|
|
||||
|
const isNotValidString = str => !(typeof str === "string" && str.length > 1); |
||||
|
|
||||
|
let APP_NAME = process.env.PLUGIN_APP_NAME; |
||||
|
const CAP_PASSWORD = process.env.PLUGIN_PASSWORD; |
||||
|
const CAP_HOST = process.env.PLUGIN_HOST; |
||||
|
|
||||
|
const INCLUDE_FILES = process.env.PLUGIN_TAR_INCLUDE |
||||
|
? process.env.PLUGIN_TAR_INCLUDE.split(",").join(" ") |
||||
|
: "."; |
||||
|
|
||||
|
const SUFFIXES = process.env.PLUGIN_SUFFIXES |
||||
|
? JSON.parse(process.env.PLUGIN_SUFFIXES) |
||||
|
: ""; |
||||
|
|
||||
|
const DRONE_BRANCH = process.env.DRONE_BRANCH; |
||||
|
|
||||
|
if ( |
||||
|
isNotValidString(APP_NAME) || |
||||
|
isNotValidString(CAP_PASSWORD || isNotValidString(CAP_HOST)) |
||||
|
) { |
||||
|
console.error("Invalid usage. Please check documentation"); |
||||
|
process.exit(1); |
||||
|
} |
||||
|
|
||||
|
if (SUFFIXES !== "") { |
||||
|
APP_NAME = APP_NAME + SUFFIXES[DRONE_BRANCH]; |
||||
|
} |
||||
|
|
||||
|
execSync(`tar -cf app.tar ${INCLUDE_FILES}`); |
||||
|
|
||||
|
execSync( |
||||
|
`caprover deploy --caproverUrl ${CAP_HOST} --capPassword ${CAP_PASSWORD} --caproverApp ${APP_NAME} --tarFile app.tar`, |
||||
|
); |
Loading…
Reference in new issue