github.com/coreos/mantle@v0.13.0/cmd/plume/fedora.go (about)

     1  // Copyright 2018 Red Hat Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package main
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"github.com/spf13/pflag"
    21  )
    22  
    23  var (
    24  	specComposeID   string
    25  	specEnv         string
    26  	specRespin      string
    27  	specImageType   string
    28  	specTimestamp   string
    29  	awsFedoraBoards = []string{
    30  		"x86_64",
    31  		"aarch64",
    32  	}
    33  	awsFedoraPartitions = []awsPartitionSpec{
    34  		awsPartitionSpec{
    35  			Name:         "AWS",
    36  			Profile:      "default",
    37  			Bucket:       "fedora-s3-bucket-fedimg",
    38  			BucketRegion: "us-east-1",
    39  			LaunchPermissions: []string{
    40  				"125523088429", // fedora production account
    41  			},
    42  			Regions: []string{
    43  				"ap-northeast-2",
    44  				"us-east-2",
    45  				"ap-southeast-1",
    46  				"ap-southeast-2",
    47  				"ap-south-1",
    48  				"eu-west-1",
    49  				"sa-east-1",
    50  				"us-east-1",
    51  				"us-west-2",
    52  				"us-west-1",
    53  				"eu-central-1",
    54  				"ap-northeast-1",
    55  				"ca-central-1",
    56  				"eu-west-2",
    57  				"eu-west-3",
    58  			},
    59  		},
    60  	}
    61  	awsFedoraUserPartitions = []awsPartitionSpec{
    62  		awsPartitionSpec{
    63  			Name:         "AWS",
    64  			Profile:      "default",
    65  			Bucket:       "fedora-s3-bucket-fedimg-test",
    66  			BucketRegion: "us-east-1",
    67  			LaunchPermissions: []string{
    68  				"013116697141", // fedora community dev test account
    69  			},
    70  			Regions: []string{
    71  				"us-east-2",
    72  				"us-east-1",
    73  			},
    74  		},
    75  	}
    76  
    77  	fedoraSpecs = map[string]channelSpec{
    78  		"rawhide": channelSpec{
    79  			BaseURL: "https://koji.fedoraproject.org/compose/rawhide",
    80  			Boards:  awsFedoraBoards,
    81  			AWS: awsSpec{
    82  				BaseName:        "Fedora",
    83  				BaseDescription: "Fedora AMI",
    84  				Prefix:          "fedora_{{.Env}}_ami_",
    85  				Image:           "Fedora-AtomicHost-{{.Version}}-{{.Timestamp}}.{{.Respin}}.{{.Arch}}.raw.xz",
    86  				Partitions:      awsFedoraPartitions,
    87  			},
    88  		},
    89  		"updates": channelSpec{
    90  			BaseURL: "https://koji.fedoraproject.org/compose/updates",
    91  			Boards:  awsFedoraBoards,
    92  			AWS: awsSpec{
    93  				BaseName:        "Fedora",
    94  				BaseDescription: "Fedora AMI",
    95  				Prefix:          "fedora_{{.Env}}_ami_",
    96  				Image:           "Fedora-AtomicHost-{{.Version}}-{{.Timestamp}}.{{.Respin}}.{{.Arch}}.raw.xz",
    97  				Partitions:      awsFedoraPartitions,
    98  			},
    99  		},
   100  		"branched": channelSpec{
   101  			BaseURL: "https://koji.fedoraproject.org/compose/branched",
   102  			Boards:  awsFedoraBoards,
   103  			AWS: awsSpec{
   104  				BaseName:        "Fedora",
   105  				BaseDescription: "Fedora AMI",
   106  				Prefix:          "fedora_{{.Env}}_ami_",
   107  				Image:           "Fedora-{{.ImageType}}-{{.Version}}-{{.Timestamp}}.n.{{.Respin}}.{{.Arch}}.raw.xz",
   108  				Partitions:      awsFedoraPartitions,
   109  			},
   110  		},
   111  		"cloud": channelSpec{
   112  			BaseURL: "https://koji.fedoraproject.org/compose/cloud",
   113  			Boards:  awsFedoraBoards,
   114  			AWS: awsSpec{
   115  				BaseName:        "Fedora",
   116  				BaseDescription: "Fedora AMI",
   117  				Prefix:          "fedora_{{.Env}}_ami_",
   118  				Image:           "Fedora-{{.ImageType}}-{{.Version}}-{{.Timestamp}}.{{.Respin}}.{{.Arch}}.raw.xz",
   119  				Partitions:      awsFedoraPartitions,
   120  			},
   121  		},
   122  		"user": channelSpec{
   123  			BaseURL: "https://koji.fedoraproject.org/compose/cloud",
   124  			Boards:  awsFedoraBoards,
   125  			AWS: awsSpec{
   126  				BaseName:        "Fedora",
   127  				BaseDescription: "Fedora AMI",
   128  				Prefix:          "fedora_{{.Env}}_ami_",
   129  				Image:           "Fedora-{{.ImageType}}-{{.Version}}-{{.Timestamp}}.{{.Respin}}.{{.Arch}}.raw.xz",
   130  				Partitions:      awsFedoraUserPartitions,
   131  			},
   132  		},
   133  	}
   134  )
   135  
   136  func AddFedoraSpecFlags(flags *pflag.FlagSet) {
   137  	flags.StringVarP(&specEnv, "environment", "E", "prod", "instance environment")
   138  	flags.StringVarP(&specImageType, "image-type", "I", "Cloud-Base", "type of image")
   139  	flags.StringVarP(&specTimestamp, "timestamp", "T", "", "compose timestamp")
   140  	flags.StringVarP(&specRespin, "respin", "R", "0", "compose respin")
   141  	flags.StringVarP(&specComposeID, "compose-id", "O", "", "compose id")
   142  }
   143  
   144  func ChannelFedoraSpec() (channelSpec, error) {
   145  	if specComposeID == "" {
   146  		plog.Fatal("--compose-id is required")
   147  	}
   148  	if specTimestamp == "" {
   149  		plog.Fatal("--timestamp is required")
   150  	}
   151  	if specVersion == "" {
   152  		plog.Fatal("--version is required")
   153  	}
   154  	if len(specBoard) == 0 || specBoard == "amd64-usr" {
   155  		specBoard = "x86_64"
   156  	}
   157  
   158  	spec, ok := fedoraSpecs[specChannel]
   159  	if !ok {
   160  		return channelSpec{}, fmt.Errorf("Unknown channel: %q", specChannel)
   161  	}
   162  
   163  	boardOk := false
   164  	for _, board := range spec.Boards {
   165  		if specBoard == board {
   166  			boardOk = true
   167  			break
   168  		}
   169  	}
   170  	if !boardOk {
   171  		plog.Fatalf("Unknown board %q for channel %q", specBoard, specChannel)
   172  	}
   173  
   174  	return spec, nil
   175  }