Skip to content

Commit

Permalink
Add compose integration test and example (with note). Add kompose to …
Browse files Browse the repository at this point in the history
…Docker image
  • Loading branch information
nkubala committed Nov 15, 2018
1 parent c3d1ef3 commit 340a392
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 8 deletions.
5 changes: 5 additions & 0 deletions deploy/skaffold/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ RUN curl -LO https://github.com/kubernetes-sigs/kustomize/releases/download/v${K
chmod +x kustomize_${KUSTOMIZE_VERSION}_linux_amd64 && \
mv kustomize_${KUSTOMIZE_VERSION}_linux_amd64 /usr/local/bin/kustomize

ENV KOMPOSE_VERSION=1.17.0
RUN curl -L https://github.com/kubernetes/kompose/releases/download/v${KOMPOSE_VERSION}/kompose-linux-amd64 -o kompose && \
chmod +x kompose-linux-amd64 && \
mv kompose-linux-amd64 /usr/local/bin/kompose

RUN echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list \
&& curl https://bazel.build/bazel-release.pub.gpg | apt-key add -

Expand Down
7 changes: 7 additions & 0 deletions examples/compose/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM golang:1.10.1-alpine3.7 as builder
COPY main.go .
RUN go build -o /app main.go

FROM alpine:3.7
CMD ["./app"]
COPY --from=builder /app .
10 changes: 10 additions & 0 deletions examples/compose/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== Example: Running skaffold with docker-compose files
:icons: font

This example provides a simple application set up to run with
https://docs.docker.com/compose/[docker-compose].
Notice there is no skaffold configuration present: to run this example,
first run `skaffold init --compose-file docker-compose.yaml`, which will
invoke the https://github.com/kubernetes/kompose[kompose] binary to generate
kubernetes manifests based off of the docker-compose configuration, and then run
`skaffold init` to generate the skaffold configuration.
7 changes: 7 additions & 0 deletions examples/compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'
services:
compose:
build: .
image: "gcr.io/k8s-skaffold/compose"
ports:
- "5000:5000"
13 changes: 13 additions & 0 deletions examples/compose/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
"time"
)

func main() {
for {
fmt.Println("Hello world!")
time.Sleep(time.Second * 1)
}
}
7 changes: 7 additions & 0 deletions integration/examples/compose/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM golang:1.10.1-alpine3.7 as builder
COPY main.go .
RUN go build -o /app main.go

FROM alpine:3.7
CMD ["./app"]
COPY --from=builder /app .
10 changes: 10 additions & 0 deletions integration/examples/compose/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== Example: Running skaffold with docker-compose files
:icons: font

This example provides a simple application set up to run with
https://docs.docker.com/compose/[docker-compose].
Notice there is no skaffold configuration present: to run this example,
first run `skaffold init --compose-file docker-compose.yaml`, which will
invoke the https://github.com/kubernetes/kompose[kompose] binary to generate
kubernetes manifests based off of the docker-compose configuration, and then run
`skaffold init` to generate the skaffold configuration.
7 changes: 7 additions & 0 deletions integration/examples/compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'
services:
compose:
build: .
image: "gcr.io/k8s-skaffold/compose"
ports:
- "5000:5000"
13 changes: 13 additions & 0 deletions integration/examples/compose/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
"time"
)

func main() {
for {
fmt.Println("Hello world!")
time.Sleep(time.Second * 1)
}
}
25 changes: 17 additions & 8 deletions integration/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,10 @@ func TestListConfig(t *testing.T) {

func TestInit(t *testing.T) {
type testCase struct {
name string
dir string
args []string
name string
dir string
args []string
skipSkaffoldYaml bool
}

tests := []testCase{
Expand All @@ -426,16 +427,24 @@ func TestInit(t *testing.T) {
"-a", "leeroy-web/Dockerfile=gcr.io/k8s-skaffold/leeroy-web",
},
},
{
name: "compose",
dir: "../examples/compose",
args: []string{"--compose-file", "docker-compose.yaml"},
skipSkaffoldYaml: true,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
oldYamlPath := filepath.Join(test.dir, "skaffold.yaml")
oldYaml, err := removeOldSkaffoldYaml(oldYamlPath)
if err != nil {
t.Fatalf("removing original skaffold.yaml: %s", err)
if !test.skipSkaffoldYaml {
oldYamlPath := filepath.Join(test.dir, "skaffold.yaml")
oldYaml, err := removeOldSkaffoldYaml(oldYamlPath)
if err != nil {
t.Fatalf("removing original skaffold.yaml: %s", err)
}
defer restoreOldSkaffoldYaml(oldYaml, oldYamlPath)
}
defer restoreOldSkaffoldYaml(oldYaml, oldYamlPath)

generatedYaml := "skaffold.yaml.out"
defer func() {
Expand Down

0 comments on commit 340a392

Please sign in to comment.