gofn/gofn

Name: gofn

Owner: gofn

Description: Function process via container provider (serverless minimalist)

Created: 2016-11-30 17:14:40.0

Updated: 2018-01-16 22:46:47.0

Pushed: 2018-01-03 20:16:50.0

Homepage:

Size: 1450

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

gofn

Build Status GoDoc Go Report Card codecov Join the chat at https://gitter.im/gofn/gofn

Function process via container provider

Premise
Install
et github.com/gofn/gofn
Example
age main

rt (
"context"
"flag"
"fmt"
"log"
"runtime"
"sync"

"github.com/gofn/gofn"
"github.com/gofn/gofn/iaas/digitalocean"
"github.com/gofn/gofn/provision"


 main() {
wait := &sync.WaitGroup{}
contextDir := flag.String("contextDir", "./", "a string")
dockerfile := flag.String("dockerfile", "Dockerfile", "a string")
imageName := flag.String("imageName", "", "a string")
remoteBuildURI := flag.String("remoteBuildURI", "", "a string")
volumeSource := flag.String("volumeSource", "", "a string")
volumeDestination := flag.String("volumeDestination", "", "a string")
remoteBuild := flag.Bool("remoteBuild", false, "true or false")
input := flag.String("input", "", "a string")
flag.Parse()
parallels := runtime.GOMAXPROCS(-1) // use max allowed CPUs to parallelize
wait.Add(parallels)
for i := 0; i < parallels; i++ {
    go run(*contextDir, *dockerfile, *imageName, *remoteBuildURI, *volumeSource, *volumeDestination, wait, *remoteBuild, *input)
}
wait.Wait()


 run(contextDir, dockerfile, imageName, remoteBuildURI, volumeSource, volumeDestination string, wait *sync.WaitGroup, remote bool, input string) {
buildOpts := &provision.BuildOptions{
    ContextDir: contextDir,
    Dockerfile: dockerfile,
    ImageName:  imageName,
    RemoteURI:  remoteBuildURI,
    StdIN:      input,
}
containerOpts := &provision.ContainerOptions{}
if volumeSource != "" {
    if volumeDestination == "" {
        volumeDestination = volumeSource
    }
    containerOpts.Volumes = []string{fmt.Sprintf("%s:%s", volumeSource, volumeDestination)}
}
if remote {
    buildOpts.Iaas = &digitalocean.Digitalocean{}
}

defer wait.Done()
stdout, stderr, err := gofn.Run(context.Background(), buildOpts, containerOpts)
if err != nil {
    log.Println(err)
}
fmt.Println("Stderr: ", stderr)
fmt.Println("Stdout: ", stdout)

Run Example
xamples

un main.go -contextDir=testDocker -imageName=python -dockerfile=Dockerfile

 using volume
un main.go -contextDir=testDocker -imageName=python -dockerfile=Dockerfile -volumeSource=/tmp -volumeDestination=/tmp

 using remote Dockerfile
un main.go -remoteBuildURI=https://github.com/gofn/dockerfile-python-example.git -imageName="pythonexample"

u can also send a string that will be written to the stdin of the container
un main.go -contextDir=testDocker -imageName=python -dockerfile=Dockerfile -input "input string"

 run in digital ocean
rt DIGITALOCEAN_API_KEY="paste your key here"
un main.go -contextDir=testDocker -imageName=python -dockerfile=Dockerfile -remoteBuild=true

You can also compile with go build or build and install with go install command then run it as a native executable.

Example Parameters

gofn generates the images with “gofn/” as a prefix.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.