Git Product home page Git Product logo

resource-framework's Introduction

DEPRECTAION NOTICE

This repostiry is deprecated. Please move to https://github.com/tbe/go-concourse-resource

resource-framework

a GoLang framework to implement concourse-ci resources

Usage

For full usage, please see godoc

package main

import (
	"log"

	"github.com/tbe/resource-framework/resource"
)

// DummySource defines the source configuration for our dummy resource
type DummySource struct {
	DoSomething bool `json:"do_something"`
}

type DummyVersion struct {
	Counter int `json:"counter" validate:"gt=0"`
}

// DummyResource implements a dummy check resource
type DummyResource struct {
	source  *DummySource
	version *DummyVersion
}

func NewDummyResource() *DummyResource {
	return &DummyResource{
		source:  &DummySource{},
		version: &DummyVersion{},
	}
}

func (r *DummyResource) Source() (source interface{}) {
	return r.source
}

func (r *DummyResource) Version() (version interface{}) {
	return r.version
}

func (r *DummyResource) Check() (version interface{}, err error) {
	if r.source.DoSomething {
		r.version.Counter++
	}
	return r.version, nil
}

func main() {
	r := NewDummyResource()

	handler, err := resource.NewHandler(r)
	if err != nil {
		log.Fatal(err)
	}
	_ = handler.Run()
}

Testing

The test package provides a helper for testing resources, written with the resource-framwork. Have a look at the tests for the resource package and on godoc

Resource Building

To build a docker container for your resource, you could to this with a Dockerfile like this:

FROM golang:alpine AS builder

RUN apk update && apk add --no-cache git ca-certificates && update-ca-certificates

ADD . /app/
WORKDIR /app
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o resource .
RUN mkdir -p /target/opt/resource/
RUN cp resource /target/opt/resource/
RUN ln -s resource /target/opt/resource/in
RUN ln -s resource /target/opt/resource/out
RUN ln -s resource /target/opt/resource/check


FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /target/opt /opt

resource-framework's People

Contributors

tbe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

amasser

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.