Skip to content

Commit

Permalink
feat(k8s): in-cluster building
Browse files Browse the repository at this point in the history
Moving this from our closed-source version. This adds an option to build
container images inside Kubernetes clusters, and by extension removes the
need for Docker and Kubernetes running on developer machines.

Use it by setting `buildMode: "cluster-docker"` in the `kubernetes` provider
configuration.
  • Loading branch information
edvald committed May 31, 2019
1 parent df47c3c commit fd27897
Show file tree
Hide file tree
Showing 56 changed files with 1,078 additions and 206 deletions.
8 changes: 8 additions & 0 deletions examples/simple-project/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ project:
- name: local
providers:
- name: local-kubernetes
- name: remote
providers:
- name: kubernetes
# Replace these values as appropriate
context: gke_garden-dev-200012_europe-west1-b_garden-dev-1
namespace: ${local.env.USER || "default"}-simple-project
defaultHostname: ${local.env.USER || "default"}-simple-project.dev-1.sys.garden
buildMode: cluster-docker
2 changes: 1 addition & 1 deletion examples/vote-helm/api/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module:
values:
name: api
image:
repository: api-image
repository: ${modules.api-image.outputs.deployment-image-name}
tag: ${modules.api-image.version}
ingress:
enabled: true
Expand Down
2 changes: 1 addition & 1 deletion examples/vote-helm/result/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module:
values:
name: result
image:
repository: result-image
repository: ${modules.result-image.outputs.deployment-image-name}
tag: ${modules.result-image.version}
ingress:
enabled: true
Expand Down
1 change: 1 addition & 0 deletions examples/vote-helm/vote/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module:
- api
values:
image:
repository: ${modules.vote-image.outputs.deployment-image-name}
tag: ${modules.vote-image.version}
ingress:
enabled: true
Expand Down
1 change: 1 addition & 0 deletions examples/vote-helm/worker/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ module:
dependencies: [worker-image]
values:
image:
repository: ${modules.worker-image.outputs.deployment-image-name}
tag: ${modules.worker-image.version}
8 changes: 8 additions & 0 deletions examples/vote/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ project:
- name: local
providers:
- name: local-kubernetes
- name: remote
providers:
- name: kubernetes
# Replace these values as appropriate
context: gke_garden-dev-200012_europe-west1-b_garden-dev-1
namespace: ${local.env.USER || "default"}-vote
defaultHostname: ${local.env.USER || "default"}-vote.dev-1.sys.garden
buildMode: cluster-docker
20 changes: 20 additions & 0 deletions garden-service/bin/push-containers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash -e

garden_service_root=$(cd `dirname $0` && cd .. && pwd)

cd ${garden_service_root}

args=( $@ )
version=${args[0]:-$(git rev-parse --short HEAD)}

echo "Building version ${version}"

npm run build

docker build -t gardendev/garden:${version} .
docker build -t gardendev/garden-gcloud:${version} --build-arg NAME=garden --build-arg VERSION=${version} -f gcloud.Dockerfile .

echo "Pushing images"

docker push gardendev/garden:${version}
docker push gardendev/garden-gcloud:${version}
10 changes: 10 additions & 0 deletions garden-service/gcloud.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ARG NAME
ARG VERSION
FROM gardendev/${NAME:-garden}:${VERSION}

RUN apk add --no-cache python \
&& mkdir -p /gcloud \
&& curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz | tar xz -C /gcloud \
&& /gcloud/google-cloud-sdk/install.sh --quiet \
&& ln -s /gcloud/google-cloud-sdk/bin/gcloud /usr/local/bin/gcloud \
&& chmod +x /usr/local/bin/gcloud
42 changes: 21 additions & 21 deletions garden-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion garden-service/src/docs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { projectSchema } from "../config/project"
import { baseModuleSpecSchema } from "../config/module"
import handlebars = require("handlebars")
import { configSchema as localK8sConfigSchema } from "../plugins/kubernetes/local/config"
import { configSchema as k8sConfigSchema } from "../plugins/kubernetes/kubernetes"
import { configSchema as k8sConfigSchema } from "../plugins/kubernetes/config"
import { configSchema as openfaasConfigSchema } from "../plugins/openfaas/openfaas"
import { joiArray } from "../config/common"
import { mavenContainerConfigSchema } from "../plugins/maven-container/maven-container"
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/plugins/container/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { GardenPlugin } from "../../types/plugin/plugin"
import { containerHelpers } from "./helpers"
import { ContainerModule, containerModuleSpecSchema } from "./config"
import { buildContainerModule, getContainerBuildStatus } from "./build"
import { KubernetesProvider } from "../kubernetes/kubernetes"
import { KubernetesProvider } from "../kubernetes/config"
import { ConfigureModuleParams } from "../../types/plugin/module/configure"
import { PublishModuleParams } from "../../types/plugin/module/publishModule"
import { HotReloadServiceParams } from "../../types/plugin/service/hotReloadService"
Expand Down
Loading

0 comments on commit fd27897

Please sign in to comment.