├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dockerfile ├── Gemfile ├── LICENSE ├── README.md ├── check └── in /.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | 3 | ### Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ### Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ### Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, pull requests, and other 42 | contributions that are not aligned to this Code of Conduct, or to ban 43 | temporarily or permanently any contributor for other behaviors that they deem 44 | inappropriate, threatening, offensive, or harmful. 45 | 46 | ### Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ### Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at conduct@starkandwayne.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ### Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute to the hashicorp-release-resource 2 | 3 | ## **Did you find a bug?** 4 | 5 | * **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/starkandwayne/hashicorp-release-resource/issues). 6 | 7 | * If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/starkandwayne/hashicorp-release-resource/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring. 8 | 9 | ## **Did you write a patch that fixes a bug?** 10 | 11 | * Open a new GitHub pull request with the patch. 12 | 13 | * Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable. 14 | 15 | * Write a test for your feature. Run all the tests! This will give you and us a higher confidence that nothing broke. 16 | 17 | ## **Do you intend to add a new feature or change an existing one?** 18 | 19 | * Please open a [open a new issue](https://github.com/starkandwayne/hashicorp-release-resource/issues/new) describing the feature you'd like to add. 20 | 21 | Thanks! 22 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | 3 | RUN apk add --no-cache curl bash jq coreutils 4 | 5 | COPY in check /opt/resource/ 6 | RUN chmod +x /opt/resource/* 7 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'octokit' 4 | gem 'httpclient' 5 | gem 'faraday-http-cache' 6 | gem 'activesupport' 7 | 8 | group :development do 9 | gem 'pry' 10 | gem 'rubocop', require: false 11 | gem 'rubocop-rspec', require: false 12 | end 13 | 14 | group :test do 15 | gem 'rspec' 16 | gem 'puffing-billy' 17 | gem 'webmock' 18 | end 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Dr Nic Williams 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hashicorp Release Resource 2 | 3 | Hashicorp software releases are made available via https://releases.hashicorp.com. This Concourse resource allows you to watch for new releases and fetch them. 4 | 5 | ## Deploying to Concourse 6 | 7 | You can use the docker image by defining the [resource type](http://concourse.ci/configuring-resource-types.html) in your pipeline YAML. 8 | 9 | For example: 10 | 11 | ```yaml 12 | resource_types: 13 | - name: hashicorp-release 14 | type: docker-image 15 | source: 16 | repository: starkandwayne/hashicorp-release-resource 17 | 18 | resources: 19 | - name: vault 20 | type: hashicorp-release 21 | source: 22 | project: vault 23 | ``` 24 | 25 | To get the latest `vault` build for `linux_amd64`: 26 | 27 | ```yaml 28 | - get: vault 29 | params: 30 | regexp: linux_amd64 31 | ``` 32 | 33 | ## Source Configuration 34 | 35 | * `project`: *Required.* The Hashicorp project name. 36 | Example: `vault` 37 | 38 | ## Behavior 39 | 40 | ### `check`: Check for new release versions 41 | 42 | ### `in`: Fetch release 43 | 44 | Downloads all (or a subset specified by `regexp` parameter) of builds for a version. 45 | 46 | Also creates files: 47 | 48 | * `version` file with the current version 49 | * `project` file with the project name 50 | 51 | #### Parameters 52 | 53 | * `regexp`: *Optional.* If provided, only matching files will be downloaded. Otherwise all builds will be downloaded. 54 | 55 | ### `out`: Not implemented 56 | 57 | If you want to upload a new Hashicorp version, perhaps visit https://www.hashicorp.com/jobs/ 58 | 59 | ## Build docker image 60 | 61 | ``` 62 | docker_user=starkandwayne 63 | docker build -t $docker_user/hashicorp-release-resource . 64 | docker push $docker_user/hashicorp-release-resource 65 | ``` 66 | -------------------------------------------------------------------------------- /check: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | exec 3>&1 # make stdout available as fd 3 for the result 6 | exec 1>&2 # redirect all output to stderr for logging 7 | 8 | payload=$(mktemp "$TMPDIR/resource-check.XXXXXX") 9 | cat > "$payload" <&0 10 | 11 | source_project=$(jq -r '.source.project // empty' < "$payload") 12 | if [[ "${source_project}X" == "X" ]]; then 13 | >&2 echo "Source parameter 'project' is missing" 14 | exit 1 15 | fi 16 | 17 | curl -sf "https://releases.hashicorp.com/${source_project}/index.json" > /dev/null || ( 18 | >&2 echo "Unknown hashicorp project '$source_project'" 19 | exit 1 20 | ) 21 | >&2 echo "Looking up versions of '${source_project}'" 22 | latest_version=$(curl -s "https://releases.hashicorp.com/${source_project}/index.json" \ 23 | | jq -r '.versions | keys[]' \ 24 | | grep -v "beta" | grep -v "rc" | grep -v "alpha" | grep -v "+" \ 25 | | sort -V | tail -n1) 26 | 27 | >&2 echo "Latest version $latest_version" 28 | 29 | jq -n --arg version "${latest_version}" '[{ version: $version }]' >&3 30 | -------------------------------------------------------------------------------- /in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | exec 3>&1 # make stdout available as fd 3 for the result 6 | exec 1>&2 # redirect all output to stderr for logging 7 | 8 | destination=$1 9 | 10 | payload=$(mktemp "$TMPDIR/resource-check.XXXXXX") 11 | cat > "$payload" <&0 12 | 13 | version=$(jq -r '.version.version // empty' < "$payload") 14 | if [[ "${version}X" == "X" ]]; then 15 | >&2 echo "Version info 'version' is missing" 16 | exit 1 17 | fi 18 | 19 | source_project=$(jq -r '.source.project // empty' < "$payload") 20 | if [[ "${source_project}X" == "X" ]]; then 21 | >&2 echo "Source parameter 'project' is missing" 22 | exit 1 23 | fi 24 | 25 | params_regexp=$(jq -r '.params.regexp // empty' < "$payload") 26 | 27 | curl -sf "https://releases.hashicorp.com/${source_project}/index.json" > /dev/null || ( 28 | >&2 echo "Unknown hashicorp project '$source_project'" 29 | exit 1 30 | ) 31 | 32 | >&2 echo "Fetching assets ${source_project} v${version}" 33 | cd "$destination" 34 | echo "$version" > version 35 | echo "$source_project" > project 36 | 37 | build_urls=$(curl -s "https://releases.hashicorp.com/${source_project}/index.json" | jq -r ".versions[\"${version}\"].builds[].url") 38 | if [[ ! -z $params_regexp ]]; then 39 | set +e 40 | build_urls=$(echo "${build_urls}" | grep "${params_regexp}") 41 | set -e 42 | fi 43 | if [[ ! -z $build_urls ]]; then 44 | for url in $build_urls; do 45 | >&2 echo "Downloading $url" 46 | curl -O "$url" 47 | done 48 | else 49 | >&2 echo "regexp '$params_regexp' did not match any build URLs" 50 | exit 1 51 | fi 52 | 53 | jq -n --arg version "${version}" '{version: { version: $version }}' >&3 54 | --------------------------------------------------------------------------------