├── .dockerignore ├── .editorconfig ├── .examples ├── notifications │ ├── README.md │ └── docker-compose.yml └── simple │ ├── README.md │ └── docker-compose.yml ├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .travis.yml ├── .travis └── docker-push.sh ├── Dockerfile ├── LICENSE ├── README.md ├── docker └── DESCRIPTION.md ├── main.py └── requirements.txt /.dockerignore: -------------------------------------------------------------------------------- 1 | # Project 2 | /.examples 3 | /.github 4 | /.travis 5 | /docker 6 | /venv 7 | .dockerignore 8 | .gitignore 9 | .travis.yml 10 | Dockerfile 11 | LICENSE 12 | README.md 13 | 14 | # JetBrains 15 | /.idea 16 | *.iml 17 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | charset = utf-8 3 | end_of_line = lf 4 | indent_style = space 5 | trim_trailing_whitespace = true 6 | insert_final_newline = true 7 | indent_size = 4 8 | 9 | [{*.yml, *.yaml}] 10 | indent_size = 2 11 | -------------------------------------------------------------------------------- /.examples/notifications/README.md: -------------------------------------------------------------------------------- 1 | # Notification Example 2 | 3 | A Disrupt example including notification support. The Disrupt service is configured to check for image updates every 5 minutes (300 seconds). 4 | 5 | It includes an example [jwilder/whoami](https://github.com/jwilder/whoami) service which will start an http server on port `8080`. 6 | 7 | ## Configuring 8 | 9 | To configure this example, edit `docker-compose.yml` and set the `NOTIFICATION_URL` environment variable to a valid [Apprise URL](https://github.com/caronc/apprise#popular-notification-services). 10 | 11 | ## Deploying 12 | 13 | To deploy this example, run the following: 14 | 15 | ```bash 16 | docker stack deploy -c docker-compose.yml 17 | ``` -------------------------------------------------------------------------------- /.examples/notifications/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | web: 5 | image: jwilder/whoami:latest 6 | ports: 7 | - "8080:8000" 8 | 9 | disrupt: 10 | image: blamebutton/disrupt:latest 11 | volumes: 12 | - "/var/run/docker.sock:/var/run/docker.sock" 13 | environment: 14 | UPDATE_DELAY: 300 15 | # format=markdown is required for cards in Discord 16 | NOTIFICATION_URL: discord://webhook_id/webhook_token?format=markdown 17 | deploy: 18 | placement: 19 | constraints: 20 | - node.role == manager 21 | -------------------------------------------------------------------------------- /.examples/simple/README.md: -------------------------------------------------------------------------------- 1 | # Simple Example 2 | 3 | The most basic Disrupt example. The Disrupt service is configured to check for image updates every 5 minutes (300 seconds). 4 | 5 | It includes an example [jwilder/whoami](https://github.com/jwilder/whoami) service which will start an http server on port `8080`. 6 | 7 | ## Deploying 8 | 9 | To deploy this example, run the following: 10 | 11 | ```bash 12 | docker stack deploy -c docker-compose.yml 13 | ``` -------------------------------------------------------------------------------- /.examples/simple/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | web: 5 | image: jwilder/whoami:latest 6 | ports: 7 | - "8080:8000" 8 | 9 | disrupt: 10 | image: blamebutton/disrupt:latest 11 | volumes: 12 | - "/var/run/docker.sock:/var/run/docker.sock" 13 | environment: 14 | UPDATE_DELAY: 300 15 | deploy: 16 | placement: 17 | constraints: 18 | - node.role == manager 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots / Logs** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Additional context** 27 | Add any other context about the problem here. 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Example: I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /venv 3 | *.iml -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: bionic 2 | language: python 3 | cache: pip 4 | 5 | python: 6 | - '3.8' # this should be in sync with the Dockerfile base image 7 | 8 | services: 9 | - docker 10 | 11 | script: 12 | - if [[ -z "$IMAGE" ]]; then exit 1; fi 13 | - docker build -t $IMAGE . 14 | 15 | deploy: 16 | - provider: script 17 | script: .travis/docker-push.sh 18 | on: 19 | branch: 'master' 20 | - provider: script 21 | script: .travis/docker-push.sh 22 | on: 23 | tags: true 24 | -------------------------------------------------------------------------------- /.travis/docker-push.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | echo "$DOCKER_PASS" | docker login -u "${DOCKER_USER}" --password-stdin 3 | 4 | if [ "${TRAVIS_BRANCH}" = "master" ]; then 5 | TAG="latest" 6 | docker tag "${IMAGE}" "${IMAGE}:${TAG}" 7 | docker push "${IMAGE}:${TAG}" 8 | fi 9 | 10 | if [ -n "${TRAVIS_TAG}" ]; then 11 | TAG="${TRAVIS_TAG}" 12 | docker tag "${IMAGE}" "${IMAGE}:${TAG}" 13 | docker push "${IMAGE}:${TAG}" 14 | fi 15 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.8-alpine 2 | 3 | ENV DOCKER_HOST='unix:///var/run/docker.sock' 4 | 5 | WORKDIR /app 6 | COPY main.py requirements.txt /app/ 7 | RUN pip install -r requirements.txt 8 | 9 | ENTRYPOINT ["python", "main.py"] 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Disrupt (Docker Swarm Service Updater) 2 | 3 | [![GitHub release](https://img.shields.io/github/v/release/BlameButton/disrupt?include_prereleases)](https://github.com/BlameButton/disrupt/releases) 4 | [![GitHub](https://img.shields.io/github/license/BlameButton/disrupt)](https://github.com/BlameButton/disrupt/blob/master/LICENSE) 5 | [![GitHub contributors](https://img.shields.io/github/contributors/blamebutton/disrupt?style=flat-square)](https://github.com/BlameButton/disrupt/graphs/contributors) 6 | 7 | [![Build Status](https://img.shields.io/travis/com/BlameButton/disrupt/master?style=flat-square)](https://travis-ci.com/BlameButton/disrupt) 8 | [![Docker Pulls](https://img.shields.io/docker/pulls/blamebutton/disrupt?style=flat-square)](https://hub.docker.com/r/blamebutton/disrupt) 9 | [![Discord Widget](https://img.shields.io/discord/556492964050763817?style=flat-square)](https://discord.gg/tDf2yBg) 10 | 11 | ## Usage 12 | 13 | ```yaml 14 | version: '3' 15 | 16 | services: 17 | whoami: 18 | image: jwilder/whoami 19 | ports: 20 | - 8080:8000 21 | 22 | disrupt: 23 | image: blamebutton/disrupt 24 | volumes: 25 | # Mount the Docker socket, this is required for interacting with the Docker API. 26 | - /var/run/docker.sock:/var/run/docker.sock 27 | deploy: 28 | placement: 29 | constraints: 30 | # Disrupt needs permission to update services, only managers are allowed to do that. 31 | - node.role == manager 32 | ``` 33 | 34 | For more examples, check out the [examples folder](/.examples) 35 | 36 | **Note**: Docker Swarm does not support running locally built images, so neither does Disrupt. 37 | 38 | ## Configuration 39 | 40 | Configuration of Disrupt is done through environment variables. This is done to make the deployment of Disrupt 41 | environment-agnostic. 42 | 43 | Below is a list of environment variables available to be configured. 44 | 45 | | Name | Type | Options | 46 | | - | - | - | 47 | | UPDATE_DELAY | Integer | default = 300 | 48 | | NOTIFICATION_URL | String | Any [Apprise](https://github.com/caronc/apprise#popular-notification-services) compatible URL | 49 | 50 | ## Notifications 51 | 52 | Disrupt uses the [Apprise](https://github.com/caronc/apprise) notification library for Python. 53 | Check out their documentation for more advanced usages. 54 | 55 | Here is a small list of notification providers that Apprise supports: 56 | 57 | - Slack 58 | - Discord 59 | - Telegram 60 | - PushBullet 61 | - Dbus 62 | - Mail 63 | - Custom notifications to a given URL in JSON or XML format 64 | 65 | ## Contributing 66 | 67 | Feel free to make a feature request or if you have Python experience; pull requests are welcome 68 | too! 69 | 70 | ## Troubleshooting 71 | 72 | ### Could not connect to Docker Engine 73 | 74 | Did you mount the Docker socket to the container? Check out the [example](#usage) if you want 75 | to know how. 76 | 77 | In the special case that you are accessing Docker over TCP, you should place Disrupt in the 78 | same network as your TCP socket. Using a Docker socket proxy (like 79 | [docker-socket-proxy](https://hub.docker.com/r/tecnativa/docker-socket-proxy/), or 80 | [sockguard](https://github.com/buildkite/sockguard)) is recommended for enhanced security 81 | in this case. You could then configure the proxy to only allow `GET` requests for service info, 82 | for example. That way, if the Disrupt container gets compromised it can't do any harm to the 83 | cluster in the form of modifications/destructive instructions. 84 | 85 | ## Support 86 | 87 | If you're having trouble getting Disrupt to work, we have a 88 | [Discord](https://discord.gg/tDf2yBg) for support and questions. 89 | -------------------------------------------------------------------------------- /docker/DESCRIPTION.md: -------------------------------------------------------------------------------- 1 | # Supported tags and respective `Dockerfile` links 2 | 3 | - [`latest` (/Dockerfile)](https://github.com/BlameButton/disrupt/blob/master/Dockerfile) 4 | 5 | # Quick reference 6 | 7 | - **Where to get help**:\ 8 | [Discord](https://discord.gg/U7RGvJY), [Mail](mailto:bramceulemans@me.com) 9 | 10 | - **Where to file issues**:\ 11 | [GitHub](https://github.com/BlameButton/disrupt/issues) 12 | 13 | - **Maintained by**:\ 14 | [BlameButton](https://github.com/BlameButton) 15 | 16 | - **Source of this description**:\ 17 | [`/docker/DESCRIPTION.md` in GitHub](https://github.com/BlameButton/disrupt/blob/master/docker/DESCRIPTION.md) 18 | 19 | # What is Disrupt? 20 | 21 | Disrupt is a Python script that will check for updates for the images of your Docker Swarm services. 22 | Disrupt can either run in a container or on the host itself. 23 | 24 | ## Configuration 25 | 26 | Configuration of Disrupt is done through environment variables. This is done to make the deployment of Disrupt 27 | environment-agnostic. 28 | 29 | Below is a list of environment variables available to be configured. 30 | 31 | | Name | Type | Options | 32 | | - | - | - | 33 | | UPDATE_DELAY | Integer | default = 300 | 34 | | NOTIFICATION_URL | String | Any [Apprise](https://github.com/caronc/apprise#popular-notification-services) compatible URL | 35 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import logging 3 | import re 4 | import time 5 | from os import getenv 6 | from sys import stdout 7 | from typing import Optional 8 | 9 | import docker 10 | from apprise import Apprise, NotifyType 11 | from docker import DockerClient 12 | from docker.models.images import Image 13 | from docker.models.services import Service 14 | 15 | 16 | class DissectException(Exception): 17 | pass 18 | 19 | 20 | logger = logging.getLogger('Disrupt') 21 | handler = logging.StreamHandler(stream=stdout) 22 | formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s - %(message)s') 23 | handler.setFormatter(formatter) 24 | logger.addHandler(handler) 25 | logger.setLevel(logging.DEBUG) 26 | 27 | 28 | def main(): 29 | """ 30 | Loops over all the Swarm services, checking if they need updates. 31 | 32 | :raises Exception when Docker Engine is not in Swarm Mode 33 | """ 34 | update_delay = getenv('UPDATE_DELAY', '300') 35 | notification_url = getenv('NOTIFICATION_URL', '') 36 | 37 | try: 38 | client = docker.from_env() 39 | except ConnectionError: 40 | logger.error('Could not connect to Docker Engine. Check https://git.io/JJujV for possible solutions') 41 | return 42 | 43 | logger.info('Started checking for updates') 44 | apprise = Apprise() 45 | if len(notification_url) > 0: 46 | # Add notification provider from URL if provided 47 | apprise.add(notification_url) 48 | 49 | if not is_swarm_manager(client): 50 | raise Exception('Docker Engine is not in Swarm Mode') 51 | while True: 52 | update_services(client, apprise) 53 | time.sleep(float(update_delay)) 54 | 55 | 56 | def is_swarm_manager(client: DockerClient) -> bool: 57 | """ 58 | Check if the given client is connected to a Docker Engine 59 | running in Swarm Mode and has the manager role. 60 | 61 | :param client: DockerClient 62 | :rtype: bool 63 | :return: true if Docker Engine is in Swarm mode, else false 64 | """ 65 | info = client.info() 66 | swarm = info['Swarm'] 67 | return swarm['LocalNodeState'] == 'active' and swarm['ControlAvailable'] 68 | 69 | 70 | def update_services(client: DockerClient, apprise: Apprise): 71 | """ 72 | Update all the services found on the Docker Swarm. 73 | 74 | :param client: Docker Client that is connected to a Docker Swarm Manager 75 | :param apprise: Apprise notification service 76 | """ 77 | services = client.services.list() 78 | logger.info(f'Checking for updates on {len(services)} service(s).') 79 | for service in services: 80 | name = service.name 81 | outdated, tag, digest = is_service_outdated(client, service) 82 | if outdated: 83 | update_message = f'Found update for `{tag}`, updating.' 84 | mode = service.attrs['Spec']['Mode'] 85 | replicated = 'Replicated' in mode 86 | if replicated: 87 | replicas = mode['Replicated']['Replicas'] 88 | plural = 's' if replicas > 1 else '' 89 | update_message = f"Found update for `{tag}`, updating {replicas} replica{plural}." 90 | 91 | apprise.notify(title=f'Service: `{name}`', body=update_message, notify_type=NotifyType.INFO) 92 | 93 | logger.info(f'Found update for service \'{name}\', updating using image {tag}') 94 | start = time.time() 95 | full_image = f"{tag}@{digest}" 96 | service.update(image=full_image, force_update=True) # Update the service 97 | end = time.time() 98 | elapsed = str((end - start))[:4] # Calculate the time it took to update the service 99 | logger.info(f'Update for service \'{name}\' successful, took {elapsed} seconds ({full_image})') 100 | 101 | success_message = f'Update successful. Took {elapsed} seconds.' 102 | apprise.notify(title=f'Service: `{name}`', body=success_message, notify_type=NotifyType.SUCCESS) 103 | else: 104 | logger.debug(f'No update found for service \'{name}\'') 105 | 106 | 107 | def is_service_outdated(client: DockerClient, service: Service) -> tuple: 108 | """ 109 | Check if the given service it outdated, based on the repository digest. 110 | 111 | :param client: the Docker Engine client 112 | :param service: the service to check for updates 113 | :return: tuple containing the following information ( 114 | if the service is outdated, 115 | image tag for the given service, 116 | digest of the remote image if available 117 | ) 118 | """ 119 | service_image = service.attrs['Spec']['TaskTemplate']['ContainerSpec']['Image'] 120 | tag, digest = split_image(service_image) 121 | remote_image = client.images.pull(tag) 122 | remote_digest = get_image_digest(remote_image) 123 | if not digest: 124 | return False, tag, digest 125 | if digest != remote_digest: 126 | return True, tag, remote_digest 127 | return False, tag, digest 128 | 129 | 130 | def split_image(tag: str) -> tuple: 131 | """ 132 | Generic split method for splitting an image tag from it's digest. I.e.:: 133 | 134 | python:latest@sha256:3f8bb7c750e86d031dd14c65d331806105ddc0c6f037ba29510f9b9fbbb35960 135 | 136 | Would return:: 137 | 138 | ('python:latest', 'sha256:3f8bb7c750e86d031dd14c65d331806105ddc0c6f037ba29510f9b9fbbb35960') 139 | 140 | :param tag: the image tag to split up 141 | :return: the split up image tag 142 | """ 143 | search = re.search('^([a-zA-Z0-9/_.:-]{0,128})(?:@(sha256:[0-9a-f]{64}))?$', tag) 144 | tag = search.group(1) 145 | digest = search.group(2) 146 | return tag, digest 147 | 148 | 149 | def get_image_digest(image: Image) -> Optional[str]: 150 | """ 151 | Get the repository digest out of an image object. 152 | 153 | :param image: the image object to get the digest out of 154 | :return: the repository digest for the given image or None if it's not present 155 | """ 156 | if not isinstance(image, Image): 157 | return None 158 | digests = image.attrs.get('RepoDigests') 159 | if digests: 160 | tag, digest = split_image(digests[0]) 161 | return digest 162 | return None 163 | 164 | 165 | if __name__ == '__main__': 166 | main() 167 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | docker 2 | apprise --------------------------------------------------------------------------------