diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..02eea72 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM rancher/cli:v2.0.4 + +# install dependencies +RUN apk add --no-cache curl + +# install kubectl +RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.12.0/bin/linux/amd64/kubectl \ + && chmod +x ./kubectl \ + && mv ./kubectl /usr/local/bin/kubectl + +# add rancher-redeploy script +COPY bin/rancher-redeploy /usr/local/bin/ +RUN chmod +x /usr/local/bin/rancher-redeploy + +# reset entrypoint +ENTRYPOINT [] diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..ba8072e --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Sourceboat GmbH & Co. KG + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/bin/rancher-redeploy b/bin/rancher-redeploy new file mode 100644 index 0000000..b267939 --- /dev/null +++ b/bin/rancher-redeploy @@ -0,0 +1,2 @@ +#!/bin/sh +rancher kubectl patch deployment $2 -n $1 -p \ "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"ci_deployment_date\":\"`date +'%s'`\"}}}}}" diff --git a/readme.md b/readme.md index d76c0de..8cde218 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,50 @@ -# Rancher Deploy +# sourceboat/rancher-deploy + +[![Docker Build Status](https://img.shields.io/docker/build/sourceboat/rancher-deploy.svg?style=flat-square)](https://hub.docker.com/r/sourceboat/rancher-deploy/builds/) +[![Release](https://img.shields.io/github/release/sourceboat/rancher-deploy.svg?style=flat-square)](https://github.com/sourceboat/rancher-deploy/releases) +[![Docker Pulls](https://img.shields.io/docker/pulls/sourceboat/rancher-deploy.svg?style=flat-square)](https://hub.docker.com/r/sourceboat/rancher-deploy/) +[![MicroBadger Size](https://img.shields.io/microbadger/image-size/sourceboat/rancher-deploy.svg?style=flat-square)](https://microbadger.com/images/sourceboat/rancher-deploy) +[![MicroBadger Layers](https://img.shields.io/microbadger/layers/sourceboat/rancher-deploy.svg?style=flat-square)](https://microbadger.com/images/sourceboat/rancher-deploy) This docker image enables simple deployments to Rancher. It is a small alpine image with [Rancher CLI](https://rancher.com/docs/rancher/v2.x/en/cli/) `rancher` and [Kubernetes CLI](https://kubernetes.io/docs/tasks/tools/install-kubectl/) `kubectl` installed. + +It also comes with a custom `rancher-redeploy` command (see usage section). + +## Usage + +### Simple Redeploy via GitLab CI + +To use this image via GitLab CI add the following to the `.gitlab-ci.yml`: + +```yml +deploy: + stage: deploy + image: sourceboat/rancher-deploy:stable + variables: + RANCHER_URL: https://rancher.example.com + K8S_NAMESPACE: my-namespace-name + K8S_DEPLOYMENT: my-deployment-name + script: + - rancher login $RANCHER_URL --token $RANCHER_TOKEN + - rancher-redeploy $K8S_NAMESPACE $K8S_DEPLOYMENT +``` + +Don't forget to provide `$RANCHER_TOKEN` via GitLab CI/CD variable. + +This will trigger a redeploy of the given Kubernetes deployment by updating a label +and pull the newest image if configured correctly. + +## Changelog + +Check [releases](https://github.com/sourceboat/rancher-deploy/releases) for all notable changes. + +## Credits + +- [Phil-Bastian Berndt](https://github.com/pehbehbeh) +- [All Contributors](https://github.com/sourceboat/rancher-deploy/graphs/contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information.