This repository has been archived by the owner on Feb 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 887
/
fetch.go
134 lines (114 loc) · 3.63 KB
/
fetch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2014 The rkt Authors
//
// 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 (
"runtime"
"github.com/appc/spec/schema/types"
"github.com/coreos/rkt/common/apps"
"github.com/coreos/rkt/rkt/image"
"github.com/coreos/rkt/store/imagestore"
"github.com/coreos/rkt/store/treestore"
"github.com/spf13/cobra"
)
const (
defaultOS = runtime.GOOS
defaultArch = runtime.GOARCH
)
var (
cmdFetch = &cobra.Command{
Use: "fetch IMAGE_URL...",
Short: "Fetch image(s) and store them in the local store",
Long: `Locates and downloads remote ACIs and their attached signatures.
If the ACI is available in the local store, the image will not be fetched
again.`,
Run: runWrapper(runFetch),
}
flagFullHash bool
)
func init() {
// Disable interspersed flags to stop parsing after the first non flag
// argument. All the subsequent parsing will be done by parseApps.
// This is needed to correctly handle multiple IMAGE --signature=sigfile options
cmdFetch.Flags().SetInterspersed(false)
cmdFetch.Flags().Var((*appAsc)(&rktApps), "signature", "local signature file to use in validating the preceding image")
cmdFetch.Flags().BoolVar(&flagStoreOnly, "store-only", false, "use only available images in the store (do not discover or download from remote URLs)")
cmdFetch.Flags().BoolVar(&flagNoStore, "no-store", false, "fetch images ignoring the local store")
cmdFetch.Flags().BoolVar(&flagFullHash, "full", false, "print the full image hash after fetching")
cmdRkt.AddCommand(cmdFetch)
// Hide image fetch option in command list
cmdImageFetch := *cmdFetch
cmdImageFetch.Hidden = true
cmdImage.AddCommand(&cmdImageFetch)
}
func runFetch(cmd *cobra.Command, args []string) (exit int) {
if err := parseApps(&rktApps, args, cmd.Flags(), false); err != nil {
stderr.PrintE("unable to parse arguments", err)
return 254
}
if rktApps.Count() < 1 {
stderr.Print("must provide at least one image")
return 254
}
if flagStoreOnly && flagNoStore {
stderr.Print("both --store-only and --no-store specified")
return 254
}
s, err := imagestore.NewStore(storeDir())
if err != nil {
stderr.PrintE("cannot open store", err)
return 254
}
ts, err := treestore.NewStore(treeStoreDir(), s)
if err != nil {
stderr.PrintE("cannot open treestore", err)
return 254
}
ks := getKeystore()
config, err := getConfig()
if err != nil {
stderr.PrintE("cannot get configuration", err)
return 254
}
ft := &image.Fetcher{
S: s,
Ts: ts,
Ks: ks,
Headers: config.AuthPerHost,
DockerAuth: config.DockerCredentialsPerRegistry,
InsecureFlags: globalFlags.InsecureFlags,
Debug: globalFlags.Debug,
TrustKeysFromHTTPS: globalFlags.TrustKeysFromHTTPS,
StoreOnly: flagStoreOnly,
NoStore: flagNoStore,
WithDeps: true,
}
err = ft.FetchImages(&rktApps)
if err != nil {
stderr.Error(err)
return 254
}
err = rktApps.Walk(func(app *apps.App) error {
hash := app.ImageID.String()
if !flagFullHash {
hash = types.ShortHash(hash)
}
stdout.Print(hash)
return nil
})
if err != nil {
stderr.Error(err)
return 254
}
return
}