-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persistent volume caching for base images (#383)
* comments * initial commit for persisent volume caching * cache warmer works * general cleanup * adding some debugging * adding missing files * Fixing up cache retrieval and cleanup * fix tests * removing auth since we only cache public images * simplifying the caching logic * fixing logic * adding volume cache to integration tests. remove auth from cache warmer image. * add building warmer to integration-test * move sample yaml files to examples dir * small test fix
- Loading branch information
1 parent
03db09e
commit effac9d
Showing
18 changed files
with
389 additions
and
6 deletions.
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.