concourse-resource

Crates.ioconcourse-resource
lib.rsconcourse-resource
version0.3.0
sourcesrc
created_at2019-03-17 16:59:56.796899
updated_at2022-02-14 01:08:26.444667
descriptionHelper create to create resources for Concourse CI
homepagehttps://github.com/mockersf/concourse-resource-rs
repositoryhttps://github.com/mockersf/concourse-resource-rs
max_upload_size
id121605
size180,770
François Mockers (mockersf)

documentation

https://docs.rs/concourse-resource

README

concourse-resource-rs License: MIT Build Status Realease Doc Crate

The API docs for the master branch are published here.

Helper to create a Concourse resource in Rust following https://concourse-ci.org/implementing-resource-types.html.

Examples

See examples for more examples.

The included multi-stage Dockerfile shows how to build a minimal docker image to deploy the concourse resource. To run it:

docker build --build-arg EXAMPLE=hello_world .

Simple hello world

use std::{fs::File, io::Write, path::Path};

use serde::{Deserialize, Serialize};

use concourse_resource::*;

struct HelloWorld {}

#[derive(Serialize, Deserialize)]
struct Version {
    ver: String,
}

impl Resource for HelloWorld {
    type Version = Version;

    type Source = concourse_resource::Empty;

    type InParams = concourse_resource::Empty;
    type InMetadata = concourse_resource::Empty;

    type OutParams = concourse_resource::Empty;
    type OutMetadata = concourse_resource::Empty;

    fn resource_check(_: Option<Self::Source>, _: Option<Self::Version>) -> Vec<Self::Version> {
        vec![Self::Version {
            ver: String::from("static"),
        }]
    }

    fn resource_in(
        _source: Option<Self::Source>,
        _version: Self::Version,
        _params: Option<Self::InParams>,
        output_path: &str,
    ) -> Result<InOutput<Self::Version, Self::InMetadata>, Box<dyn std::error::Error>> {
        let mut path = Path::new(output_path).to_path_buf();
        path.push("hello_world.txt");
        let mut file = File::create(path)?;
        file.write_all(b"hello, world!")?;

        Ok(InOutput {
            version: Self::Version {
                ver: String::from("static"),
            },
            metadata: None,
        })
    }

    fn resource_out(
        _: Option<Self::Source>,
        _: Option<Self::OutParams>,
        _: &str,
    ) -> OutOutput<Self::Version, Self::OutMetadata> {
        unimplemented!()
    }
}

create_resource!(HelloWorld);
Commit count: 44

cargo fmt