|
| 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