Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Resources v2 #1

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions 01-resources-v2/branch-gen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
resources:
- name: atc
type: git
source: {uri: https://github.com/concourse/atc}
space: {branch: master}
vito marked this conversation as resolved.
Show resolved Hide resolved

- name: atc-gen
type: git
source: {uri: "https://github.com/concourse/atc"}

jobs:
- name: gen
plan:
- get: atc
trigger: true
- task: gen
file: atc/ci/gen.yml
config:
platform: ...
image_resource: ...
outputs:
- name: generated-repo
# has the generated code committed to the repo
- name: branch-name
# has a 'name' file with `gen-(some deterministic hash)`
- put: atc-gen
params: {branch_name: branch-name/name, repository: generated-repo}

- name: test
plan:
- get: atc
passed: [gen]
trigger: true
- get: atc-gen
passed: [gen]
spaces: [{branch: gen-*}]
trigger: true
- task: test
file: atc/ci/test.yml
30 changes: 30 additions & 0 deletions 01-resources-v2/commit-status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
resource_types:
- name: github-status
type: docker-image
source: {repository: concourse/github-status-resource}

resources:
- name: atc
type: git
source:
uri: https://github.com/concourse/atc
notify:
- on: build_started
using: atc-status # invoke atc-status notifier with 'self' set to this resource
- on: build_finished
using: atc-status # invoke atc-status notifier with 'self' set to this resource

- name: atc-status
type: github-status
source:
repository: concourse/atc
access_token: ((token))

jobs:
- name: atc-pr-unit
plan:
- get: atc-pr
trigger: true
spaces: all

This comment was marked as spam.

This comment was marked as spam.

- task: unit
file: atc/ci/pr.yml
2 changes: 2 additions & 0 deletions 01-resources-v2/git-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
check-repo
dot
4 changes: 4 additions & 0 deletions 01-resources-v2/git-example/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source :rubygems

gem 'git'
gem 'pry'
19 changes: 19 additions & 0 deletions 01-resources-v2/git-example/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GEM
remote: http://rubygems.org/
specs:
coderay (1.1.2)
git (1.4.0)
method_source (0.9.0)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)

PLATFORMS
ruby

DEPENDENCIES
git
pry

BUNDLED WITH
1.16.2
13 changes: 13 additions & 0 deletions 01-resources-v2/git-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Git Resource v2

This implementation is done in Ruby using the `git` gem. I chose Ruby
over Bash because having a real language with more accessible data
structures is probably going to be more important with this new
interface, and Ruby feels pretty well suited (really just need a bit more
than Bash).

Please leave comments on parts you like/don't like! But bear in mind the
goal here isn't necessarily the prettiness of the code, it's to see what
kinds of things the resource has to do. I'll be using Ruby purely as a
scripting language, hacking things together where needed in the interest
of brevity.
104 changes: 104 additions & 0 deletions 01-resources-v2/git-example/artifact
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env ruby

require "json"
require "git"

# $request = JSON.parse(STDIN.read, symbolize_names: true)

def commit_versions(log)
log.collect do |c|
{
version: {ref: c.sha},
metadata: [
{name: "author", value: c.author.name},
{name: "author_date", value: c.author_date},
{name: "commit", value: c.sha},
{name: "committer", value: c.committer.name},
{name: "committer_date", value: c.committer_date},
{name: "message", value: c.message}
]
}
end
end

case ARGV[0]
when "check"
$request = {
config: {uri: "https://github.com/vito/booklit"},
from: {master: {ref: "40bc6986197e411471d306bb8eb3a21c5b5f9d26"}}
vito marked this conversation as resolved.
Show resolved Hide resolved
}

git =
if Dir.exists?("check-repo")
Git.open("check-repo").tap(&:fetch)
else
Git.clone($request[:config][:uri], "check-repo")
end

spaces = []
git.branches.local.each do |b|
# skip "default branch" entry
next if b.name =~ /HEAD ->/

b.checkout

paths = $request[:config][:paths] || ["."]
paths += ($request[:config][:ignore_paths] || []).collect { |p| ":!" + p }

log = git.log(nil).path(paths)

# TODO: this will get *all* commits and load it into memory, which is
# probably a bad idea. the linux repo for example has 710k+ commits.
#
# should this be paginated? or should it stream each version back to the
# caller somehow so everything doesn't have to be sucked into memory?
#
# TODO: when checking from a given version, should the given version be
# returned? this was done in the original API so that you could run
# `check-resource -f <version>`, but in this new world where we just always
# collect all versions, that won't be necessary. in fact, `check-resource
# -f <version>` would need to be given a space that it's checking against.
commits =
if version = $request[:from][b.name]
begin
commit_versions(log.between(version[:ref]))
rescue
# bad ref; emit all versions
commit_versions(log)
end
else
commit_versions(log)
end

$stderr.puts "#{b.name}: #{commits.length} commits"

spaces << {
space: {branch: b.name},
versions: commits
}
end

response = JSON.dump(spaces)
puts response
puts response.size
when "get"
$request = {
config: {uri: "https://github.com/vito/booklit"},
space: {branch: "master"},
vito marked this conversation as resolved.
Show resolved Hide resolved
version: {ref: "f828f2758256b0e93dc3c101f75604efe92ca07e"}
}

git =
Git.clone($request[:config][:uri], "dot", # TODO: irl this would be '.'
branch: $request[:space][:branch],
recursive: true)

git.checkout($request[:version][:ref])

# TODO: draw the rest of the owl
#
# most of this is uninteresting.

when "put"
puts "putting"
end
13 changes: 13 additions & 0 deletions 01-resources-v2/git-example/info
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env ruby

require "json"

puts JSON.dump({
version: "2.0"

artifacts: {
check: "artifact check",
get: "artifact get",
put: "artifact put"
}
})
32 changes: 32 additions & 0 deletions 01-resources-v2/notifications.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
resource_types:
- name: slack-notifier
type: docker-image
source: {repository: concourse/slack-notifier-resource}

resources:
- name: atc
type: git
source:
uri: https://github.com/concourse/atc

- name: slack-alert
type: slack-notifier
source:
url: https://hooks.slack.com/services/XXXX
notify:
- on: build_finished
params:
template:
succeeded: |
Yay! <{{.ExternalURL}}/builds/{{.BuildID}}|{{.BuildName}}> succeeded. :)
failed: |
Oh no! <{{.ExternalURL}}/builds/{{.BuildID}}|{{.BuildName}}> failed. :(

jobs:
- name: atc-pr-unit
plan:
- get: atc-pr
trigger: true
spaces: all
- task: unit
file: atc/ci/pr.yml
Loading