keyval-resource

module
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2018 License: Apache-2.0

README

Docker Stars Docker pulls Docker build status Docker Automated build

dockeri.co

Concourse CI Key Value Resource

Implements a resource that passes key values between jobs without using any external resource such as git/s3 etc.

Thanks

This resource was implemented based on the time resource

Source Configuration

resource_types:
  - name: keyval
    type: docker-image
    source:
      repository: swce/keyval-resource
      
resources:
  - name: keyval
    type: keyval
Parameters

None.

Behavior

check: Produce a single dummy key

This is a version-less resource so check behavior is no-op

in: Report the given time.

Fetches the given key values and stores them in the keyval.properties file. The format is of a .properties file, e.g. "<key>=<value>".

Parameters

None.

out: Consumes the given properties file
- put: keyval
  params:
    file: keyvalout/keyval.properties

Reads the given properties file and sets them for the next job.

Parameters
  • file - the properties file to read the key values from

Examples

resource_types:
  - name: keyval
    type: docker-image
    source:
      repository: swce/keyval-resource

resources:
  - name: keyval
    type: keyval

jobs:

  - name: build
    plan:
      - task: build
        file: tools/tasks/build/task.yml
      - put: keyval
        params:
          file: keyvalout/keyval.properties

  - name: test-deploy
    plan:
      - aggregate:
        - get: keyval
          passed:
          - build
      - task: test-deploy
        file: tools/tasks/task.yml

The build job writes all the key values it needs to pass along (e.g. artifact id) in the keyvalout/keyval.properties file. The test-deploy can read the data from the keyval/keyval.properties file and use them as it pleases.

CI suggestions

Auto export the keys

You can add the following bash script to the start of every job to auto export the passed key values, if they exist. The script assumes that the resource folder is keyval.

  • Don't forget to source the script so it's exports will be passed along
#!/bin/bash

props="${ROOT_FOLDER}/keyval/keyval.properties"
if [ -f "$props" ]
then
  echo "Reading passed key values"
  while IFS= read -r var
  do
    if [ ! -z "$var" ]
    then
      echo "Adding: $var"
      export "$var"
    fi
  done < "$props"
fi

Auto pass the keys

You can add the following bash script to the end of every job to auto pass specific environment variables as key values to the next job. The script only passes environment variables that start with PASSED_. The script assumes that the resource out file is keyvalout/keyval.properties:

e.g.

- put: keyval
  params:
    file: keyvalout/keyval.properties
#!/bin/bash

propsDir="${ROOT_FOLDER}/keyvalout"
propsFile="${propsDir}/keyval.properties"
if [ -d "$propsDir" ]
then
  touch "$propsFile"
  echo "Setting key values for next job in ${propsFile}"
  while IFS='=' read -r name value ; do
    if [[ $name == 'PASSED_'* ]]; then
      echo "Adding: ${name}=${value}"
      echo "${name}=${value}" >> "$propsFile"
    fi
  done < <(env)
fi

Development

Prerequisites
  • golang is required - version 1.9.x is tested; earlier versions may also work.
  • docker is required - version 17.06.x is tested; earlier versions may also work.
  • godep is used for dependency management of the golang packages.
Running the tests

The tests have been embedded with the Dockerfile; ensuring that the testing environment is consistent across any docker enabled platform. When the docker image builds, the test are run inside the docker container, on failure they will stop the build.

Run the tests with the following command:

docker build -t keyval-resource .
Contributing

Please make all pull requests to the master branch and ensure tests pass locally.

Directories

Path Synopsis
Godeps
_workspace/src/github.com/google/uuid
Package uuid generates and inspects UUIDs.
Package uuid generates and inspects UUIDs.
_workspace/src/github.com/magiconair/properties
Package properties provides functions for reading and writing ISO-8859-1 and UTF-8 encoded .properties files and has support for recursive property expansion.
Package properties provides functions for reading and writing ISO-8859-1 and UTF-8 encoded .properties files and has support for recursive property expansion.
_workspace/src/github.com/magiconair/properties/assert
Package assert provides helper functions for testing.
Package assert provides helper functions for testing.
_workspace/src/github.com/onsi/ginkgo
Ginkgo is a BDD-style testing framework for Golang The godoc documentation describes Ginkgo's API.
Ginkgo is a BDD-style testing framework for Golang The godoc documentation describes Ginkgo's API.
_workspace/src/github.com/onsi/ginkgo/config
Ginkgo accepts a number of configuration options.
Ginkgo accepts a number of configuration options.
_workspace/src/github.com/onsi/ginkgo/ginkgo
The Ginkgo CLI The Ginkgo CLI is fully documented [here](http://onsi.github.io/ginkgo/#the_ginkgo_cli) You can also learn more by running: ginkgo help Here are some of the more commonly used commands: To install: go install github.com/onsi/ginkgo/ginkgo To run tests: ginkgo To run tests in all subdirectories: ginkgo -r To run tests in particular packages: ginkgo <flags> /path/to/package /path/to/another/package To pass arguments/flags to your tests: ginkgo <flags> <packages> -- <pass-throughs> To run tests in parallel ginkgo -p this will automatically detect the optimal number of nodes to use.
The Ginkgo CLI The Ginkgo CLI is fully documented [here](http://onsi.github.io/ginkgo/#the_ginkgo_cli) You can also learn more by running: ginkgo help Here are some of the more commonly used commands: To install: go install github.com/onsi/ginkgo/ginkgo To run tests: ginkgo To run tests in all subdirectories: ginkgo -r To run tests in particular packages: ginkgo <flags> /path/to/package /path/to/another/package To pass arguments/flags to your tests: ginkgo <flags> <packages> -- <pass-throughs> To run tests in parallel ginkgo -p this will automatically detect the optimal number of nodes to use.
_workspace/src/github.com/onsi/ginkgo/internal/remote
Aggregator is a reporter used by the Ginkgo CLI to aggregate and present parallel test output coherently as tests complete.
Aggregator is a reporter used by the Ginkgo CLI to aggregate and present parallel test output coherently as tests complete.
_workspace/src/github.com/onsi/ginkgo/reporters
Ginkgo's Default Reporter A number of command line flags are available to tweak Ginkgo's default output.
Ginkgo's Default Reporter A number of command line flags are available to tweak Ginkgo's default output.
_workspace/src/github.com/onsi/gomega
Gomega is the Ginkgo BDD-style testing framework's preferred matcher library.
Gomega is the Ginkgo BDD-style testing framework's preferred matcher library.
_workspace/src/github.com/onsi/gomega/format
Gomega's format package pretty-prints objects.
Gomega's format package pretty-prints objects.
_workspace/src/github.com/onsi/gomega/gbytes
Package gbytes provides a buffer that supports incrementally detecting input.
Package gbytes provides a buffer that supports incrementally detecting input.
_workspace/src/github.com/onsi/gomega/gexec
Package gexec provides support for testing external processes.
Package gexec provides support for testing external processes.
_workspace/src/github.com/onsi/gomega/ghttp
Package ghttp supports testing HTTP clients by providing a test server (simply a thin wrapper around httptest's server) that supports registering multiple handlers.
Package ghttp supports testing HTTP clients by providing a test server (simply a thin wrapper around httptest's server) that supports registering multiple handlers.
_workspace/src/github.com/onsi/gomega/ghttp/protobuf
Package protobuf is a generated protocol buffer package.
Package protobuf is a generated protocol buffer package.
_workspace/src/github.com/onsi/gomega/matchers
Gomega matchers This package implements the Gomega matchers and does not typically need to be imported.
Gomega matchers This package implements the Gomega matchers and does not typically need to be imported.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL