Skip to content

Commit

Permalink
Merge pull request #3 from josegonzalez/master
Browse files Browse the repository at this point in the history
Upgrade to support 0.4.x
  • Loading branch information
kristofsajdak committed Sep 29, 2015
2 parents 03d65cc + cd120c8 commit e14b4ef
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 69 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
insert_final_newline = true
indent_style = space
indent_size = 2

[Makefile]
insert_final_newline = true
indent_style = tab
indent_size = 4

[*.mk]
insert_final_newline = true
indent_style = tab
indent_size = 4
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sudo: required
language: bash
env:
- DOKKU_VERSION=master
before_install: make setup
script: make test
7 changes: 7 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (C) 2015 AGCO

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.
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
shellcheck:
ifeq ($(shell shellcheck > /dev/null 2>&1 ; echo $$?),127)
ifeq ($(shell uname),Darwin)
brew install shellcheck
else
sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse'
sudo apt-get update -qq && sudo apt-get install -qq -y shellcheck
endif
endif

bats:
ifeq ($(shell bats > /dev/null 2>&1 ; echo $$?),127)
ifeq ($(shell uname),Darwin)
brew install shellcheck
else
sudo add-apt-repository ppa:duggan/bats --yes
sudo apt-get update -qq && sudo apt-get install -qq -y bats
endif
endif

ci-dependencies: shellcheck bats

lint:
# these are disabled due to their expansive existence in the codebase. we should clean it up though
# SC2046: Quote this to prevent word splitting. - https://github.com/koalaman/shellcheck/wiki/SC2046
# SC2068: Double quote array expansions, otherwise they're like $* and break on spaces. - https://github.com/koalaman/shellcheck/wiki/SC2068
# SC2086: Double quote to prevent globbing and word splitting - https://github.com/koalaman/shellcheck/wiki/SC2086
@echo linting...
@$(QUIET) find ./ -maxdepth 1 -not -path '*/\.*' | xargs file | egrep "shell|bash" | awk '{ print $$1 }' | sed 's/://g' | xargs shellcheck -e SC2046,SC2068,SC2086

setup:
$(MAKE) ci-dependencies

test: setup lint
60 changes: 31 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
Docker Registry plugin for Dokku
--------------------------------
# dokku-registry [![Build Status](https://img.shields.io/travis/agco/dokku-registry.svg?branch=master "Build Status")](https://travis-ci.org/agco/dokku-registry)

The Docker registry plugin for [Dokku](https://github.com/progrium/dokku) adds support for managing application releases as part of a continuous delivery workflow.
The Docker registry plugin for [Dokku](https://github.com/progrium/dokku) adds support for managing application releases as part of a continuous delivery workflow.

On Heroku similar functionality is offered by the [heroku-labs pipeline feature](https://devcenter.heroku.com/articles/labs-pipelines), which allows you to promote builds across multiple environments (staging -> production)

Installation
------------
```
## requirements

- dokku 0.4.0+
- docker 1.8.x

## installation

```shell
# on 0.3.x
cd /var/lib/dokku/plugins
git clone https://github.com/agco-adm/dokku-registry
git clone https://github.com/agco/dokku-registry.git registry
dokku plugins-install

# on 0.4.x
dokku plugin:install https://github.com/agco/dokku-registry.git registry
```

Commands
--------
## Commands

```
$ dokku help
registry:login <docker login args> Login to a docker registry
registry:push <git_url> <docker_registry_image> Clone a git url, exec buildstep and push the resulting Docker image to the logged on registry
registry:pull <app> <docker_registry_image> Pull a Docker image (produced with buildstep) from the logged on registry and deploy
```

Workflow
--------
## Workflow


## Build machine
### Build machine

```
dokku registry:login —username=<username> —password=<password> —email=<email> <server>
```
This logs you in to the dockerhub registry
Other registries can be specified as well with using the optional server arg
Check the [docker login](https://docs.docker.com/reference/commandline/cli/#login) docs for more details
Check the [docker login](https://docs.docker.com/reference/commandline/cli/#login) docs for more details

```
dokku registry:push <git_url> <image_tag>
```
This clones the code from a given git_url and builds it with buildstep
The resulting Docker is tagged as specified by the image_tag arg and pushed to the current logged-on Docker registry
This clones the code from a given git_url and builds it with buildstep
The resulting Docker is tagged as specified by the image_tag arg and pushed to the current logged-on Docker registry

## Deploy target(s)
### Deploy target(s)

```
dokku registry:login —username=<username> —password=<password> —email=<email> <server>
Expand All @@ -50,34 +57,29 @@ dokku registry:login —username=<username> —password=<password> —email=<ema
```
dokku registry:pull <appname> <image_tag>
```
This pulls the image tag from the current logged-on registry and deploys it to Dokku
The application will be auto-created in case it doesn't exist yet
This pulls the image tag from the current logged-on registry and deploys it to Dokku. The application will be auto-created in case it doesn't exist yet.

## Quick example
### Quick example

Note : This is just to demonstrate syntax, replace credentials and registry image tag with your own values
Note : This is just to demonstrate syntax, replace credentials and registry image tag with your own values

```
dokku registry:login --username=myusername --email=myemail@mailinator.com --password=mypwd
dokku registry:push https://github.com/heroku/node-js-getting-started.git myusername/myapp:1.2.3
dokku registry:pull myapp myusername/myapp:1.2.3
dokku registry:push https://github.com/heroku/node-js-getting-started.git myusername/myapp:1.2.3
dokku registry:pull myapp myusername/myapp:1.2.3
```

## Set config variables prior to application start

There is an outstanding PR which can accomodate this : https://github.com/progrium/dokku/pull/599/files
### Set config variables prior to application start

The workflow then looks something like the following

```
dokku registry:login --username=myusername --email=myemail@mailinator.com --password=mypwd
dokku create myapp
dokku config:set myapp FOO=BAR
dokku registry:pull myapp myusername/myapp:1.2.3
dokku registry:pull myapp myusername/myapp:1.2.3
```

Awaiting the PR to get merged, here is a Dokku fork which has created a branch merging a couple of PRs with the 599 (create command) included https://github.com/neam/dokku/tree/awaiting-prs

An example on how to bootstrap this can be found here : https://github.com/agco-adm/dokku-provision-ALM-support


86 changes: 46 additions & 40 deletions commands
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
#!/bin/bash
#set -e;
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x

case "$1" in

registry:login)
shift
echo "$@"
docker login "$@"
;;
shift
echo "$@"
docker login "$@"
;;

registry:push)
mkdir -p /home/dokku/checkout
cd /home/dokku/checkout
UUID=$(uuidgen)
git clone "$2" "$UUID"
cd "$UUID"
dokku apps:create "$UUID"
DOCKERFILE=$(ls -l | grep Dockerfile | wc -l )
if [ $((DOCKERFILE)) -eq 1 ]; then
IMAGE_TYPE="dockerfile"
else
IMAGE_TYPE="herokuish"
fi
tar c . | dokku build "$UUID" "$IMAGE_TYPE"
docker tag "dokku/$UUID" "$3"
docker push "$3"
dokku delete "$UUID"
rm -rf /home/dokku/checkout/"$UUID"
;;
mkdir -p /home/dokku/checkout
cd /home/dokku/checkout
UUID=$(uuidgen)
git clone "$2" "$UUID"
cd "$UUID"
dokku apps:create "$UUID"
if [[ -f "$UUID/Dockerfile" ]]; then
IMAGE_TYPE="dockerfile"
else
IMAGE_TYPE="herokuish"
fi
tar c . | dokku build "$UUID" "$IMAGE_TYPE"
docker tag "dokku/$UUID" "$3"
docker push "$3"
dokku delete "$UUID"
rm -rf /home/dokku/checkout/"$UUID"
;;

registry:pull)
APP=$2
DOCKER_REGISTRY_IMAGE=$3
mkdir -p "$DOKKU_ROOT/$APP"
docker pull $DOCKER_REGISTRY_IMAGE
docker tag $DOCKER_REGISTRY_IMAGE "dokku/$APP"
dokku release $APP
dokku deploy $APP
;;

help)
APP=$2; DOCKER_REGISTRY_IMAGE=$3
mkdir -p "$DOKKU_ROOT/$APP"
docker pull "$DOCKER_REGISTRY_IMAGE"
docker tag "$DOCKER_REGISTRY_IMAGE" "dokku/$APP"
dokku release "$APP"
dokku deploy "$APP"
;;

cat && cat<<EOF
registry:login <docker login args> Login to a docker registry
registry:push <git_url> <docker_registry_image> Clone a git url, exec buildstep and push the resulting Docker image to the logged on registry
registry:pull <app> <docker_registry_image> Pull a Docker image (produced with buildstep) from the logged on registry and deploy
help | registry:help)
HELP=$(cat<<EOF
registry:login <docker login args>, Login to a docker registry
registry:push <git_url> <docker_registry_image>, Clone a git url, exec buildstep and push the resulting Docker image to the logged on registry
registry:pull <app> <docker_registry_image>, Pull a Docker image (produced with buildstep) from the logged on registry and deploy
EOF
)
if [[ -n $DOKKU_API_VERSION ]]; then
echo "$HELP"
else
cat && echo "$HELP"
fi
;;

*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac
esac
4 changes: 4 additions & 0 deletions plugin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[plugin]
description = "manage dokku application releases similar to heroku's pipeline"
version = "1.0.0"
[plugin.config]

0 comments on commit e14b4ef

Please sign in to comment.