Skip to content

Latest commit

 

History

History
76 lines (57 loc) · 1.54 KB

buildpacks.md

File metadata and controls

76 lines (57 loc) · 1.54 KB

Using Buildpacks as Kickstart

https://buildpacks.io/docs/

$ brew tap buildpack/tap
$ brew install pack

$ pack builder suggest
$ pack inspect-builder cloudfoundry/cnb:tiny
$ pack stack suggest

To get a more complete view, have a look at the CNB sample repository.

$ mkdir cloud-native-buildpacks
$ cd cloud-native-buildpacks

$ git clone https://github.com/buildpacks/samples.git
$ cd samples/apps

$ pack build -p kotlin-gradle --builder cnbs/sample-builder:alpine kotlin-gradle-app
$ docker run --rm -it -e PORT=8080 -p 8080:8080 kotlin-gradle-app

$ pack build -p java-maven --builder cnbs/sample-builder:alpine java-maven-app
$ docker run --rm -it -e PORT=8080 -p 8080:8080 java-maven-app

Now we build our own small Go base microservice using CN Buildpacks.

$ mkdir golang-simple
$ cd golang-simple

$ touch main.go
$ mod init github.com/lreimer/productive-cloud-native-devex/golang-simple 

$ pack suggest-builders
$ pack build --builder cloudfoundry/cnb:tiny golang-simple-app
$ docker run --rm -it -e PORT=8080 -p 8080:8080 golang-simple-app
package main

import (
	"fmt"
	"net/http"
	"os"
)

func main() {
	http.HandleFunc("/", indexHandler)

	http.ListenAndServe(port(), nil)
}

func port() string {
	port := os.Getenv("PORT")
	if len(port) == 0 {
		port = "8080"
	}
	return ":" + port
}

func indexHandler(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path != "/" {
		http.NotFound(w, r)
		return
	}

	w.WriteHeader(http.StatusOK)
	fmt.Fprintf(w, "Ways Towards a Productive Cloud-native DevEx with CNB")
}