Goss is tool for validating server’s configuration. Dgoss is wrapper written on top of the goss for validating docker images.

Let’s say we want to test the following Dockerfile.

FROM golang as builder
WORKDIR /go/src/github.com/golang-rest-docker/
COPY main.go .
RUN go get
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .



FROM alpine
RUN apk --no-cache add ca-certificates
WORKDIR /
COPY --from=builder /go/src/github.com/golang-rest-docker/app .
CMD ["./app"]

After building the above Dockerfile by executing docker build -t golang-rest:latest -f Dockerfile ., generally we check for the following things:

Writing Validation rules

DGoss provides interactive CLI for writing the validation rules.

dgoss edit golang-rest:latest
[[email protected] golang-rest-docker]$ dgoss edit golang-rest:latest
INFO: Starting docker container
INFO: Container ID: 1f5f05f3
INFO: Run goss add/autoadd to add resources
/goss $ goss a process app
Adding Process to './goss.yaml':

app:
  running: true
/goss $ goss a port 8080
Adding Port to './goss.yaml':

tcp:8080:
  listening: false
  ip: []
/goss $ goss a http http://localhost:8080
Adding HTTP to './goss.yaml':

http://localhost:8080:
  status: 200
  allow-insecure: false
  no-follow-redirects: false
  timeout: 5000
  body: []
/goss $ exit
INFO: Copied '/goss/goss.yaml' from container to '.'
INFO: Deleting container

[[email protected] golang-rest-docker]$ ls -l
total 12
-rw-rw-r-- 1 vagrant vagrant 307 Jan  2 16:59 Dockerfile
-rw-r--r-- 1 vagrant vagrant 219 Jan  2 17:20 goss.yaml
-rw-rw-r-- 1 vagrant vagrant 341 Jan  2 16:39 main.go
port:
  tcp:8080:
    listening: false
    ip: []
process:
  app:
    running: true
http:
  http://localhost:8080:
    status: 200
    allow-insecure: false
    no-follow-redirects: false
    timeout: 5000
    body: []

Running Validation rules

[[email protected] golang-rest-docker]$ dgoss run golang-rest:latest
INFO: Starting docker container
INFO: Container ID: e674252d
INFO: Sleeping for 0.2
INFO: Running Tests
Process: app: running: matches expectation: [true]
Port: tcp:8080: listening: matches expectation: [false]
Port: tcp:8080: ip: skipped
HTTP: http://localhost:8080: status: matches expectation: [200]


Failures/Skipped:

Port: tcp:8080: ip: skipped

Total Duration: 0.012s
Count: 4, Failed: 0, Skipped: 1
INFO: Deleting container

Quality is never an accident; it is always the result of intelligent effort,

John Ruskin.