Giter Club home page Giter Club logo

pivnet-product-stemcell-resource's Introduction

PivNet Product Stemcell Resource

Go Version Actions Status Code Coverage

Inspired by the PivNet Resource.

This resource is specifically designed to discover the stemcell dependency of a tracked product.

Installing

The recommended method to use this resource is with resource_types in the pipeline config as follows:

---
resource_types:
- name: pivnet-product-stemcell
  type: docker-image
  source:
    repository: shanman190/pivnet-product-stemcell-resource
    tag: latest-final

Using tag: latest-final will automatically pull the latest final release, which can be found on the releases page.

To avoid automatically upgrading, use a fixed tag instead e.g. tag: v0.1.0

Releases are semantically versioned; these correspond to the git tags in this repository.

Source configuration

resources:
- name: p-mysql
  type: pivnet
  source:
    api_token: {{api-token}}
    product_slug: p-mysql
    stemcell_slug: stemcells-ubuntu-xenial
  • api_token: Required string.

    Token from your Pivotal Network profile. Accepts either your Legacy API Token or UAA Refresh Token.

  • product_slug: Required string.

    Name of product on Pivotal Network.

  • stemcell_slug: Required string.

    Name of stemcell on Pivotal Network.

  • release_type: Optional boolean.

    If true, lock to a specific Pivotal Network release type.

  • copy_metadata: Optional boolean.

    If true, copy specified metadata from the latest All Users release within the minor releases. Defaults to false.

    The following metadata is copied:

    • Release Notes URL
    • End of General Support
    • End of Technical Guidance
    • End of Availability
    • EULA
    • License Exception
    • ECCN
    • Controlled
    • Dependency Specifiers
    • Upgrade Path Specifiers
  • endpoint: Optional string.

    Endpoint to use for communicating with Pivotal Network.

    Defaults to https://network.pivotal.io.

  • product_version: Optional string.

    Regular expression to match against product versions, e.g. 1\.2\..*.

    Empty values match all product versions.

  • sort_by: Optional string.

    Order to use for sorting releases. One of the following:

    • none: the order they come back from Pivotal Network.
    • semver: by semantic version, in descending order from the highest-valued version.
    • last_updated: by last updated at time, in descending order from the most recently updated version. Please note that if an earlier release is updated then the Pivnet Resource 'check' step will return it again.

Example pipeline configuration

See example pipeline configurations.

Behavior

check: check for new stemcell versions for the tracked product versions on Pivotal Network

Discovers all stemcell versions of the provided product. Returned versions are optionally filtered and ordered by the source configuration.

in: download the stemcell for the tracked product from Pivotal Network

Downloads the stemcell for the tracked product from Pivotal Network. You will be required to accept a EULA for any stemcell you're downloading for the first time, as well as if the terms and conditions associated with the product change.

The metadata for the stemcell is written to both metadata.json and metadata.yaml in the working directory (typically /tmp/build/get). Use this to programmatically determine metadata of the release.

See metadata for more details on the structure of the metadata file.

Parameters

  • globs: Optional array.

    Array of globs matching files to download.

    If multiple files are matched, they are all downloaded.

    • The globs match on the actual file names, not the display names in Pivotal Network. This is to provide a more consistent experience between uploading and downloading files.

    • If the globs fail to match any files the release download fails with error.

    • If one or more globs fails to match any files, only the matched files will be downloaded.

    • If globs is not provided (or is nil), all files will be downloaded.

    • Setting globs to the empty array (i.e. globs: []) will not attempt to download any files.

    • Files are downloaded to the working directory (e.g. /tmp/build/get) and the file names will be the same as they are on Pivotal Network - e.g. a file with name some-file.txt will be downloaded to /tmp/build/get/some-file.txt.

  • unpack: Optional boolean.

    If true, unpack the downloaded file.

    • This can be used to use a root filesystem that is packaged as an archive file on network.pivotal.io as the image to run a given Concourse task.

More generally, the unpack parameter can be used with get to pass an image to a task definition, as in the below example.

resource:
- name: image
  type: pivnet
  source:
    api_token: {{pivnet_token}}
    product_slug: {{image-slug}}
    product_version: 0\.0\..*

jobs:
- name: sample
  serial: true
  plan:
  - get: tasks
  - get: image
    resource: pcf-automation
    params:
      globs: ["image-*.tar"]
      unpack: true

  - task: say hello
    image: image
    file: tasks/say-hello.yml

out: not implemented

Not implemented. Returns an error

Some common gotchas

Using glob patterns instead of regex patterns

We commonly see product_version patterns that look something like these:

product_version: Go*          # Go Buildpack
#....
product_version: 1\.12\.*       # ERT

These superficially resemble globs, not regexes โ€” but they are regexes. These will generally work, but not because they are a glob. They work because the regex will also match.

For example, the first pattern, Go* will match "Go Buildpack 1.1.1". But it would also match "Goooooooo" or "Go Tell It On A Mountain". The second pattern, 1\.12\.*, will match "1.12.0". But it will also match "1.12........." and "1.12.notanumber"

Instead, try patterns like:

product_version: Go.*\d+\.\d+\.\d+  # Go Buildpack
#....
product_version: 1\.12\.\d+         # ERT

Note that the regex syntax is Go's, which is slightly limited compared to PCRE and other popular syntaxes.

Using check-resource for sorted but non-sequential releases (eg. Buildpacks, Stemcells)

When doing a check, pivnet-resource defaults to using the server-provided order. This works fine for simple cases where the response from the server is already in semver order. For example, imagine this order from a product:

1.12.3
1.12.2
1.12.1
1.12.0
1.11.4
1.11.3
1.11.2
1.11.1
1.11.0

This list is in descending semver order. All the 1.12 patch releases are together, followed by all the 1.11 patch releases and so on.

Some products do not group into major or major.minor groups in their responses. This is usually because a product has multiple concurrent version releases. For example, stemcells typically have multiple major versions available. When a CVE is announced that affects them, multiple releases may occur at once, giving an order like:

9999.21
7777.19
9999.20
7777.18

In this example, the available versions for 9999 and 7777 are sorted within the list, but not sequential.

To fix, use sort_by: semver in your resource definition.

Note that buildpack "versions" are actually a name and a version combined. You'll need to escape spaces in your check-resource command for it to work properly. Eg:

fly -t pivnet check-resource \
  --resource pivnet-resource-bug-152616708/binary-buildpack \
  --from product_version:Binary\ 1.0.11#2017-03-23T13:57:51.214Z

In this example we escaped the space between "Binary" and "1.0.11".

Integration environment

The Pivotal Network team maintains an integration environment at https://pivnet-integration.cfapps.io/.

This environment is useful for teams to develop against, as changes to products in this account are separated from the live account.

An example configuration for the integration environment might look like:

resources:
- name: p-mysql
  type: pivnet-product-stemcell
  source:
    api_token: {{api-token}}
    product_slug: p-mysql
    stemcell_slug: stemcells-ubuntu-xenial
    endpoint: https://pivnet-integration.cfapps.io

Developing

Prerequisites

A valid install of golang is required - version 1.13.x is tested; earlier versions may also work.

Dependencies

We use go modules for dependencies.

Running the tests

Install the golint and ginkgo executables with:

go get -u golang.org/x/lint/golint
go get -u github.com/onsi/ginkgo/ginkgo

Run the tests with the following command:

ginkgo \
    -r \
    -race \
    -randomizeAllSpecs \
    -randomizeSuites \
    -keepGoing \
    -slowSpecThreshold="${SLOW_SPEC_THRESHOLD}"

And check for code formatting agains the Golang style guide with the following command:

golint ./...

Contributing

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

pivnet-product-stemcell-resource's People

Contributors

scuba10steve avatar shanman190 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

scuba10steve

pivnet-product-stemcell-resource's Issues

Old stemcell line releases may be detected as the newest overall

Description:
When a PivNet product release (supposedly) supports multiple stemcell lines there's no guarantee the newest line will be first in the list of release dependencies. This can lead to a situation where an older stemcell line is ahead of a newer stemcell line, resulting in the former's newest release treated as the newest overall stemcell release.

Using https://network.pivotal.io/products/p-clamav-addon/#/releases/814642 as an example, it has stemcell releases in the following order:
315.x
456.x
621.x

For a new pivnet-product-stemcell resource with product p-clamav-addon, the latest 315.x is returned as the newest overall stemcell release.

Potential solution:

  1. Introduce an optional stemcell_version (similar to product_version) to allow selection of the stemcell line.
    • It's likely this wouldn't actually be used, but...
  2. If stemcell_version is not specified, select releases only in the overall newest stemcell line before new version detection, sorting, etc.
    • This would provide reasonable default behavior of picking the (likely) newest release of the newest stemcell line (which would work for pretty much all cases, including the example above where the release's tiles actually require 621.x), while providing a mechanism to specify an older stemcell line in the unlikely case it's actually needed.

An alternative might be moving stemcell version sorting to before checking for new versions, but in this type of situation it probably wouldn't be a good idea unless sort_by: semver were being used.

e: Another alternative would be to not add stemcell_version and always pick the newest available stemcell line, since there are other ways to pick a specific stemcell line.

Panic during check when product release has no release dependencies

run check step: run check step: check: resource script '/opt/resource/check []' failed: exit status 2

stderr:
panic: runtime error: slice bounds out of range [:1] with capacity 0

goroutine 1 [running]:
github.com/shanman190/pivnet-product-stemcell-resource/versions.Since(0x0, 0x0, 0x0, 0xc00001c320, 0x6, 0x18, 0x0, 0x0, 0x0, 0x0)
	/home/runner/work/pivnet-product-stemcell-resource/pivnet-product-stemcell-resource/versions/versions.go:22 +0x12a
github.com/shanman190/pivnet-product-stemcell-resource/check.(*Command).Run(0xc000539cb0, 0xc0000180c0, 0x22, 0xc00001a730, 0xe, 0xc00001a740, 0xb, 0xc00001c2e0, 0x17, 0x0, ...)
	/home/runner/work/pivnet-product-stemcell-resource/pivnet-product-stemcell-resource/check/check_command.go:156 +0x5d9
main.main()
	/home/runner/work/pivnet-product-stemcell-resource/pivnet-product-stemcell-resource/cmd/check/main.go:89 +0x905

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.