Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions go/models/deploy_environment_variable.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions go/models/deploy_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 21 additions & 12 deletions go/porcelain/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ const (

var installDirs = []string{"node_modules/", "bower_components/"}

type uploadType int
type pointerData struct {
SHA string
Size int64
}
type (
uploadType int
pointerData struct {
SHA string
Size int64
}
)

type DeployObserver interface {
OnSetupWalk() error
Expand All @@ -74,6 +76,12 @@ type DeployWarner interface {
OnWalkWarning(path, msg string)
}

type DeployEnvironmentVariable struct {
Key string
Value string
IsSecret bool
}

// DeployOptions holds the option for creating a new deploy
type DeployOptions struct {
SiteID string
Expand All @@ -83,6 +91,7 @@ type DeployOptions struct {
EdgeRedirectsDir string
BuildDir string
LargeMediaEnabled bool
Environment []*models.DeployEnvironmentVariable

IsDraft bool
SkipRetry bool
Expand Down Expand Up @@ -270,6 +279,10 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy *
deployFiles.Functions = options.functions.Sums
}

if len(options.Environment) > 0 {
deployFiles.Environment = options.Environment
}

if options.Observer != nil {
if err := options.Observer.OnSuccessfulWalk(deployFiles); err != nil {
return nil, err
Expand Down Expand Up @@ -763,7 +776,6 @@ func bundle(ctx context.Context, functionDir string, observer DeployObserver) (*

func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer DeployObserver) (*deployFiles, []*models.FunctionSchedule, map[string]models.FunctionConfig, error) {
manifestBytes, err := ioutil.ReadAll(manifestFile)

if err != nil {
return nil, nil, nil, err
}
Expand All @@ -774,7 +786,6 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep
var manifest functionsManifest

err = json.Unmarshal(manifestBytes, &manifest)

if err != nil {
return nil, nil, nil, fmt.Errorf("malformed functions manifest file: %w", err)
}
Expand All @@ -785,7 +796,6 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep

for _, function := range manifest.Functions {
fileInfo, err := os.Stat(function.Path)

if err != nil {
return nil, nil, nil, fmt.Errorf("manifest file specifies a function path that cannot be found: %s", function.Path)
}
Expand All @@ -802,7 +812,6 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep
Timeout: function.Timeout,
}
file, err := newFunctionFile(function.Path, fileInfo, runtime, &meta, observer)

if err != nil {
return nil, nil, nil, err
}
Expand Down Expand Up @@ -974,7 +983,7 @@ func jsFile(i os.FileInfo) bool {
func goFile(filePath string, i os.FileInfo, observer DeployObserver) bool {
warner, hasWarner := observer.(DeployWarner)

if m := i.Mode(); m&0111 == 0 && runtime.GOOS != "windows" { // check if it's an executable file. skip on windows, since it doesn't have that mode
if m := i.Mode(); m&0o111 == 0 && runtime.GOOS != "windows" { // check if it's an executable file. skip on windows, since it doesn't have that mode
if hasWarner {
warner.OnWalkWarning(filePath, "Go binary does not have executable permissions")
}
Expand Down Expand Up @@ -1016,8 +1025,8 @@ func ignoreFile(rel string, ignoreInstallDirs bool) bool {
func createHeader(archive *zip.Writer, i os.FileInfo, runtime string) (io.Writer, error) {
if runtime == goRuntime || runtime == amazonLinux2 {
return archive.CreateHeader(&zip.FileHeader{
CreatorVersion: 3 << 8, // indicates Unix
ExternalAttrs: 0777 << 16, // -rwxrwxrwx file permissions
CreatorVersion: 3 << 8, // indicates Unix
ExternalAttrs: 0o777 << 16, // -rwxrwxrwx file permissions

// we need to make sure we don't have two ZIP files with the exact same contents - otherwise, our upload deduplication mechanism will do weird things.
// adding in the function name as a comment ensures that every function ZIP is unique
Expand Down
43 changes: 43 additions & 0 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4146,6 +4146,28 @@ definitions:
type: array
items:
$ref: '#/definitions/functionSchedule'
deployEnvironmentVariable:
type: object
required:
- key
- value
- scopes
properties:
key:
type: string
value:
type: string
is_secret:
type: boolean
scopes:
type: array
items:
type: string
enum:
- builds
- functions
- runtime
- post-processing
deployFiles:
type: object
description: |
Expand Down Expand Up @@ -4186,6 +4208,27 @@ definitions:
type: string
framework_version:
type: string
environment:
description: |
A list of deploy-specific environment variable data. Data specified this way applies only
to this specific deploy and is merged into any existing environment variables set on the
account and site.

Deploy-specific environment variable data takes precedence over account and site
environment variable data: For example, a deploy-specific variable with the key `NODE_ENV`
will take priority over any existing site- and account-level environment variable data
with the key `NODE_ENV`.

Environment variable data may be provided at one of two times:

- When creating a new Deploy with deploy files (most common)
- When finalizing an existing Deploy with deploy files

Once set, environment variables for a specific deploy cannot be modified. Subsequent
attempts to modify environment variable data for a deploy will be ignored.
type: array
items:
$ref: '#/definitions/deployEnvironmentVariable'
pluginParams:
type: object
properties:
Expand Down
Loading