-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persistent volume caching for base images #383
Merged
sharifelgamal
merged 21 commits into
GoogleContainerTools:master
from
sharifelgamal:caching
Oct 11, 2018
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
fcfc2f4
comments
sharifelgamal 4db3991
Merge branch 'master' of github.com:GoogleCloudPlatform/kaniko into c…
sharifelgamal f12eadc
Merge branch 'master' of github.com:GoogleCloudPlatform/kaniko into c…
sharifelgamal e915460
Merge branch 'master' of github.com:GoogleCloudPlatform/kaniko into c…
sharifelgamal 8dd6d47
initial commit for persisent volume caching
sharifelgamal fc1d3e1
Merge branch 'master' of github.com:GoogleCloudPlatform/kaniko into c…
sharifelgamal 979092e
cache warmer works
sharifelgamal 1667b39
Merge branch 'master' of github.com:GoogleCloudPlatform/kaniko into c…
sharifelgamal ad4f604
general cleanup
sharifelgamal 69a760e
adding some debugging
sharifelgamal c44bd34
adding missing files
sharifelgamal 123d5f3
Fixing up cache retrieval and cleanup
sharifelgamal 88c6945
Merge branch 'master' of github.com:GoogleCloudPlatform/kaniko into c…
sharifelgamal 72e71ce
fix tests
sharifelgamal 78c2111
removing auth since we only cache public images
sharifelgamal b8ac1be
simplifying the caching logic
sharifelgamal 27888f3
fixing logic
sharifelgamal d158f70
adding volume cache to integration tests. remove auth from cache warm…
sharifelgamal 0a550f0
add building warmer to integration-test
sharifelgamal 47c8ff4
move sample yaml files to examples dir
sharifelgamal 78d4898
small test fix
sharifelgamal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
Copyright 2018 Google LLC | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/GoogleContainerTools/kaniko/pkg/cache" | ||
"github.com/GoogleContainerTools/kaniko/pkg/config" | ||
"github.com/GoogleContainerTools/kaniko/pkg/constants" | ||
"github.com/GoogleContainerTools/kaniko/pkg/util" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
opts = &config.WarmerOptions{} | ||
logLevel string | ||
) | ||
|
||
func init() { | ||
RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", constants.DefaultLogLevel, "Log level (debug, info, warn, error, fatal, panic") | ||
addKanikoOptionsFlags(RootCmd) | ||
addHiddenFlags(RootCmd) | ||
} | ||
|
||
var RootCmd = &cobra.Command{ | ||
Use: "cache warmer", | ||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
if err := util.ConfigureLogging(logLevel); err != nil { | ||
return err | ||
} | ||
if len(opts.Images) == 0 { | ||
return errors.New("You must select at least one image to cache") | ||
} | ||
return nil | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := cache.WarmCache(opts); err != nil { | ||
exit(errors.Wrap(err, "Failed warming cache")) | ||
} | ||
}, | ||
} | ||
|
||
// addKanikoOptionsFlags configures opts | ||
func addKanikoOptionsFlags(cmd *cobra.Command) { | ||
RootCmd.PersistentFlags().VarP(&opts.Images, "image", "i", "Image to cache. Set it repeatedly for multiple images.") | ||
RootCmd.PersistentFlags().StringVarP(&opts.CacheDir, "cache-dir", "c", "/cache", "Directory of the cache.") | ||
} | ||
|
||
// addHiddenFlags marks certain flags as hidden from the executor help text | ||
func addHiddenFlags(cmd *cobra.Command) { | ||
RootCmd.PersistentFlags().MarkHidden("azure-container-registry-config") | ||
} | ||
|
||
func exit(err error) { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright 2018 Google LLC | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/GoogleContainerTools/kaniko/cmd/warmer/cmd" | ||
) | ||
|
||
func main() { | ||
if err := cmd.RootCmd.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2018 Google, Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Builds the static Go image to execute in a Kubernetes job | ||
|
||
FROM golang:1.10 | ||
WORKDIR /go/src/github.com/GoogleContainerTools/kaniko | ||
COPY . . | ||
RUN make | ||
|
||
FROM scratch | ||
COPY --from=0 /go/src/github.com/GoogleContainerTools/kaniko/out/warmer /kaniko/warmer | ||
COPY files/ca-certificates.crt /kaniko/ssl/certs/ | ||
COPY files/config.json /kaniko/.docker/ | ||
ENV HOME /root | ||
ENV USER /root | ||
ENV PATH /usr/local/bin:/kaniko | ||
ENV SSL_CERT_DIR=/kaniko/ssl/certs | ||
ENV DOCKER_CONFIG /kaniko/.docker/ | ||
WORKDIR /workspace | ||
ENTRYPOINT ["/kaniko/warmer"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
kind: PersistentVolumeClaim | ||
apiVersion: v1 | ||
metadata: | ||
name: kaniko-cache-claim | ||
spec: | ||
storageClassName: manual | ||
accessModes: | ||
- ReadOnlyMany | ||
resources: | ||
requests: | ||
storage: 8Gi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
kind: PersistentVolume | ||
apiVersion: v1 | ||
metadata: | ||
name: kaniko-cache-volume | ||
labels: | ||
type: local | ||
spec: | ||
storageClassName: manual | ||
capacity: | ||
storage: 10Gi | ||
accessModes: | ||
- ReadOnlyMany | ||
hostPath: | ||
path: "/tmp/kaniko-cache" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: kaniko | ||
spec: | ||
containers: | ||
- name: kaniko | ||
image: gcr.io/kaniko-project/executor:latest | ||
args: ["--dockerfile=<dockerfile>", | ||
"--context=<context>", | ||
"--destination=<destination>", | ||
"--cache", | ||
"--cache-dir=/cache"] | ||
volumeMounts: | ||
- name: kaniko-secret | ||
mountPath: /secret | ||
- name: kaniko-cache | ||
mountPath: /cache | ||
env: | ||
- name: GOOGLE_APPLICATION_CREDENTIALS | ||
value: /secret/kaniko-secret.json | ||
restartPolicy: Never | ||
volumes: | ||
- name: kaniko-secret | ||
secret: | ||
secretName: kaniko-secret | ||
- name: kaniko-cache | ||
persistentVolumeClaim: | ||
claimName: kaniko-cache-claim | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: kaniko-warmer | ||
spec: | ||
containers: | ||
- name: kaniko-warmer | ||
image: gcr.io/kaniko-project/warmer:latest | ||
args: ["--cache-dir=/cache", | ||
"--image=gcr.io/google-appengine/debian9"] | ||
volumeMounts: | ||
- name: kaniko-secret | ||
mountPath: /secret | ||
- name: kaniko-cache | ||
mountPath: /cache | ||
env: | ||
- name: GOOGLE_APPLICATION_CREDENTIALS | ||
value: /secret/kaniko-secret.json | ||
restartPolicy: Never | ||
volumes: | ||
- name: kaniko-secret | ||
secret: | ||
secretName: kaniko-secret | ||
- name: kaniko-cache | ||
persistentVolumeClaim: | ||
claimName: kaniko-cache-claim | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we shouldn't need this if we return an error