Skip to content

Commit fd02c95

Browse files
authored
feat: feature flag guard provision version to allow rolling update (#1399)
1 parent ad5bb9b commit fd02c95

14 files changed

Lines changed: 53 additions & 9 deletions

File tree

packages/api/internal/middleware/launchdarkly.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func createLaunchDarklyTeamContext(c *gin.Context) (ldcontext.Context, bool) {
4646

4747
var contexts []ldcontext.Context
4848
if team != nil {
49-
contexts = append(contexts, featureflags.TeamContext(team.ID.String(), team.Name))
49+
contexts = append(contexts, featureflags.TeamContextWithName(team.ID.String(), team.Name))
5050
if clusterID := team.ClusterID; clusterID != nil {
5151
contexts = append(contexts, featureflags.ClusterContext(clusterID.String()))
5252
}

packages/orchestrator/benchmark_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ func BenchmarkBaseImageLaunch(b *testing.B) {
232232

233233
builder := build.NewBuilder(
234234
logger,
235+
featureFlags,
235236
sandboxFactory,
236237
persistenceTemplate,
237238
persistenceBuild,

packages/orchestrator/cmd/build-template/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ func buildTemplate(
190190

191191
builder := build.NewBuilder(
192192
logger,
193+
featureFlags,
193194
sandboxFactory,
194195
persistenceTemplate,
195196
persistenceBuild,

packages/orchestrator/internal/template/build/builder.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/e2b-dev/infra/packages/orchestrator/internal/template/constants"
3333
artifactsregistry "github.com/e2b-dev/infra/packages/shared/pkg/artifacts-registry"
3434
"github.com/e2b-dev/infra/packages/shared/pkg/dockerhub"
35+
featureflags "github.com/e2b-dev/infra/packages/shared/pkg/feature-flags"
3536
"github.com/e2b-dev/infra/packages/shared/pkg/storage"
3637
"github.com/e2b-dev/infra/packages/shared/pkg/storage/header"
3738
"github.com/e2b-dev/infra/packages/shared/pkg/telemetry"
@@ -55,10 +56,12 @@ type Builder struct {
5556
sandboxes *sandbox.Map
5657
templateCache *sbxtemplate.Cache
5758
metrics *metrics.BuildMetrics
59+
featureFlags *featureflags.Client
5860
}
5961

6062
func NewBuilder(
6163
logger *zap.Logger,
64+
featureFlags *featureflags.Client,
6265
sandboxFactory *sandbox.Factory,
6366
templateStorage storage.StorageProvider,
6467
buildStorage storage.StorageProvider,
@@ -71,6 +74,7 @@ func NewBuilder(
7174
) *Builder {
7275
return &Builder{
7376
logger: logger,
77+
featureFlags: featureFlags,
7478
sandboxFactory: sandboxFactory,
7579
templateStorage: templateStorage,
7680
buildStorage: buildStorage,
@@ -217,6 +221,7 @@ func runBuild(
217221

218222
baseBuilder := base.New(
219223
bc,
224+
builder.featureFlags,
220225
builder.logger,
221226
builder.proxy,
222227
builder.templateStorage,

packages/orchestrator/internal/template/build/phases/base/builder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/e2b-dev/infra/packages/shared/pkg"
3131
artifactsregistry "github.com/e2b-dev/infra/packages/shared/pkg/artifacts-registry"
3232
"github.com/e2b-dev/infra/packages/shared/pkg/dockerhub"
33+
featureflags "github.com/e2b-dev/infra/packages/shared/pkg/feature-flags"
3334
"github.com/e2b-dev/infra/packages/shared/pkg/id"
3435
"github.com/e2b-dev/infra/packages/shared/pkg/storage"
3536
"github.com/e2b-dev/infra/packages/shared/pkg/utils"
@@ -61,6 +62,7 @@ type BaseBuilder struct {
6162
templateStorage storage.StorageProvider
6263
artifactRegistry artifactsregistry.ArtifactsRegistry
6364
dockerhubRepository dockerhub.RemoteRepository
65+
featureFlags *featureflags.Client
6466

6567
layerExecutor *layer.LayerExecutor
6668
index cache.Index
@@ -69,6 +71,7 @@ type BaseBuilder struct {
6971

7072
func New(
7173
buildContext buildcontext.BuildContext,
74+
featureFlags *featureflags.Client,
7275
logger *zap.Logger,
7376
proxy *proxy.SandboxProxy,
7477
templateStorage storage.StorageProvider,
@@ -89,6 +92,7 @@ func New(
8992
artifactRegistry: artifactRegistry,
9093
dockerhubRepository: dockerhubRepository,
9194
sandboxFactory: sandboxFactory,
95+
featureFlags: featureFlags,
9296

9397
layerExecutor: layerExecutor,
9498
index: index,

packages/orchestrator/internal/template/build/phases/base/hash.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package base
22

33
import (
4+
"context"
45
"fmt"
56
"strconv"
67

78
"github.com/e2b-dev/infra/packages/orchestrator/internal/template/build/phases"
89
"github.com/e2b-dev/infra/packages/orchestrator/internal/template/build/storage/cache"
10+
featureflags "github.com/e2b-dev/infra/packages/shared/pkg/feature-flags"
911
)
1012

11-
func (bb *BaseBuilder) Hash(_ phases.LayerResult) (string, error) {
13+
func (bb *BaseBuilder) Hash(ctx context.Context, _ phases.LayerResult) (string, error) {
1214
var baseSource string
1315
if bb.Config.FromTemplate != nil {
1416
// When building from template, use the base template metadata
@@ -23,9 +25,20 @@ func (bb *BaseBuilder) Hash(_ phases.LayerResult) (string, error) {
2325
baseSource = bb.Config.FromImage
2426
}
2527

28+
provisionVersion := provisionScriptFile
29+
if val, err := bb.featureFlags.IntFlag(
30+
ctx,
31+
featureflags.BuildProvisionVersion,
32+
featureflags.TemplateContext(bb.Config.TemplateID),
33+
featureflags.TeamContext(bb.Config.TeamID),
34+
// for dev environments (fallback value), use the provision script hash
35+
); val != featureflags.BuildProvisionVersion.Fallback() && err == nil {
36+
provisionVersion = strconv.FormatInt(int64(val), 10)
37+
}
38+
2639
return cache.HashKeys(
2740
bb.index.Version(),
28-
provisionScriptFile,
41+
provisionVersion,
2942
strconv.FormatInt(bb.Config.DiskSizeMB, 10),
3043
baseSource,
3144
), nil

packages/orchestrator/internal/template/build/phases/finalize/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (ppb *PostProcessingBuilder) Metadata() phases.PhaseMeta {
7575
}
7676
}
7777

78-
func (ppb *PostProcessingBuilder) Hash(sourceLayer phases.LayerResult) (string, error) {
78+
func (ppb *PostProcessingBuilder) Hash(_ context.Context, sourceLayer phases.LayerResult) (string, error) {
7979
return cache.HashKeys(sourceLayer.Hash, "config-run-cmd"), nil
8080
}
8181

packages/orchestrator/internal/template/build/phases/phase.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type BuilderPhase interface {
3131
String(ctx context.Context) (string, error)
3232
Metadata() PhaseMeta
3333

34-
Hash(sourceLayer LayerResult) (string, error)
34+
Hash(ctx context.Context, sourceLayer LayerResult) (string, error)
3535
Layer(ctx context.Context, sourceLayer LayerResult, hash string) (LayerResult, error)
3636
Build(ctx context.Context, userLogger *zap.Logger, prefix string, sourceLayer LayerResult, currentLayer LayerResult) (LayerResult, error)
3737
}
@@ -83,7 +83,7 @@ func Run(
8383
)
8484

8585
phaseStartTime := time.Now()
86-
hash, err := builder.Hash(sourceLayer)
86+
hash, err := builder.Hash(ctx, sourceLayer)
8787
if err != nil {
8888
return LayerResult{}, fmt.Errorf("getting hash: %w", err)
8989
}

packages/orchestrator/internal/template/build/phases/steps/hash.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package steps
22

33
import (
4+
"context"
45
"strings"
56

67
"github.com/e2b-dev/infra/packages/orchestrator/internal/template/build/phases"
78
"github.com/e2b-dev/infra/packages/orchestrator/internal/template/build/storage/cache"
89
"github.com/e2b-dev/infra/packages/shared/pkg/utils"
910
)
1011

11-
func (sb *StepBuilder) Hash(sourceLayer phases.LayerResult) (string, error) {
12+
func (sb *StepBuilder) Hash(_ context.Context, sourceLayer phases.LayerResult) (string, error) {
1213
return cache.HashKeys(
1314
sourceLayer.Hash,
1415
sb.step.GetType(),

packages/orchestrator/internal/template/build/phases/user/hash.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package user
22

33
import (
4+
"context"
5+
46
"github.com/e2b-dev/infra/packages/orchestrator/internal/template/build/phases"
57
"github.com/e2b-dev/infra/packages/orchestrator/internal/template/build/storage/cache"
68
)
79

810
const prefix = "DEFAULT USER"
911

10-
func (ub *UserBuilder) Hash(sourceLayer phases.LayerResult) (string, error) {
12+
func (ub *UserBuilder) Hash(_ context.Context, sourceLayer phases.LayerResult) (string, error) {
1113
return cache.HashKeys(
1214
sourceLayer.Hash,
1315
prefix,

0 commit comments

Comments
 (0)