Skip to content
Closed
Show file tree
Hide file tree
Changes from 10 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ tests/periodic-test/build-template/e2b.toml
.air
go.work.sum
.infisical.json
.vscode/mise-tools
.vscode/mise-tools
/packages/fc-kernels
18 changes: 12 additions & 6 deletions DEV-LOCAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
> Note: Linux is required for developing on bare metal. This is a work in progress. Not everything will function as expected.

1. `sudo modprobe nbd nbds_max=64`
2. `make local-infra`: runs clickhouse, grafana, loki, memcached, mimir, otel, postgres, redis, tempo
3. `cd packages/db && make migrate-local` initialize the database
4. `cd packages/local-dev && go run seed-local-database.go` generate user, team, and token for local development
5. `cd packages/api && make run-local` run the api locally
6. `cd packages/orchestrator && make build-debug && sudo make run-local` run the orchestrator and template-manager locally.
7. `cd packages/client-proxy && make run-local` run the client-proxy locally.
2. `echo always | sudo tee /sys/kernel/mm/transparent_hugepage/enabled` enable huge pages
3. `sudo sysctl -w vm.nr_hugepages=2048` enable huge pages
4. `make download-public-kernels` download linux kernels
5. `make local-infra` runs clickhouse, grafana, loki, memcached, mimir, otel, postgres, redis, tempo
6. `cd packages/db && make migrate-local` initialize the database
7. `cd packages/envd && make build-debug` create the envd that will be embedded in templates
8. `cd packages/fc-versions && make build` build the firecracker versions
9. `cd packages/local-dev && go run seed-local-database.go` generate user, team, and token for local development
10. `cd packages/api && make run-local` run the api locally
11. `cd packages/orchestrator && make run-local` run the orchestrator and template-manager locally.
12. `cd packages/client-proxy && make run-local` run the client-proxy locally.
13. `cd packages/shared/script && make local-build-base-template` instructs orchestrator to create the 'base' template

# Services
- grafana: http://localhost:53000)
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ copy-public-builds:
gsutil cp -r gs://e2b-prod-public-builds/kernels/* gs://$(GCP_PROJECT_ID)-fc-kernels/
gsutil cp -r gs://e2b-prod-public-builds/firecrackers/* gs://$(GCP_PROJECT_ID)-fc-versions/

.PHONY: download-public-kernels
download-public-kernels:
mkdir -p ./packages/fc-kernels
gsutil cp -r gs://e2b-prod-public-builds/kernels/* ./packages/fc-kernels/

.PHONY: generate
generate: generate/api generate/orchestrator generate/client-proxy generate/envd generate/db generate/shared generate-tests generate-mocks
generate/%:
Expand Down
6 changes: 2 additions & 4 deletions packages/api/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ OTEL_COLLECTOR_GRPC_ENDPOINT=localhost:4317
POSTGRES_CONNECTION_STRING=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable
REDIS_URL=localhost:6379
SANDBOX_ACCESS_TOKEN_HASH_SEED=--sandbox-access-token-hash-seed--
SD_ORCHESTRATOR_PROVIDER=STATIC
SD_ORCHESTRATOR_STATIC=127.0.0.1
SD_EDGE_PROVIDER=STATIC
SD_EDGE_STATIC=127.0.0.1
LOCAL_CLUSTER_ENDPOINT=localhost:3001
LOCAL_CLUSTER_TOKEN=--edge-secret--
2 changes: 0 additions & 2 deletions packages/api/internal/auth/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ func (a *commonAuthenticator[T]) Authenticate(ctx context.Context, input *openap
return fmt.Errorf("%s %w", a.errorMessage, err)
}

telemetry.ReportEvent(ctx, "api key extracted")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was spamming me locally, and seemed useless. Happy to bring it back if it's useful though.


// If the API key is valid, we will get a result back
result, validationError := a.validationFunction(ctx, headerKey)
if validationError != nil {
Expand Down
6 changes: 6 additions & 0 deletions packages/orchestrator/.env.local
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
ARTIFACTS_REGISTRY_PROVIDER=Local
ENVIRONMENT=local
FIRECRACKER_VERSIONS_DIR=../fc-versions/builds
HOST_ENVD_PATH=../envd/bin/envd
HOST_KERNELS_DIR=../fc-kernels
LOCAL_TEMPLATE_STORAGE_BASE_PATH=./tmp/local-template-storage
SANDBOX_CACHE_DIR=./tmp/sandbox-cache-dir
ORCHESTRATOR_BASE_PATH=./tmp/
ORCHESTRATOR_LOCK_PATH=./tmp/.lock
ORCHESTRATOR_SERVICES=orchestrator,template-manager
OTEL_COLLECTOR_GRPC_ENDPOINT=localhost:4317
REDIS_URL=localhost:6379
SNAPSHOT_CACHE_DIR=./tmp/snapshot-cache
STORAGE_PROVIDER=Local
4 changes: 3 additions & 1 deletion packages/orchestrator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ endef

.PHONY: run-local
run-local:
make build-debug
$(call setup_local_env)
NODE_ID=$$(hostname) ./bin/orchestrator --port 3000
mkdir -p $(ORCHESTRATOR_BASE_PATH)/build-templates
NODE_ID=$$(hostname) sudo -E ./bin/orchestrator --port 3000

.PHONY: upload/clean-nfs-cache
upload/clean-nfs-cache:
Expand Down
42 changes: 23 additions & 19 deletions packages/orchestrator/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"go.uber.org/zap"

"github.com/e2b-dev/infra/packages/orchestrator/internal/cfg"
"github.com/e2b-dev/infra/packages/orchestrator/internal/paths"
"github.com/e2b-dev/infra/packages/orchestrator/internal/proxy"
"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox"
blockmetrics "github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/block/metrics"
Expand Down Expand Up @@ -53,8 +54,8 @@ func BenchmarkBaseImageLaunch(b *testing.B) {
baseImage = "e2bdev/base"
kernelVersion = "vmlinux-6.1.102"
fcVersion = "v1.10.1_1fcdaec08"
templateID = "fcb33d09-3141-42c4-8d3b-c2df411681db"
buildID = "ba6aae36-74f7-487a-b6f7-74fd7c94e479"
templateID = "fcb33d09-3141-42c4-8d3b-c2df411681dc"
buildID = "ba6aae36-74f7-487a-b6f7-74fd7c94e478"
useHugePages = false
allowInternetAccess = true
templateVersion = "v2.0.0"
Expand Down Expand Up @@ -98,15 +99,15 @@ func BenchmarkBaseImageLaunch(b *testing.B) {

// hacks, these should go away
b.Setenv("ARTIFACTS_REGISTRY_PROVIDER", "Local")
b.Setenv("USE_LOCAL_NAMESPACE_STORAGE", "true")
b.Setenv("STORAGE_PROVIDER", "Local")
b.Setenv("ORCHESTRATOR_BASE_PATH", tempDir)
b.Setenv("HOST_ENVD_PATH", abs(filepath.Join("..", "envd", "bin", "envd")))
b.Setenv("FIRECRACKER_VERSIONS_DIR", abs(filepath.Join("..", "fc-versions", "builds")))
b.Setenv("HOST_ENVD_PATH", abs(filepath.Join("..", "envd", "bin", "envd")))
b.Setenv("HOST_KERNELS_DIR", abs(kernelsDir))
b.Setenv("LOCAL_TEMPLATE_STORAGE_BASE_PATH", abs(filepath.Join(persistenceDir, "templates")))
b.Setenv("ORCHESTRATOR_BASE_PATH", tempDir)
b.Setenv("SANDBOX_DIR", abs(sandboxDir))
b.Setenv("SNAPSHOT_CACHE_DIR", abs(filepath.Join(tempDir, "snapshot-cache")))
b.Setenv("LOCAL_TEMPLATE_STORAGE_BASE_PATH", abs(filepath.Join(persistenceDir, "templates")))
b.Setenv("STORAGE_PROVIDER", "Local")
b.Setenv("USE_LOCAL_NAMESPACE_STORAGE", "true")

config, err := cfg.Parse()
require.NoError(b, err)
Expand Down Expand Up @@ -231,6 +232,7 @@ func BenchmarkBaseImageLaunch(b *testing.B) {

builder := build.NewBuilder(
logger,
config.BuilderConfig,
featureFlags,
sandboxFactory,
persistenceTemplate,
Expand Down Expand Up @@ -259,11 +261,12 @@ func BenchmarkBaseImageLaunch(b *testing.B) {
HugePages: sandboxConfig.HugePages,
}

metadata := storage.TemplateFiles{
BuildID: buildID,
KernelVersion: kernelVersion,
FirecrackerVersion: fcVersion,
}
metadata := paths.NewWithVersions(
config.BuilderConfig,
buildID,
kernelVersion,
fcVersion,
)
_, err = builder.Build(b.Context(), metadata, templateConfig, logger.Core())
require.NoError(b, err)
}
Expand All @@ -288,7 +291,7 @@ func BenchmarkBaseImageLaunch(b *testing.B) {
}

for b.Loop() {
tc.testOneItem(b, buildID, kernelVersion, fcVersion)
tc.testOneItem(b, config.BuilderConfig, buildID, kernelVersion, fcVersion)
}
}

Expand All @@ -312,7 +315,7 @@ type testContainer struct {
runtime sandbox.RuntimeMetadata
}

func (tc *testContainer) testOneItem(b *testing.B, buildID, kernelVersion, fcVersion string) {
func (tc *testContainer) testOneItem(b *testing.B, config cfg.BuilderConfig, buildID, kernelVersion, fcVersion string) {
b.Helper()

ctx, span := tracer.Start(b.Context(), "testOneItem")
Expand Down Expand Up @@ -341,11 +344,12 @@ func (tc *testContainer) testOneItem(b *testing.B, buildID, kernelVersion, fcVer
meta, err := sbx.Template.Metadata()
require.NoError(b, err)

templateMetadata := meta.SameVersionTemplate(storage.TemplateFiles{
BuildID: buildID,
KernelVersion: kernelVersion,
FirecrackerVersion: fcVersion,
})
templateMetadata := meta.SameVersionTemplate(paths.NewWithVersions(
config,
buildID,
kernelVersion,
fcVersion,
))
snap, err := sbx.Pause(ctx, templateMetadata)
require.NoError(b, err)
require.NotNil(b, snap)
Expand Down
8 changes: 3 additions & 5 deletions packages/orchestrator/cmd/build-template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"go.uber.org/zap/zapcore"

"github.com/e2b-dev/infra/packages/orchestrator/internal/cfg"
"github.com/e2b-dev/infra/packages/orchestrator/internal/paths"
"github.com/e2b-dev/infra/packages/orchestrator/internal/proxy"
"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox"
blockmetrics "github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/block/metrics"
Expand Down Expand Up @@ -191,6 +192,7 @@ func buildTemplate(

builder := build.NewBuilder(
logger,
c.BuilderConfig,
featureFlags,
sandboxFactory,
persistenceTemplate,
Expand Down Expand Up @@ -221,11 +223,7 @@ func buildTemplate(
HugePages: true,
}

metadata := storage.TemplateFiles{
BuildID: buildID,
KernelVersion: kernelVersion,
FirecrackerVersion: fcVersion,
}
metadata := paths.NewWithVersions(c.BuilderConfig, buildID, kernelVersion, fcVersion)
_, err = builder.Build(ctx, metadata, template, logger.Core())
if err != nil {
return fmt.Errorf("error building template: %w", err)
Expand Down
9 changes: 7 additions & 2 deletions packages/orchestrator/cmd/inspect-data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"log"

"github.com/e2b-dev/infra/packages/orchestrator/internal/cfg"
"github.com/e2b-dev/infra/packages/orchestrator/internal/paths"
"github.com/e2b-dev/infra/packages/shared/pkg/storage"
)

Expand All @@ -18,10 +20,13 @@ func main() {

flag.Parse()

template := storage.TemplateFiles{
BuildID: *buildId,
config, err := cfg.ParseBuilder()
if err != nil {
log.Fatal(err)
}

template := paths.New(config, *buildId)

var storagePath string
var blockSize int64

Expand Down
9 changes: 7 additions & 2 deletions packages/orchestrator/cmd/inspect-header/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"log"
"unsafe"

"github.com/e2b-dev/infra/packages/orchestrator/internal/cfg"
"github.com/e2b-dev/infra/packages/orchestrator/internal/paths"
"github.com/e2b-dev/infra/packages/shared/pkg/storage"
"github.com/e2b-dev/infra/packages/shared/pkg/storage/header"
)
Expand All @@ -17,10 +19,13 @@ func main() {

flag.Parse()

template := storage.TemplateFiles{
BuildID: *buildId,
config, err := cfg.ParseBuilder()
if err != nil {
log.Fatal(err)
}

template := paths.New(config, *buildId)

var storagePath string

switch *kind {
Expand Down
12 changes: 7 additions & 5 deletions packages/orchestrator/cmd/simulate-headers-merge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/google/uuid"

"github.com/e2b-dev/infra/packages/orchestrator/internal/cfg"
"github.com/e2b-dev/infra/packages/orchestrator/internal/paths"
"github.com/e2b-dev/infra/packages/shared/pkg/storage"
"github.com/e2b-dev/infra/packages/shared/pkg/storage/header"
)
Expand All @@ -21,13 +23,13 @@ func main() {

flag.Parse()

baseTemplate := storage.TemplateFiles{
BuildID: *baseBuildId,
config, err := cfg.ParseBuilder()
if err != nil {
log.Fatal(err)
}

diffTemplate := storage.TemplateFiles{
BuildID: *diffBuildId,
}
baseTemplate := paths.New(config, *baseBuildId)
diffTemplate := paths.New(config, *diffBuildId)

var baseStoragePath string
var diffStoragePath string
Expand Down
Loading
Loading