Skip to content
This repository was archived by the owner on Mar 16, 2026. It is now read-only.

Commit cf08792

Browse files
committed
Merge branch 'master' of github.com:lucaperret/drone-now
2 parents 22e478e + 9e27fc9 commit cf08792

4 files changed

Lines changed: 161 additions & 49 deletions

File tree

.drone.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pipeline:
33
image: plugins/docker
44
secrets: [ docker_username, docker_password ]
55
repo: lucap/drone-now
6-
auto_tag: true
76
when:
87
event: tag
8+
branches:
9+
- master

DOCS.md

Lines changed: 88 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,87 +8,148 @@ logo: now.svg
88
image: lucap/drone-now
99
---
1010

11-
The Now plugin deploy your build to [now.sh](https://zeit.co/now). The below pipeline configuration demonstrates simple usage:
11+
The Now plugin deploy your build to [now.sh](https://zeit.co/now).
12+
13+
The below pipeline configuration demonstrates simple usage:
14+
15+
Note: `deploy_name` is an optional parameter. If it is not given now.sh will use name of the working directory .
1216

1317
```yaml
1418
pipeline:
1519
now:
1620
image: lucap/drone-now
17-
token: xxxxx
18-
name: deployment-name
21+
deploy_name: deployment-name
22+
now_token: keep-this-secret
1923
```
2024
21-
Example configuration for assigning [Aliases and Domains](https://zeit.co/docs/features/aliases):
25+
Or use the secret NOW_TOKEN instead, if you supply both the plugin will use the `now_token` parameter first
2226

2327
```diff
2428
pipeline:
2529
now:
2630
image: lucap/drone-now
27-
token: xxxxx
28-
- name: deployment-name
29-
+ alias: my-deployment-alias
31+
deploy_name: deployment-name
32+
- now_token: keep-this-secret
33+
+ secrets: [ now_token ]
3034
```
3135

32-
Example configuration with custom [Path Aliases](https://zeit.co/docs/features/path-aliases):
36+
Set the directory you want to deploy. See the [Deployment Documentation](https://zeit.co/docs/getting-started/deployment#) for more info.
3337

3438
```diff
3539
pipeline:
3640
now:
3741
image: lucap/drone-now
38-
token: xxxxx
39-
- alias: my-deployment-alias
40-
+ rules_domain: example.com
41-
+ rules_file: rules.json
42+
deploy_name: deployment-name
43+
secrets: [ now_token ]
44+
+ directory: public
4245
```
4346

44-
Example configuration for [Scaling](https://zeit.co/docs/getting-started/scaling):
47+
Example configuration with team scope:
4548

4649
```diff
4750
pipeline:
4851
now:
4952
image: lucap/drone-now
50-
token: xxxxx
51-
- rules_domain: example.com
52-
- rules_file: rules.json
53-
+ scale: 2
53+
deploy_name: deployment-name
54+
secrets: [ now_token ]
55+
- directory: public
56+
+ team: myteam
5457
```
5558

59+
5660
Example configuration to enforce type (by default, it's detected automatically):
5761

5862
```diff
5963
pipeline:
6064
now:
6165
image: lucap/drone-now
62-
token: xxxxx
63-
- scale: 2
66+
deploy_name: deployment-name
67+
secrets: [ now_token ]
68+
- team: myteam
6469
+ type: npm
6570
```
6671

67-
Example configuration using token from secrets:
72+
Example configuration for assigning [Aliases and Domains](https://zeit.co/docs/features/aliases):
6873

6974
```diff
7075
pipeline:
7176
now:
7277
image: lucap/drone-now
73-
- token: xxxxx
74-
+ secrets: [ now_token ]
78+
deploy_name: deployment-name
79+
secrets: [ now_token ]
80+
- type: npm
81+
+ alias: my-deployment-alias
82+
```
83+
84+
Example configuration for [Cleaning Up Old Deployments](https://zeit.co/docs/other/faq#how-do-i-remove-an-old-deployment):
85+
86+
Note: You must set the `alias` parameter with `cleanup`.
87+
88+
```diff
89+
pipeline:
90+
now:
91+
image: lucap/drone-now
92+
deploy_name: deployment-name
93+
secrets: [ now_token ]
94+
+ alias: my-deployment-alias
95+
+ cleanup: true
96+
```
97+
98+
Example configuration with custom [Path Aliases](https://zeit.co/docs/features/path-aliases):
99+
100+
```diff
101+
pipeline:
102+
now:
103+
image: lucap/drone-now
104+
deploy_name: deployment-name
105+
secrets: [ now_token ]
106+
- alias: my-deployment-alias
107+
- cleanup: true
108+
+ rules_domain: example.com
109+
+ rules_file: rules.json
75110
```
76111

112+
Example configuration for [Scaling](https://zeit.co/docs/getting-started/scaling):
113+
114+
```diff
115+
pipeline:
116+
now:
117+
image: lucap/drone-now
118+
deploy_name: deployment-name
119+
secrets: [ now_token ]
120+
- rules_domain: example.com
121+
- rules_file: rules.json
122+
+ scale: 2
123+
```
124+
125+
77126
# Secret Reference
78127

79128
now_token
80129
: Now token
81130

82131
# Parameter Reference
83132

84-
token
85-
: Now token
133+
now_token
134+
: Your API token (can also be set implicitly with a secret named NOW_TOKEN)
86135

87-
name
136+
deploy_name
88137
: Set the name of the deployment
89138

139+
directory
140+
: The directory you want to deploy
141+
142+
team
143+
: Set the team scope
144+
145+
type
146+
: Deployment type (docker, npm, static)
147+
90148
alias
91-
: Target Now.sh subdomain or domain
149+
: Target now.sh subdomain or domain
150+
151+
cleanup
152+
: Equivalent to `now rm --safe --yes $alias`
92153

93154
rules_domain
94155
: Your domain
@@ -97,7 +158,4 @@ rules_file
97158
: File that contain set of rules
98159

99160
scale
100-
: Min and Max scaling values
101-
102-
type
103-
: Deployment type (docker, npm, static)
161+
: Min and Max scaling values

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ Deploy the working directory to now.
2525

2626
```bash
2727
docker run --rm \
28-
-e PLUGIN_TOKEN=xxxxx \
28+
-e NOW_TOKEN=xxxxxxx \
29+
-e PLUGIN_DEPLOY_NAME=my-deployment-name \
2930
-e PLUGIN_ALIAS=my-deployment-alias.now.sh \
3031
-v $(pwd):$(pwd) \
3132
-w $(pwd) \
@@ -38,6 +39,10 @@ docker run --rm \
3839
pipeline:
3940
now:
4041
image: lucap/drone-now
41-
token: xxxxx
42-
alias: my-deployment-alias.now.sh
42+
deploy_name: my-deployment-name
43+
type: static
44+
team: xxxxxxxx
45+
directory: public
46+
alias: my.deployment.com
47+
secrets: [ now_token ]
4348
```

script.sh

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,97 @@
11
#!/bin/sh
22
set -e
33

4-
NOW_TOKEN_OPTION="--token=$PLUGIN_TOKEN"
5-
NOW_DEPLOY_OPTIONS="${NOW_TOKEN_OPTION} --no-clipboard"
4+
NOW_DEPLOY_OPTIONS=" --no-clipboard"
5+
NOW_AUTH=""
66

7-
if [ -n "$PLUGIN_NAME" ]
7+
# Get the token or error
8+
if [ -z "$PLUGIN_NOW_TOKEN" ]
89
then
9-
NOW_DEPLOY_OPTIONS="${NOW_DEPLOY_OPTIONS} --name ${PLUGIN_NAME}"
10+
# No explicit token provided, check for secret
11+
if [ -z "$NOW_TOKEN" ]
12+
then
13+
echo "> Error!! either the parameter now_token or the secret NOW_TOKEN is required!"
14+
exit 1;
15+
else
16+
PLUGIN_NOW_TOKEN="$NOW_TOKEN"
17+
fi
1018
fi
1119

12-
if [ -n "$PLUGIN_TYPE" ]
20+
if [ -n "$PLUGIN_TEAM" ]
21+
then
22+
echo "> adding custom team scope $PLUGIN_TEAM"
23+
NOW_TEAM_OPTION="--team $PLUGIN_TEAM"
24+
else
25+
echo "> No custom team scope provided."
26+
fi
27+
28+
NOW_AUTH="$NOW_AUTH --token $PLUGIN_NOW_TOKEN $NOW_TEAM_OPTION"
29+
30+
if [ -n "$PLUGIN_DEPLOY_NAME" ]
1331
then
14-
NOW_DEPLOY_OPTIONS="${NOW_DEPLOY_OPTIONS} --${PLUGIN_TYPE}"
32+
echo "> adding deploy_name $PLUGIN_DEPLOY_NAME"
33+
NOW_DEPLOY_OPTIONS="${NOW_DEPLOY_OPTIONS} --name $PLUGIN_DEPLOY_NAME"
34+
else
35+
echo "> No deployment name provided. The directory will be used as the name"
1536
fi
1637

17-
if [ -n "$PLUGIN_TOKEN" ]
38+
if [ -n "$PLUGIN_TYPE" ]
1839
then
19-
echo "> Deploying on now.sh…" &&
20-
NOW_DEPLOYMENT_URL=$(now $NOW_DEPLOY_OPTIONS) &&
21-
echo "> Success! Deployment complete to $NOW_DEPLOYMENT_URL!";
40+
echo "> adding type $PLUGIN_TYPE"
41+
NOW_DEPLOY_OPTIONS="${NOW_DEPLOY_OPTIONS} --$PLUGIN_TYPE"
2242
else
23-
echo "> Error! NOW_TOKEN is required"
43+
echo "> No deployment type provided, now.sh will try to detect it..."
2444
fi
2545

46+
if [ -n "$PLUGIN_DIRECTORY" ]
47+
then
48+
echo "> Deploying $PLUGIN_DIRECTORY on now.sh…"
49+
fi
50+
51+
NOW_DEPLOYMENT_URL=$(now $NOW_AUTH $NOW_DEPLOY_OPTIONS $PLUGIN_DIRECTORY) &&
52+
echo "> Success! Deployment complete to $NOW_DEPLOYMENT_URL";
53+
2654
if [ -n "$PLUGIN_ALIAS" ]
2755
then
2856
echo "> Assigning alias…" &&
29-
ALIAS_SUCCESS_MESSAGE=$(now alias $NOW_DEPLOYMENT_URL $PLUGIN_ALIAS $NOW_TOKEN_OPTION) &&
57+
ALIAS_SUCCESS_MESSAGE=$(now alias $NOW_AUTH $NOW_DEPLOYMENT_URL $PLUGIN_ALIAS) &&
3058
echo "$ALIAS_SUCCESS_MESSAGE" &&
3159
NOW_DEPLOYMENT_URL="https://$PLUGIN_ALIAS";
3260
fi
3361

62+
if [ "$PLUGIN_CLEANUP" == "true" ]
63+
then
64+
if [ -n "$PLUGIN_ALIAS" ]
65+
then
66+
echo "> Cleaning up old deployments…" &&
67+
ALIAS_SUCCESS_MESSAGE=$(now rm --safe --yes $NOW_AUTH $PLUGIN_ALIAS) &&
68+
echo "$ALIAS_SUCCESS_MESSAGE"
69+
else
70+
echo "> Warning!! You must set the alias parameter when using the cleanup parameter so that now.sh knows which deployments to remove!"
71+
fi
72+
fi
73+
3474
if [ -n "$PLUGIN_SCALE" ]
3575
then
3676
echo "> Scaling…" &&
37-
SCALE_SUCCESS_MESSAGE=$(now scale $NOW_DEPLOYMENT_URL $PLUGIN_SCALE $NOW_TOKEN_OPTION) &&
77+
SCALE_SUCCESS_MESSAGE=$(now scale $NOW_AUTH $NOW_DEPLOYMENT_URL $PLUGIN_SCALE) &&
3878
echo "$SCALE_SUCCESS_MESSAGE";
3979
fi
4080

4181
if [ -n "$PLUGIN_RULES_DOMAIN" ] && [ -n "$PLUGIN_RULES_FILE" ]
4282
then
4383
echo "> Assigning domain rules…" &&
44-
RULES_SUCCESS_MESSAGE=$(now alias $PLUGIN_RULES_DOMAIN -r $PLUGIN_RULES_FILE $NOW_TOKEN_OPTION) &&
84+
RULES_SUCCESS_MESSAGE=$(now alias $NOW_AUTH $PLUGIN_RULES_DOMAIN -r $PLUGIN_RULES_FILE) &&
4585
echo "$RULES_SUCCESS_MESSAGE" &&
4686
NOW_DEPLOYMENT_URL=$PLUGIN_ALIAS;
4787
fi
4888

49-
echo $'\n'"> Successfully deployed! $NOW_DEPLOYMENT_URL"$'\n'
89+
## Check exit code
90+
rc=$?;
91+
if [[ $rc != 0 ]];
92+
then
93+
echo "> non-zero exit code $rc" &&
94+
exit $rc
95+
else
96+
echo $'\n'"> Successfully deployed! $NOW_DEPLOYMENT_URL"$'\n'
97+
fi

0 commit comments

Comments
 (0)