diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..42b27ca --- /dev/null +++ b/.drone.yml @@ -0,0 +1,8 @@ +pipeline: + docker: + image: plugins/docker + secrets: [ docker_username, docker_password ] + repo: lucap/drone-netlify + auto_tag: true + when: + event: tag diff --git a/DOCS.md b/DOCS.md new file mode 100644 index 0000000..881526d --- /dev/null +++ b/DOCS.md @@ -0,0 +1,104 @@ +--- +date: 2018-02-15T00:00:00+00:00 +title: Netlify +author: lucaperret +tags: [ deploy, netlify ] +repo: lucaperret/drone-netlify +logo: netlify.svg +image: lucap/drone-netlify +--- + +The netlify plugin deploy your build to [netlify.com](https://netlify.com). + +The below pipeline configuration demonstrates simple usage to deploy the current working directory: + +```yaml +pipeline: + netlify: + image: lucap/drone-netlify + token: xxxxx + site_id: xxxxxxx-xxxx-xxx-xxxxxxxx +``` + +Example configuration for assigning [Netlify subdomain](https://www.netlify.com/docs/custom-domains/): + +```diff +pipeline: + netlify: + image: lucap/drone-netlify + token: xxxxx + site_id: xxxxxxx-xxxx-xxx-xxxxxxxx ++ site_name: my-deployment-alias +``` + +Example configuration with [Custom domain](https://www.netlify.com/docs/custom-domains/): + +```diff +pipeline: + netlify: + image: lucap/drone-netlify + token: xxxxx + site_id: xxxxxxx-xxxx-xxx-xxxxxxxx +- site_name: my-deployment-alias ++ domain: my-custom-domain.com +``` + +Example configuration for specifying [environment](https://www.netlify.com/docs/continuous-deployment/#deploy-contexts): + +```diff +pipeline: + netlify: + image: lucap/drone-netlify + token: xxxxx + site_id: xxxxxxx-xxxx-xxx-xxxxxxxx +- domain: my-custom-domain.com ++ environment: production +``` + +Example configuration to deploy a specific folder or Zip (default current working directory): + +```diff +pipeline: + netlify: + image: lucap/drone-netlify + token: xxxxx + site_id: xxxxxxx-xxxx-xxx-xxxxxxxx +- environment: production ++ path: ./dist +``` + +Example configuration using token from secrets: + +```diff +pipeline: + netlify: + image: lucap/drone-netlify +- token: xxxxx + site_id: xxxxxxx-xxxx-xxx-xxxxxxxx ++ secrets: [ netlify_token ] +``` + +# Secret Reference + +netlify_token +: Netlify [token](https://app.netlify.com/applications) + +# Parameter Reference + +token +: `Required` Netlify [token](https://app.netlify.com/applications) + +site_id +: `Required` Set the Site ID (or API ID in your Site settings dashboard) + +site_name +: Set a Netlify subdomain + +domain +: Set your custom domain + +environment +: Specify an environment + +path +: Path to a folder or zip file to deploy diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2217335 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:alpine + +LABEL maintainer="Luca Perret " +LABEL org.label-schema.version=latest +LABEL org.label-schema.vcs-url="https://github.com/lucaperret/drone-netlify" +LABEL org.label-schema.name="drone-netlify" +LABEL org.label-schema.description="Deploying to netlify with Drone CI" +LABEL org.label-schema.vendor="Luca Perret" +LABEL org.label-schema.schema-version="1.0" + +RUN npm install -g netlify-cli + +ADD script.sh /bin/ +RUN chmod +x /bin/script.sh + +ENTRYPOINT /bin/script.sh diff --git a/LICENSE b/LICENSE index 05c6fe1..54f9112 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Luca +Copyright (c) 2018 Luca Perret Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md new file mode 100644 index 0000000..9cba4e9 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# Drone-netlify + +![Netlify logo](netlify.png?raw=true "netlify.com") + +[![Docker Pulls](https://img.shields.io/docker/pulls/lucap/drone-netlify.svg)](https://hub.docker.com/r/lucap/drone-netlify/) +[![Image](https://images.microbadger.com/badges/image/lucap/drone-netlify.svg)](https://microbadger.com/images/lucap/drone-netlify "Get your own image badge on microbadger.com") +[![GitHub release](https://img.shields.io/github/release/lucaperret/drone-netlify.svg)](https://github.com/lucaperret/drone-netlify/releases/latest) + +Deploying to [Netlify](https://netlify.com) with [Drone](https://drone.io) CI. + +Use case examples: + +- Automatically create staging deployments for pull requests +- Automatically deploy and alias upon pushes to master + +## Usage + +For the usage information and a listing of the available options please take a look at [the docs](DOCS.md). + +There are two ways to deploy. + +### From docker + +Deploy the working directory to Netlify. + +```bash +docker run --rm \ + -e PLUGIN_TOKEN=xxxxx \ + -e PLUGIN_SITE_ID=xxxxxxx-xxxx-xxx-xxxxxxxx \ + -e PLUGIN_SITE_NAME=netlify-subdomain + -v $(pwd):$(pwd) \ + -w $(pwd) \ + lucap/drone-netlify +``` + +### From Drone CI + +```yaml +pipeline: + netlify: + image: lucap/drone-netlify + token: xxxxx + site_id: xxxxxxx-xxxx-xxx-xxxxxxxx + site_name: netlify-subdomain +``` diff --git a/netlify.png b/netlify.png new file mode 100644 index 0000000..fea4691 Binary files /dev/null and b/netlify.png differ diff --git a/netlify.svg b/netlify.svg new file mode 100644 index 0000000..6df4255 --- /dev/null +++ b/netlify.svg @@ -0,0 +1,37 @@ + + + + logomark + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/script.sh b/script.sh new file mode 100755 index 0000000..5f889c3 --- /dev/null +++ b/script.sh @@ -0,0 +1,46 @@ +#!/bin/sh +set -e + +NETLIFY_SITE="" +NETLIFY_DEPLOY_OPTIONS="" +NETLIFY_UPDATE_OPTIONS="" + +if [ -n "$PLUGIN_ENVIRONMENT" ] +then + NETLIFY_DEPLOY_OPTIONS="-e ${PLUGIN_ENVIRONMENT}" + NETLIFY_UPDATE_OPTIONS="${NETLIFY_DEPLOY_OPTIONS}" +fi + +if [ -n "$PLUGIN_PATH" ] +then + NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} -p ${PLUGIN_PATH}" +else + NETLIFY_DEPLOY_OPTIONS="${NETLIFY_DEPLOY_OPTIONS} -p ./" +fi + +if [ -n "$PLUGIN_SITE_ID" ] && [ -n "$PLUGIN_TOKEN" ] +then + NETLIFY_SITE="-t $PLUGIN_TOKEN -s $PLUGIN_SITE_ID" + echo "> Deploying on Netlify…" && + netlify $NETLIFY_SITE deploy $NETLIFY_DEPLOY_OPTIONS; +else + echo "> Error! site_id and token are required" +fi + +if [ -n "$PLUGIN_SITE_NAME" ] +then + NETLIFY_UPDATE_OPTIONS="${NETLIFY_UPDATE_OPTIONS} -n ${PLUGIN_SITE_NAME}" +fi + +if [ -n "$PLUGIN_DOMAIN" ] +then + NETLIFY_UPDATE_OPTIONS="${NETLIFY_UPDATE_OPTIONS} -d ${PLUGIN_DOMAIN}" +fi + +if [ -n "$PLUGIN_SITE_NAME" ] || [ -n "$PLUGIN_DOMAIN" ] +then + echo "> Updating your Netlify site…" && + netlify $NETLIFY_SITE update $NETLIFY_UPDATE_OPTIONS; +fi + +echo $'\n'"> Successfully deployed!"$'\n' \ No newline at end of file