Skip to content

Instantly share code, notes, and snippets.

FROM golang
COPY . /code
ENV GO111MODULE on
WORKDIR /code
RUN ["go", "run", "-mod=vendor", "main.go"]
@wayneashleyberry
wayneashleyberry / app.go
Created August 6, 2018 10:55
Go command to run an application
// Command contains the app command
var Command = &cobra.Command{
Use: "app",
Short: "Run the application",
Run: func(cmd *cobra.Command, args []string) {
var s app.Specification
envconfig.MustProcess("", &s)
if err := probe.Create(); err != nil {
panic(err)
@wayneashleyberry
wayneashleyberry / deployment.yml
Created August 6, 2018 10:54
Probes for a Kubernetes deployment configuration
livenessProbe:
exec:
command:
- cat
- /tmp/live
readinessProbe:
httpGet:
path: /health
port: 80
@wayneashleyberry
wayneashleyberry / live.go
Created August 6, 2018 10:53
Go command for a Kubernetes liveness probe
package live
import (
"os"
"github.com/overhq/over-stories-api/pkg/probe"
"github.com/spf13/cobra"
)
// Command contains the livee command
@wayneashleyberry
wayneashleyberry / probe.go
Created August 6, 2018 10:52
package for creating probe files
package probe
import "os"
const liveFile = "/tmp/live"
// Create will create a file for the liveness check
func Create() error {
_, err := os.Create(liveFile)
return err
@wayneashleyberry
wayneashleyberry / main.go
Created August 6, 2018 10:50
Go http server with graceful shutdown
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
)
@wayneashleyberry
wayneashleyberry / deployment.yml
Created August 6, 2018 10:48
Example probe configuration for a Kubernetes deployment
livenessProbe:
httpGet:
path: /health
port: 80
readinessProbe:
httpGet:
path: /health
port: 80
@wayneashleyberry
wayneashleyberry / main.go
Created August 6, 2018 10:47
The hello world of Go servers (with a health check)
package main
import (
"net/http"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)
func main() {
foo: bar
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-service
spec:
replicas: 1
selector:
matchLabels:
app: my-app
strategy: