|
| 1 | +# Drone — Cloudflare Caching |
| 2 | +> Drone plugin to purge cache via Cloudflare's API |
| 3 | +
|
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +## About |
| 9 | + |
| 10 | +> **WARNING**: Logic works if authenticated with email and global API token, not currently working with scoped API tokens. This is an issue with Cloudflare and should hopefully be resolved soon. |
| 11 | +
|
| 12 | +Our Drone plugin enables the ability for your pipeline to interface with Cloudflare's API to purge cache. This plugin is written in Go and it uses the [cloudflare-go](https://github.com/cloudflare/cloudflare-go) package to communicate with Cloudflare's API. For information on Cloudflare's API please refer to their [documentation](https://api.cloudflare.com/#zone-purge-all-files) page. |
| 13 | + |
| 14 | +## Cloudflare Token |
| 15 | + |
| 16 | +The API token that is used to authenticate with Cloudflare's API can be created in Cloudflare's dashboard. It is recommended to create an API token that includes only the zone resource you want to manipulate and give edit permissions only to the Cache Purge resource. |
| 17 | + |
| 18 | +## Build |
| 19 | + |
| 20 | +Develop locally by running the plugin with the following commands. Also please note that you should specify environmental variables for the plugin either via the inline method (`FOO=bar go run src/main`) or via the `export FOO=bar` method before the `go run` command. |
| 21 | + |
| 22 | +```shell |
| 23 | +$ dep ensure |
| 24 | +$ go run src/main.go |
| 25 | +``` |
| 26 | + |
| 27 | +## Docker |
| 28 | + |
| 29 | +Drone plugins work off of docker images. The following commands will go over building, pushing, and running the docker image for this plugin. |
| 30 | + |
| 31 | +###### Build Docker Image: |
| 32 | + |
| 33 | +```shell |
| 34 | +$ docker build -t jetrails/drone-cloudflare-caching . |
| 35 | +``` |
| 36 | + |
| 37 | +###### Run Docker Container: |
| 38 | + |
| 39 | +You can then replicate the command that Drone will use to launch the plugin by running: |
| 40 | + |
| 41 | +```shell |
| 42 | +$ docker run --rm \ |
| 43 | + -e PLUGIN_API_TOKEN="u4C7ev06GMS8_vWBTpjqtVReT3I7FwGpW7MG44ZD" \ |
| 44 | + -e PLUGIN_ZONE_IDENTIFIER="eJzrjE44s6Ki67x1tSDJzI8LdXxM3nj7" \ |
| 45 | + -e PLUGIN_ACTION="purge_everything" \ |
| 46 | + -v $(pwd):/drone/src \ |
| 47 | + -w /drone/src \ |
| 48 | + jetrails/drone-cloudflare-caching |
| 49 | +``` |
| 50 | + |
| 51 | +###### Push Docker Image: |
| 52 | + |
| 53 | +Finally, push this image to our Docker Hub [repository](https://hub.docker.com/r/jetrails/drone-cloudflare-caching) (assuming you have permission): |
| 54 | + |
| 55 | +```shell |
| 56 | +$ docker push jetrails/drone-cloudflare-caching |
| 57 | +``` |
| 58 | + |
| 59 | +## Usage |
| 60 | + |
| 61 | +This plugin supports purging all cache, purging hosts, purging files, and purging tags. Please refer to the table below with all possible settings that can be passed to the plugin: |
| 62 | + |
| 63 | +| Name | Required | Default | Case-Sensitive | Type | |
| 64 | +|:---------------:|:--------------------------:|:-------:|:--------------:|:---------------------------------------------------------:| |
| 65 | +| api_token | Yes | - | Yes | STRING | |
| 66 | +| zone_identifier | Yes | - | Yes | STRING | |
| 67 | +| action | Yes | - | No | ENUM[purge_everything,purge_hosts,purge_files,purge_tags] | |
| 68 | +| list | action != purge_everything | - | Yes | ARRAY\<STRING\> | |
| 69 | + |
| 70 | +## Examples |
| 71 | + |
| 72 | +```yaml |
| 73 | +kind: pipeline |
| 74 | +name: default |
| 75 | + |
| 76 | +steps: |
| 77 | +- name: cloudflare |
| 78 | + image: jetrails/drone-cloudflare-caching |
| 79 | + settings: |
| 80 | + api_token: |
| 81 | + from_secret: cloudflare_token |
| 82 | + zone_identifier: |
| 83 | + from_secret: cloudflare_zone_identifier |
| 84 | + action: purge_everything |
| 85 | +``` |
| 86 | +
|
| 87 | +```yaml |
| 88 | +kind: pipeline |
| 89 | +name: default |
| 90 | + |
| 91 | +steps: |
| 92 | +- name: cloudflare |
| 93 | + image: jetrails/drone-cloudflare-caching |
| 94 | + settings: |
| 95 | + api_token: |
| 96 | + from_secret: cloudflare_token |
| 97 | + zone_identifier: |
| 98 | + from_secret: cloudflare_zone_identifier |
| 99 | + action: purge_hosts |
| 100 | + list: |
| 101 | + - example.com |
| 102 | + - foo.example.com |
| 103 | + - bar.example.com |
| 104 | +``` |
| 105 | +
|
| 106 | +```yaml |
| 107 | +kind: pipeline |
| 108 | +name: default |
| 109 | + |
| 110 | +steps: |
| 111 | +- name: cloudflare |
| 112 | + image: jetrails/drone-cloudflare-caching |
| 113 | + settings: |
| 114 | + api_token: |
| 115 | + from_secret: cloudflare_token |
| 116 | + zone_identifier: |
| 117 | + from_secret: cloudflare_zone_identifier |
| 118 | + action: purge_files |
| 119 | + list: |
| 120 | + - https://example.com/script.js |
| 121 | + - https://example.com/logo.svg |
| 122 | +``` |
| 123 | +
|
| 124 | +```yaml |
| 125 | +kind: pipeline |
| 126 | +name: default |
| 127 | + |
| 128 | +steps: |
| 129 | +- name: cloudflare |
| 130 | + image: jetrails/drone-cloudflare-caching |
| 131 | + settings: |
| 132 | + api_token: |
| 133 | + from_secret: cloudflare_token |
| 134 | + zone_identifier: |
| 135 | + from_secret: cloudflare_zone_identifier |
| 136 | + action: purge_tags |
| 137 | + list: |
| 138 | + - foo |
| 139 | + - bar |
| 140 | +``` |
| 141 | +
|
| 142 | +## Feature Requests / Issues |
| 143 | +
|
| 144 | +Feel free to open an issue for any feature requests and issues that you may come across. For furthur inquery, please contact [development@jetrails.com](mailto://development@jetrails.com). |
0 commit comments