github.com/jonsyu1/godel@v0.0.0-20171017211503-64567a0cf169/apps/distgo/params/dist.go (about) 1 // Copyright 2016 Palantir Technologies, 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 params 16 17 import ( 18 "github.com/palantir/pkg/matcher" 19 20 "github.com/palantir/godel/apps/distgo/pkg/osarch" 21 ) 22 23 type Dist struct { 24 // OutputDir is the directory to which the distribution is written. 25 OutputDir string 26 27 // InputDir is the path (from the project root) to a directory whose contents will be copied into the output 28 // distribution directory at the beginning of the "dist" command. Can be used to include static resources and 29 // other files required in a distribution. 30 InputDir string 31 32 // InputProducts is a slice of the names of products in the project (other than the current one) whose binaries 33 // are required for the "dist" task. The "dist" task will ensure that the outputs of "build" exist for all of 34 // the products specified in this slice (and will build the products as part of the task if necessary) and make 35 // the outputs available to the "dist" script as environment variables. Note that the "dist" task only 36 // guarantees that the products will be built and their locations will be available in the environment variables 37 // provided to the script -- it is the responsibility of the user to write logic in the dist script to copy the 38 // generated binaries. 39 InputProducts []string 40 41 // Script is the content of a script that is written to file a file and run after the initial distribution 42 // process but before the artifact generation process. The contents of this value are written to a file with a 43 // header `#!/bin/bash` with the contents of the global `dist-script-include` prepended and executed. The script 44 // process inherits the environment variables of the Go process and also has the following environment variables 45 // defined: 46 // 47 // DIST_DIR: the absolute path to the root directory of the distribution created for the current product 48 // PROJECT_DIR: the root directory of project 49 // PRODUCT: product name 50 // VERSION: product version 51 // IS_SNAPSHOT: 1 if the version contains a git hash as part of the string, 0 otherwise 52 Script string 53 54 // Info specifies the type of the distribution to be built and configuration for it. If unspecified, defaults to 55 // a DistInfo of type SLSDistType. 56 Info DistInfo 57 58 // Publish is the configuration for the "publish" task. 59 Publish Publish 60 } 61 62 type DistInfoType string 63 64 const ( 65 SLSDistType DistInfoType = "sls" // distribution that uses the Standard Layout Specification 66 BinDistType DistInfoType = "bin" // distribution that includes all of the binaries for a product 67 RPMDistType DistInfoType = "rpm" // RPM distribution 68 OSArchBinDistType DistInfoType = "os-arch-bin" // distribution that consists of the binaries for a specific OS/Architecture 69 ManualDistType DistInfoType = "manual" // distribution that consists of a distribution whose output is created by the distribution script 70 ) 71 72 type DistInfo interface { 73 Type() DistInfoType 74 } 75 76 type ManualDistInfo struct { 77 // Extension is the extension used by the target output generated by the dist script: for example, "tgz", 78 // "zip", etc. Extension is used to locate the output generated by the dist script. The output should be a file 79 // of the form "{{product-name}}-{{version}}.{{Extension}}". If Extension is empty, it is assumed that the 80 // output has no extension and is of the form "{{product-name}}-{{version}}". 81 Extension string 82 } 83 84 func (i *ManualDistInfo) Type() DistInfoType { 85 return ManualDistType 86 } 87 88 type OSArchsBinDistInfo struct { 89 // OSArchs specifies the GOOS and GOARCH pairs for which TGZ distributions are created. If blank, defaults to 90 // the GOOS and GOARCH of the host system at runtime. 91 OSArchs []osarch.OSArch 92 } 93 94 func (i *OSArchsBinDistInfo) Type() DistInfoType { 95 return OSArchBinDistType 96 } 97 98 type BinDistInfo struct { 99 // OmitInitSh specifies whether or not the distribution should omit the auto-generated "init.sh" invocation 100 // script. If true, the "init.sh" script will not be generated and included in the output distribution. 101 OmitInitSh bool 102 103 // InitShTemplateFile is the relative path to the template that should be used to generate the "init.sh" script. 104 // If the value is absent, the default template will be used. 105 InitShTemplateFile string 106 } 107 108 func (i *BinDistInfo) Type() DistInfoType { 109 return BinDistType 110 } 111 112 type SLSDistInfo struct { 113 // InitShTemplateFile is the path to a template file that is used as the basis for the init.sh script of the 114 // distribution. The path is relative to the project root directory. The contents of the file is processed using 115 // Go templates and is provided with a distgo.ProductBuildSpec struct. If omitted, the default init.sh script 116 // is used. 117 InitShTemplateFile string 118 119 // ManifestTemplateFile is the path to a template file that is used as the basis for the manifest.yml file of 120 // the distribution. The path is relative to the project root directory. The contents of the file is processed 121 // using Go templates and is provided with a distgo.ProductBuildSpec struct. 122 ManifestTemplateFile string 123 124 // ServiceArgs is the string provided as the service arguments for the default init.sh file generated for the distribution. 125 ServiceArgs string 126 127 // ProductType is the SLS product type for the distribution. 128 ProductType string 129 130 // ManifestExtensions contain the SLS manifest extensions for the distribution. 131 ManifestExtensions map[string]interface{} 132 133 // Reloadable will enable the `init.sh reload` command which sends SIGHUP to the process. 134 Reloadable bool 135 136 // YMLValidationExclude specifies a matcher used to specify YML files or paths that should not be validated as 137 // part of creating the distribution. By default, the SLS distribution task verifies that all "*.yml" and 138 // "*.yaml" files in the distribution are syntactically valid. If a distribution is known to ship with YML files 139 // that are not valid YML, this parameter can be used to exclude those files from validation. 140 YMLValidationExclude matcher.Matcher 141 } 142 143 func (i *SLSDistInfo) Type() DistInfoType { 144 return SLSDistType 145 } 146 147 type RPMDistInfo struct { 148 // Release is the release identifier that forms part of the name/version/release/architecture quadruplet 149 // uniquely identifying the RPM package. Default is "1". 150 Release string 151 // ConfigFiles is a slice of absolute paths within the RPM that correspond to configuration files. RPM 152 // identifies these as mutable. Default is no files. 153 ConfigFiles []string 154 // BeforeInstallScript is the content of shell script to run before this RPM is installed. Optional. 155 BeforeInstallScript string 156 // AfterInstallScript is the content of shell script to run immediately after this RPM is installed. Optional. 157 AfterInstallScript string 158 // AfterRemoveScript is the content of shell script to clean up after this RPM is removed. Optional. 159 AfterRemoveScript string 160 } 161 162 func (i *RPMDistInfo) Type() DistInfoType { 163 return RPMDistType 164 }