Skip to content

Commit

Permalink
Merge branch 'master' into refactor-break-2
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 committed Sep 12, 2019
2 parents ee038d0 + 7570afa commit c0bf9af
Show file tree
Hide file tree
Showing 38 changed files with 485 additions and 399 deletions.
3 changes: 1 addition & 2 deletions deprecation-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ However the **behavior** of individual component might suffer breaking changes d
- Artifact types:
- Dockerfile: beta
- Bazel: beta
- jibMaven: alpha
- jibGradle: alpha
- Jib: beta
- Filesync: alpha
- Port-forwarding: alpha
- Taggers: beta
Expand Down
35 changes: 21 additions & 14 deletions docs/content/en/docs/how-tos/builders/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,26 @@ Skaffold requires using Jib v1.4.0 or later.

### Configuration

To use Jib, add a `jibMaven` or `jibGradle` field to each artifact you specify in the
To use Jib, add a `jib` field to each artifact you specify in the
`artifacts` part of the `build` section. `context` should be a path to
your Maven or Gradle project.

{{< alert title="Note" >}}
Your project must be configured to use Jib already.
{{< /alert >}}

The `jibMaven` type offers the following options:
The `jib` type offers the following options:

{{< schema root="JibMavenArtifact" >}}
{{< schema root="JibArtifact" >}}

The `jibGradle` type offers the following options:
Skaffold's jib support chooses the underlying builder (Maven or Gradle)
based on the presence of standard build files in the `artifact`'s
`context` directory:

{{< schema root="JibGradleArtifact" >}}
- _Maven_: `pom.xml`, or `.mvn` directory.
- _Gradle_: `build.gradle`, `gradle.properties`, `settings.gradle`,
or the Gradle wrapper script (`gradlew`, `gradlew.bat`, or
`gradlew.cmd`).

### Example

Expand All @@ -190,13 +195,13 @@ each produce a separate container image.

#### Maven

To build a Maven multi-module project, first identify the modules that should
produce a container image. Then for each such module:
To build a Maven multi-module project, first identify the sub-projects (also called _modules_
in Maven) that should produce a container image. Then for each such sub-project:

- Create a Skaffold `artifact` in the `skaffold.yaml`:
- Create a Skaffold `artifact` in the `skaffold.yaml`.
- Set the `artifact`'s `context` field to the root project location.
- Add a `jibMaven` element and set its `module` field to the module's
`:artifactId`, `groupId:artifactId`, or the relative path to the module
- Add a `jib` element and set its `project` field to the sub-project's
`:artifactId`, `groupId:artifactId`, or the relative path to the sub-project
_within the project_.

{{% alert title="Updating from earlier versions" %}}
Expand All @@ -207,10 +212,12 @@ no longer required with Jib 1.4.0 and should be removed.

#### Gradle

To build a multi-module project with Gradle, specify each sub-project as a separate
Skaffold artifact. For each artifact, add a `jibGradle` field with a `project` field
containing the sub-project's name (the directory, by default). Each artifact's `context` field
should point to the root project location.
To build a multi-module project with Gradle, first identify the sub-projects that should produce
a container image. Then for each such sub-project:

- Create a Skaffold `artifact` in the `skaffold.yaml`.
- Set the `artifact`'s `context` field to the root project location.
- Add a `jib` element and set its `project` field to the sub-project's name (the directory, by default).

## Jib Maven and Gradle remotely with Google Cloud Build

Expand Down
93 changes: 12 additions & 81 deletions docs/content/en/schemas/v1beta14.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@
"gcr.io/k8s-skaffold/example"
]
},
"jibMaven": {
"$ref": "#/definitions/JibMavenArtifact",
"description": "*alpha* builds images using the [Jib plugin for Maven](https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin).",
"x-intellij-html-description": "<em>alpha</em> builds images using the <a href=\"https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin\">Jib plugin for Maven</a>."
"jib": {
"$ref": "#/definitions/JibArtifact",
"description": "*alpha* builds images using the [Jib plugins for Maven or Gradle](https://github.com/GoogleContainerTools/jib/).",
"x-intellij-html-description": "<em>alpha</em> builds images using the <a href=\"https://github.com/GoogleContainerTools/jib/\">Jib plugins for Maven or Gradle</a>."
},
"sync": {
"$ref": "#/definitions/Sync",
Expand All @@ -178,42 +178,7 @@
"image",
"context",
"sync",
"jibMaven"
],
"additionalProperties": false
},
{
"properties": {
"context": {
"type": "string",
"description": "directory containing the artifact's sources.",
"x-intellij-html-description": "directory containing the artifact's sources.",
"default": "."
},
"image": {
"type": "string",
"description": "name of the image to be built.",
"x-intellij-html-description": "name of the image to be built.",
"examples": [
"gcr.io/k8s-skaffold/example"
]
},
"jibGradle": {
"$ref": "#/definitions/JibGradleArtifact",
"description": "*alpha* builds images using the [Jib plugin for Gradle](https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin).",
"x-intellij-html-description": "<em>alpha</em> builds images using the <a href=\"https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin\">Jib plugin for Gradle</a>."
},
"sync": {
"$ref": "#/definitions/Sync",
"description": "*alpha* local files synced to pods instead of triggering an image build when modified.",
"x-intellij-html-description": "<em>alpha</em> local files synced to pods instead of triggering an image build when modified."
}
},
"preferredOrder": [
"image",
"context",
"sync",
"jibGradle"
"jib"
],
"additionalProperties": false
},
Expand Down Expand Up @@ -1236,67 +1201,33 @@
"description": "patch to be applied by a profile.",
"x-intellij-html-description": "patch to be applied by a profile."
},
"JibGradleArtifact": {
"JibArtifact": {
"properties": {
"args": {
"items": {
"type": "string"
},
"type": "array",
"description": "additional build flags passed to Gradle.",
"x-intellij-html-description": "additional build flags passed to Gradle.",
"description": "additional build flags passed to the builder.",
"x-intellij-html-description": "additional build flags passed to the builder.",
"default": "[]",
"examples": [
"[\"--no-build-cache\"]"
]
},
"project": {
"type": "string",
"description": "selects which Gradle project to build.",
"x-intellij-html-description": "selects which Gradle project to build."
"description": "selects which sub-project to build for multi-module builds.",
"x-intellij-html-description": "selects which sub-project to build for multi-module builds."
}
},
"preferredOrder": [
"project",
"args"
],
"additionalProperties": false,
"description": "*alpha* builds images using the [Jib plugin for Gradle](https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin).",
"x-intellij-html-description": "<em>alpha</em> builds images using the <a href=\"https://github.com/GoogleContainerTools/jib/tree/master/jib-gradle-plugin\">Jib plugin for Gradle</a>."
},
"JibMavenArtifact": {
"properties": {
"args": {
"items": {
"type": "string"
},
"type": "array",
"description": "additional build flags passed to Maven.",
"x-intellij-html-description": "additional build flags passed to Maven.",
"default": "[]",
"examples": [
"[\"-x\", \"-DskipTests\"]"
]
},
"module": {
"type": "string",
"description": "selects which Maven module to build, for a multi module project.",
"x-intellij-html-description": "selects which Maven module to build, for a multi module project."
},
"profile": {
"type": "string",
"description": "selects which Maven profile to activate.",
"x-intellij-html-description": "selects which Maven profile to activate."
}
},
"preferredOrder": [
"module",
"profile",
"args"
],
"additionalProperties": false,
"description": "*alpha* builds images using the [Jib plugin for Maven](https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin).",
"x-intellij-html-description": "<em>alpha</em> builds images using the <a href=\"https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin\">Jib plugin for Maven</a>."
"description": "*alpha* builds images using the [Jib plugins for Maven and Gradle](https://github.com/GoogleContainerTools/jib/).",
"x-intellij-html-description": "<em>alpha</em> builds images using the <a href=\"https://github.com/GoogleContainerTools/jib/\">Jib plugins for Maven and Gradle</a>."
},
"KanikoArtifact": {
"properties": {
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/jib-gradle/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Config
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-jib-gradle
jibGradle: {}
jib: {}

# optional profile to run the jib build on Google Cloud Build
profiles:
Expand Down
19 changes: 11 additions & 8 deletions integration/examples/jib-multimodule/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
:icons: font

Jib is one of the supported builders in Skaffold.
[Jib](https://github.com/GoogleContainerTools/jib) builds Docker and OCI images
https://github.com/GoogleContainerTools/jib[Jib] builds Docker and OCI images
for your Java applications and is available as plugins for Maven and Gradle.

Sometimes a project is configured to have multiple modules to create several
Sometimes a project is configured to have multiple _modules_ to create several
container images. Skaffold can work with Jib to build these containers as
required.

Expand All @@ -18,14 +18,17 @@ build:
- image: gcr.io/k8s-skaffold/skaffold-jib-1
# context is the root of the multi-module project
context: .
jibMaven:
# module is either the relative location within the project (i.e.,
# relative to `context`) or :artifactId or groupId:artifactId
module: moduleLocation
jib:
# project is the location relative to the artifact `context`
# For Maven, this is either the path relative to the artifact's
# `context`, or `:artifactId` or `groupId:artifactId`.
# For Gradle, this is the project name (defaults to the
# directory name).
project: moduleLocation
- image: gcr.io/k8s-skaffold/skaffold-jib-2
context: .
jibMaven:
module: :artifactId
jib:
project: :artifactId
----

There are a few caveats:
Expand Down
12 changes: 6 additions & 6 deletions integration/examples/jib-multimodule/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ kind: Config
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-jib-1
jibMaven:
# module can be the relative directory
module: project1
jib:
# project can be the relative directory
project: project1
- image: gcr.io/k8s-skaffold/skaffold-jib-2
jibMaven:
# module can be [groupId]:artifactId
module: :skaffold-project-2
jib:
# project can be [groupId]:artifactId
project: :skaffold-project-2

# optional profile to run the jib build on Google Cloud Build
profiles:
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/jib/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-example
context: .
jibMaven: {}
jib: {}
----

Please note that this example is for a standalone Maven project, where
Expand Down
2 changes: 1 addition & 1 deletion integration/examples/jib/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Config
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-jib
jibMaven: {}
jib: {}

# optional profile to run the jib build on Google Cloud Build
profiles:
Expand Down
4 changes: 2 additions & 2 deletions integration/testdata/debug/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: skaffold/v1beta10
apiVersion: skaffold/v1beta14
kind: Config
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-debug-jib
context: jib
jibMaven:
jib:
args:
- --no-transfer-progress
- image: gcr.io/k8s-skaffold/skaffold-debug-npm
Expand Down
2 changes: 1 addition & 1 deletion integration/testdata/jib-gradle/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Config
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-jib
jibGradle: {}
jib: {}

profiles:
- name: gcb
Expand Down
4 changes: 2 additions & 2 deletions integration/testdata/jib/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Config
build:
artifacts:
- image: gcr.io/k8s-skaffold/skaffold-jib
jibMaven:
jib:
args:
- --no-transfer-progress

Expand All @@ -16,5 +16,5 @@ profiles:
- name: old-jib
patches:
- op: add
path: /build/artifacts/0/jibMaven/args
path: /build/artifacts/0/jib/args
value: ['-Djib.maven-plugin-version=1.3.0']
39 changes: 24 additions & 15 deletions pkg/skaffold/build/gcb/jib.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,35 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/jib"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/pkg/errors"
cloudbuild "google.golang.org/api/cloudbuild/v1"
)

func (b *Builder) jibMavenBuildSpec(artifact *latest.JibMavenArtifact, tag string) cloudbuild.Build {
return cloudbuild.Build{
Steps: []*cloudbuild.BuildStep{{
Name: b.MavenImage,
Entrypoint: "sh",
Args: fixHome("mvn", jib.GenerateMavenArgs("build", tag, artifact, b.skipTests, b.insecureRegistries)),
}},
func (b *Builder) jibBuildSpec(artifact *latest.Artifact, tag string) (cloudbuild.Build, error) {
t, err := jib.DeterminePluginType(artifact.Workspace, artifact.JibArtifact)
if err != nil {
return cloudbuild.Build{}, err
}
}

func (b *Builder) jibGradleBuildSpec(artifact *latest.JibGradleArtifact, tag string) cloudbuild.Build {
return cloudbuild.Build{
Steps: []*cloudbuild.BuildStep{{
Name: b.GradleImage,
Entrypoint: "sh",
Args: fixHome("gradle", jib.GenerateGradleArgs("jib", tag, artifact, b.skipTests, b.insecureRegistries)),
}},
switch t {
case jib.JibMaven:
return cloudbuild.Build{
Steps: []*cloudbuild.BuildStep{{
Name: b.MavenImage,
Entrypoint: "sh",
Args: fixHome("mvn", jib.GenerateMavenArgs("build", tag, artifact.JibArtifact, b.skipTests, b.insecureRegistries)),
}},
}, nil
case jib.JibGradle:
return cloudbuild.Build{
Steps: []*cloudbuild.BuildStep{{
Name: b.GradleImage,
Entrypoint: "sh",
Args: fixHome("gradle", jib.GenerateGradleArgs("jib", tag, artifact.JibArtifact, b.skipTests, b.insecureRegistries)),
}},
}, nil
default:
return cloudbuild.Build{}, errors.New("skaffold can't determine Jib artifact type for Google Cloud Build")
}
}

Expand Down
Loading

0 comments on commit c0bf9af

Please sign in to comment.