From e42f41f1c959327355a166042a23a2098b7be49b Mon Sep 17 00:00:00 2001 From: whitestar Date: Tue, 20 Jun 2017 21:58:38 +0900 Subject: [PATCH] adds the `fly_prune_workers` command. --- cookbooks/concourse-ci/CHANGELOG.md | 4 ++ cookbooks/concourse-ci/README.md | 2 +- cookbooks/concourse-ci/concourse.yml | 36 +++++++++++++++++ cookbooks/concourse-ci/metadata.rb | 2 +- cookbooks/concourse-ci/recipes/fly.rb | 8 ++++ .../default/usr/local/bin/fly_prune_workers | 46 ++++++++++++++++++++++ 6 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 cookbooks/concourse-ci/concourse.yml create mode 100644 cookbooks/concourse-ci/templates/default/usr/local/bin/fly_prune_workers diff --git a/cookbooks/concourse-ci/CHANGELOG.md b/cookbooks/concourse-ci/CHANGELOG.md index 5f1bbeb..89bcd12 100644 --- a/cookbooks/concourse-ci/CHANGELOG.md +++ b/cookbooks/concourse-ci/CHANGELOG.md @@ -1,6 +1,10 @@ concourse-ci CHANGELOG ====================== +0.1.8 +----- +- adds the `fly_prune_workers` command. + 0.1.7 ----- - improves CA certificates import feature. diff --git a/cookbooks/concourse-ci/README.md b/cookbooks/concourse-ci/README.md index 3393916..b4b230a 100644 --- a/cookbooks/concourse-ci/README.md +++ b/cookbooks/concourse-ci/README.md @@ -71,7 +71,7 @@ This recipe does nothing. #### concourse-ci::fly -This recipe installs the `fly` CLI. +This recipe installs the `fly` CLI and the `fly_prune_workers` command. #### concourse-ci::docker-compose diff --git a/cookbooks/concourse-ci/concourse.yml b/cookbooks/concourse-ci/concourse.yml new file mode 100644 index 0000000..3e52268 --- /dev/null +++ b/cookbooks/concourse-ci/concourse.yml @@ -0,0 +1,36 @@ +--- +# $ fly -t target sp -p concourse-ci-cookbook -c concourse.yml +resources: +- name: src-git + type: git + source: + uri: git://git.osdn.net/gitroot/metasearch/grid-chef-repo.git + branch: master + +jobs: +- name: build-cookbook + plan: + - get: src-git + trigger: false + - task: ci-build + config: + platform: linux + + image_resource: + type: docker-image + source: + repository: chef/chefdk + tag: 0.17.17 + + inputs: + - name: src-git + + run: + #dir: ./src-git/cookbooks/concourse-ci + #path: rake + path: /bin/bash + args: + - -c + - | + cd ./src-git/cookbooks/concourse-ci + rake diff --git a/cookbooks/concourse-ci/metadata.rb b/cookbooks/concourse-ci/metadata.rb index e4baabc..a816ad5 100644 --- a/cookbooks/concourse-ci/metadata.rb +++ b/cookbooks/concourse-ci/metadata.rb @@ -5,7 +5,7 @@ maintainer_email '' license 'Apache 2.0' description 'Installs/Configures Concourse CI by Docker Compose' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '0.1.7' +version '0.1.8' source_url 'http://scm.osdn.jp/gitroot/metasearch/grid-chef-repo.git' issues_url 'https://osdn.jp/projects/metasearch/ticket' diff --git a/cookbooks/concourse-ci/recipes/fly.rb b/cookbooks/concourse-ci/recipes/fly.rb index 06645a9..47ec301 100644 --- a/cookbooks/concourse-ci/recipes/fly.rb +++ b/cookbooks/concourse-ci/recipes/fly.rb @@ -31,3 +31,11 @@ remote_file path_to_fly do not_if "#{path_to_fly} -v | grep #{fly_ver}" not_if { ::File.exist?(path_to_fly) } unless node['concourse-ci']['fly']['auto_upgrade'] end + +template "#{File.dirname(path_to_fly)}/fly_prune_workers" do + source 'usr/local/bin/fly_prune_workers' + owner 'root' + group 'root' + mode '0755' + action :create +end diff --git a/cookbooks/concourse-ci/templates/default/usr/local/bin/fly_prune_workers b/cookbooks/concourse-ci/templates/default/usr/local/bin/fly_prune_workers new file mode 100644 index 0000000..6f3c2b9 --- /dev/null +++ b/cookbooks/concourse-ci/templates/default/usr/local/bin/fly_prune_workers @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +PATH=.:/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:`dirname $0` + +target='' + +usage() { + echo 'Usage: prune_workers -t target' + echo + echo "Options:" + echo " -h: this help." + echo " -t: target name." + echo +} + +ARGS="$@" +# Validation +while getopts 't:h' OPT; do + case $OPT in + 't' ) + target=$OPTARG + ;; + 'h' ) + usage + exit 0 + ;; + '?' ) + usage + exit 1 + ;; + esac +done + +shift $((OPTIND - 1)) + +if [ $# != 0 ]; then + usage + exit 1 +fi + +if [ -z $target ]; then + usage + exit 1 +fi + +fly -t $target ws | awk '$6=="stalled" {print $1}' | xargs -t -n 1 --no-run-if-empty fly -t $target prune-worker -w -- 2.11.0