Skip to content

Commit 263902a

Browse files
config validate should error when using deprecated images (#667)
1 parent 226bb7f commit 263902a

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

cmd/config.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type configOptions struct {
2626
// Path to the config.yml file to operate on.
2727
// Used to for compatibility with `circleci config validate --path`
2828
var configPath string
29+
var ignoreDeprecatedImages bool // should we ignore deprecated images warning
2930

3031
var configAnnotations = map[string]string{
3132
"<path>": "The path to your config (use \"-\" for STDIN)",
@@ -71,6 +72,7 @@ func newConfigCommand(config *settings.Config) *cobra.Command {
7172
}
7273
validateCommand.Annotations["<path>"] = configAnnotations["<path>"]
7374
validateCommand.PersistentFlags().StringVarP(&configPath, "config", "c", ".circleci/config.yml", "path to config file")
75+
validateCommand.PersistentFlags().BoolVar(&ignoreDeprecatedImages, "ignore-deprecated-images", false, "ignores the deprecated images error")
7476
if err := validateCommand.PersistentFlags().MarkHidden("config"); err != nil {
7577
panic(err)
7678
}
@@ -132,11 +134,21 @@ func validateConfig(opts configOptions, flags *pflag.FlagSet) error {
132134

133135
orgSlug, _ := flags.GetString("org-slug")
134136

135-
_, err := api.ConfigQuery(opts.cl, path, orgSlug, nil, pipeline.LocalPipelineValues())
137+
response, err := api.ConfigQuery(opts.cl, path, orgSlug, nil, pipeline.LocalPipelineValues())
136138
if err != nil {
137139
return err
138140
}
139141

142+
// check if a deprecated Linux VM image is being used
143+
// link here to blog post when available
144+
// returns an error if a deprecated image is used
145+
if !ignoreDeprecatedImages {
146+
err := deprecatedImageCheck(response)
147+
if err != nil {
148+
return err
149+
}
150+
}
151+
140152
if path == "-" {
141153
fmt.Printf("Config input is valid.\n")
142154
} else {

cmd/deprecated-images.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package cmd
2+
3+
import (
4+
"github.com/CircleCI-Public/circleci-cli/api"
5+
6+
"github.com/pkg/errors"
7+
"gopkg.in/yaml.v3"
8+
)
9+
10+
// CircleCI Linux VM images that will be permanently removed on May 31st.
11+
var deprecatedImages = []string{
12+
"circleci/classic:201710-01",
13+
"circleci/classic:201703-01",
14+
"circleci/classic:201707-01",
15+
"circleci/classic:201708-01",
16+
"circleci/classic:201709-01",
17+
"circleci/classic:201710-02",
18+
"circleci/classic:201711-01",
19+
"circleci/classic",
20+
"circleci/classic:latest",
21+
"circleci/classic:edge",
22+
"circleci/classic:201808-01",
23+
"ubuntu-1604:201903-01",
24+
"ubuntu-1604:202004-01",
25+
"ubuntu-1604:202007-01",
26+
"ubuntu-1604:202010-01",
27+
"ubuntu-1604:202101-01",
28+
"ubuntu-1604:202104-01",
29+
}
30+
31+
// Simplified Config -> job Structure for an image
32+
33+
type job struct {
34+
Machine interface{} `yaml:"machine"`
35+
}
36+
37+
// Simplified Config Structure for an image
38+
type processedConfig struct {
39+
Jobs map[string]job `yaml:"jobs"`
40+
}
41+
42+
// Processes the config down to v2.0, then checks image used against the block list
43+
func deprecatedImageCheck(response *api.ConfigResponse) error {
44+
45+
aConfig := processedConfig{}
46+
err := yaml.Unmarshal([]byte(response.OutputYaml), &aConfig)
47+
if err != nil {
48+
return err
49+
}
50+
51+
// check each job
52+
for key := range aConfig.Jobs {
53+
54+
switch aConfig.Jobs[key].Machine.(type) {
55+
case bool, nil:
56+
// using machine true
57+
continue
58+
}
59+
60+
image := aConfig.Jobs[key].Machine.(map[string]interface{})["image"]
61+
62+
// using the `docker`/`xcode` executors
63+
if image == nil {
64+
continue
65+
}
66+
67+
for _, v := range deprecatedImages {
68+
if image.(string) == v {
69+
return errors.New("The config is using a deprecated Linux VM image (" + v + "). Please see https://circleci.com/blog/ubuntu-14-16-image-deprecation/. This error can be ignored by using the '--ignore-deprecated-images' flag.")
70+
}
71+
}
72+
}
73+
74+
return nil
75+
}

0 commit comments

Comments
 (0)