Skip to content

Commit 39ba028

Browse files
committed
feat: accept deploy-specific environment variable data to DeploySite, DoDeploy
1 parent 7b1c75b commit 39ba028

File tree

4 files changed

+246
-12
lines changed

4 files changed

+246
-12
lines changed

go/models/deploy_environment_variable.go

Lines changed: 132 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/models/deploy_files.go

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/porcelain/deploy.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ const (
4949

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

52-
type uploadType int
53-
type pointerData struct {
54-
SHA string
55-
Size int64
56-
}
52+
type (
53+
uploadType int
54+
pointerData struct {
55+
SHA string
56+
Size int64
57+
}
58+
)
5759

5860
type DeployObserver interface {
5961
OnSetupWalk() error
@@ -74,6 +76,12 @@ type DeployWarner interface {
7476
OnWalkWarning(path, msg string)
7577
}
7678

79+
type DeployEnvironmentVariable struct {
80+
Key string
81+
Value string
82+
IsSecret bool
83+
}
84+
7785
// DeployOptions holds the option for creating a new deploy
7886
type DeployOptions struct {
7987
SiteID string
@@ -83,6 +91,7 @@ type DeployOptions struct {
8391
EdgeRedirectsDir string
8492
BuildDir string
8593
LargeMediaEnabled bool
94+
Environment []*models.DeployEnvironmentVariable
8695

8796
IsDraft bool
8897
SkipRetry bool
@@ -270,6 +279,10 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy *
270279
deployFiles.Functions = options.functions.Sums
271280
}
272281

282+
if len(options.Environment) > 0 {
283+
deployFiles.Environment = options.Environment
284+
}
285+
273286
if options.Observer != nil {
274287
if err := options.Observer.OnSuccessfulWalk(deployFiles); err != nil {
275288
return nil, err
@@ -763,7 +776,6 @@ func bundle(ctx context.Context, functionDir string, observer DeployObserver) (*
763776

764777
func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer DeployObserver) (*deployFiles, []*models.FunctionSchedule, map[string]models.FunctionConfig, error) {
765778
manifestBytes, err := ioutil.ReadAll(manifestFile)
766-
767779
if err != nil {
768780
return nil, nil, nil, err
769781
}
@@ -774,7 +786,6 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep
774786
var manifest functionsManifest
775787

776788
err = json.Unmarshal(manifestBytes, &manifest)
777-
778789
if err != nil {
779790
return nil, nil, nil, fmt.Errorf("malformed functions manifest file: %w", err)
780791
}
@@ -785,7 +796,6 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep
785796

786797
for _, function := range manifest.Functions {
787798
fileInfo, err := os.Stat(function.Path)
788-
789799
if err != nil {
790800
return nil, nil, nil, fmt.Errorf("manifest file specifies a function path that cannot be found: %s", function.Path)
791801
}
@@ -802,7 +812,6 @@ func bundleFromManifest(ctx context.Context, manifestFile *os.File, observer Dep
802812
Timeout: function.Timeout,
803813
}
804814
file, err := newFunctionFile(function.Path, fileInfo, runtime, &meta, observer)
805-
806815
if err != nil {
807816
return nil, nil, nil, err
808817
}
@@ -974,7 +983,7 @@ func jsFile(i os.FileInfo) bool {
974983
func goFile(filePath string, i os.FileInfo, observer DeployObserver) bool {
975984
warner, hasWarner := observer.(DeployWarner)
976985

977-
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
986+
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
978987
if hasWarner {
979988
warner.OnWalkWarning(filePath, "Go binary does not have executable permissions")
980989
}
@@ -1016,8 +1025,8 @@ func ignoreFile(rel string, ignoreInstallDirs bool) bool {
10161025
func createHeader(archive *zip.Writer, i os.FileInfo, runtime string) (io.Writer, error) {
10171026
if runtime == goRuntime || runtime == amazonLinux2 {
10181027
return archive.CreateHeader(&zip.FileHeader{
1019-
CreatorVersion: 3 << 8, // indicates Unix
1020-
ExternalAttrs: 0777 << 16, // -rwxrwxrwx file permissions
1028+
CreatorVersion: 3 << 8, // indicates Unix
1029+
ExternalAttrs: 0o777 << 16, // -rwxrwxrwx file permissions
10211030

10221031
// 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.
10231032
// adding in the function name as a comment ensures that every function ZIP is unique

swagger.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4146,6 +4146,28 @@ definitions:
41464146
type: array
41474147
items:
41484148
$ref: '#/definitions/functionSchedule'
4149+
deployEnvironmentVariable:
4150+
type: object
4151+
required:
4152+
- key
4153+
- value
4154+
- scopes
4155+
properties:
4156+
key:
4157+
type: string
4158+
value:
4159+
type: string
4160+
is_secret:
4161+
type: boolean
4162+
scopes:
4163+
type: array
4164+
items:
4165+
type: string
4166+
enum:
4167+
- builds
4168+
- functions
4169+
- runtime
4170+
- post-processing
41494171
deployFiles:
41504172
type: object
41514173
description: |
@@ -4154,6 +4176,8 @@ definitions:
41544176
2. As a zip file using one of these methods:
41554177
- Set Content-Type to 'application/zip' and send the zip file as the raw request body
41564178
- Include the zip file content in the 'zip' field of this JSON object with Content-Type 'application/json'
4179+
required:
4180+
- environment
41574181
properties:
41584182
files:
41594183
type: object
@@ -4186,6 +4210,27 @@ definitions:
41864210
type: string
41874211
framework_version:
41884212
type: string
4213+
environment:
4214+
description: |
4215+
A list of deploy-specific environment variable data. Data specified this way applies only
4216+
to this specific deploy and is merged into any existing environment variables set on the
4217+
account and site.
4218+
4219+
Deploy-specific environment variable data takes precedence over account and site
4220+
environment variable data: For example, a deploy-specific variable with the key `NODE_ENV`
4221+
will take priority over any existing site- and account-level environment variable data
4222+
with the key `NODE_ENV`.
4223+
4224+
Environment variable data may be provided at one of two times:
4225+
4226+
- When creating a new Deploy with deploy files (most common)
4227+
- When finalizing an existing Deploy with deploy files
4228+
4229+
Once set, environment variables for a specific deploy cannot be modified. Subsequent
4230+
attempts to modify environment variable data for a deploy will be ignored.
4231+
type: array
4232+
items:
4233+
$ref: '#/definitions/deployEnvironmentVariable'
41894234
pluginParams:
41904235
type: object
41914236
properties:

0 commit comments

Comments
 (0)