An open API service indexing awesome lists of open source software.

https://github.com/tbe/go-concourse-resource

a Go module to simplify the development of concourse resources
https://github.com/tbe/go-concourse-resource

Last synced: 11 months ago
JSON representation

a Go module to simplify the development of concourse resources

Awesome Lists containing this project

README

          

# concourse-resource

[![Go Report Card](https://goreportcard.com/badge/pkg.loki.codes/concourse-resource)](https://goreportcard.com/report/pkg.loki.codes/concourse-resource)
[![Go Reference](https://pkg.go.dev/badge/pkg.loki.codes/concourse-resource.svg)](https://pkg.go.dev/pkg.loki.codes/concourse-resource)

***a Go module to simplify the development of concourse resources***

## Features

### minimal dependencies

Only `github.com/stretchr/testify` and `github.com/go-playground/validator/v10` are directly required by this module.

### config validation

To validate your input, simply add the correct [`validator` tags](https://pkg.go.dev/github.com/go-playground/validator/v10)

### flexible

Use whatever library you want, do what ever you want. This module takes only care about the communication with concourse.
No assumptions beyond that are made.

### testable

Test your resources with `go test`. A full set of testing helpers and a `testify` suite are provided.

## Usage

To develop a new resource, you must provide a type, that fulfills at least one of the following interfaces:

- `types.CheckResource`
- `types.InResource`
- `types.OutResource`

If your resource takes parameters for `in` or `out`, the type must implement the `types.ParametrizedResource` interface.

In addition, a factory function must be provided.

While all arguments to `check`, `in` and `out` are provided by the resource at runtime, the configuration (`source`)
must be provided statically.

All communication with *concourse* is done by the `Handler`. For an example of a resource, have a look at the [`test/dummy`](test/dummy)
implementation.

Inside your main, put all the stuff together and call the `Run` method.

```go
package main

import (
"log"

resource "pkg.loki.codes/concourse-resource"

"your/resource/implementation"
)

func main() {
if err := resource.New[implementation.Config](implementation.New).Run(); err != nil {
log.Fatal(err)
}
}

```

### Environment variables (metadata)

The [Concourse metadata](https://concourse-ci.org/implementing-resource-types.html#resource-metadata) can be accessed with the help
of some wrappers.

See [metadata](metadata)

## Container build

To build your container image, you may just symlink the binary to the correct locations. For example:

```Dockerfile
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
```

## See also

- [Concourse Documentation](https://concourse-ci.org/implementing-resource-types.html****)

## Testing

There is an extensive test framework. See [test](test)