Skip to content

Commit

Permalink
Sandbox2 wrapper (#1536)
Browse files Browse the repository at this point in the history
* Progress adding sandbox API

* Fixed versioning

* Working example, if you make runfiles visible

* Working node spawn but sketchy af

* Progress using non fork method, but should probably ue forking method

* Fixed policy enforcement of node process, but still execveat error. Should try using bazel pathed nodejs version

* Added bazel build nodejs binary path instead of from usr root

* Progress, still stuch on execveat issue

* Tidy

* Swap to dynamic startup

* Progress passing compile.js to sandboxed script

* Swapped to running compile_loader.js, added custom absolute path finder. Still have fd > -1 error though

* Simplify input

* Strip fd stuff

* Tidy

* Remove runfiles build dependency

* Remove import, format

* Add fd inferral, binary run seems to be failing silently

* Update to latest SAPI, timplify and tidy

* Entry point experimentation

* Progress updating policies

* More allowed syscalls, with explanations

* Tidy policy order

* Working policies

* Progress setting up test

* Tidy some logging

* Update entry point to new worker bundle locale

* Bump protobufjs from 6.8.8 to 6.11.3 (#1346)

* Bump protobufjs from 6.8.8 to 6.11.3

Bumps [protobufjs](https://github.com/protobufjs/protobuf.js) from 6.8.8 to 6.11.3.
- [Release notes](https://github.com/protobufjs/protobuf.js/releases)
- [Changelog](https://github.com/protobufjs/protobuf.js/blob/v6.11.3/CHANGELOG.md)
- [Commits](protobufjs/protobuf.js@6.8.8...v6.11.3)

---
updated-dependencies:
- dependency-name: protobufjs
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update protobufjs dep versions

* Upgrade to protobufjs v7.0.0, node to 16x

* Bump bazel to version 5.2.0

* Bump test CI to correct bazel version

* 3.5.0

* 3.5.0

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Lewis Hemens <lewishemens@google.com>

* Require defaultLocation to be set in BigQuery (#1353)

* Enforce defaultLocation requirement in core and cli initialization

* Add a test

* Bump version

* Update publish script branch (#1354)

* Explicitly set path in dataform.json location validation error (#1355)

* Audit npm/yarn packages and fix (#1356)

* Audit npm/yarn packages and fix

* Remove docs build/push scripts and triggers

* Cut version 2.0.0 (#1361)

* Update @dataform/core to never return a graph with non-unique action names. (#1366)

* Update @dataform/core to never return a graph with non-unique action names.

* Include a compilation error for each removed action.

* Rename a shadowed variable

* Increment DF_VERSION

* Bump moment-timezone from 0.5.28 to 0.5.37 (#1370)

Bumps [moment-timezone](https://github.com/moment/moment-timezone) from 0.5.28 to 0.5.37.
- [Release notes](https://github.com/moment/moment-timezone/releases)
- [Changelog](https://github.com/moment/moment-timezone/blob/develop/changelog.md)
- [Commits](moment/moment-timezone@0.5.28...0.5.37)

---
updated-dependencies:
- dependency-name: moment-timezone
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Upgrade vm2. (#1372)

* Upgrade vm2.

* bump version

* Publish core.proto within the @dataform/core package (#1378)

* Publish core.proto within the @dataform/core package

* Bump version

* Update readme.md (#1397)

* Update readme.md

* Update readme.md

* Enable `main` compilation by default for all @dataform/core versions >= `2.0.4`. (#1401)

* Use main compilation by default for all @dataform/core versions >= 2.0.4.

* use semver.subset

* Bump decode-uri-component from 0.2.0 to 0.2.2 (#1404)

Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2.
- [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases)
- [Commits](SamVerschueren/decode-uri-component@v0.2.0...v0.2.2)

---
updated-dependencies:
- dependency-name: decode-uri-component
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Main <- Master (#1407)

* typo (#1364)

* Buttons label fix (#1365)

"Read the blog post" was linking to the package page and "Visit the package page" was linking to the blog post.

* Update assertions.md (#1377)

Co-authored-by: Dolan <dolanstanley@gmail.com>
Co-authored-by: Stuart Lewis <75398266+stulew93@users.noreply.github.com>

* Make table level assertions have the same tags as the table (#1406)

* Make table level assertions have the same tags as the table

* add tag propagation post assertion adding

* Update version to 2.1.0

* Bump qs from 6.5.2 to 6.5.3 (#1408)

Bumps [qs](https://github.com/ljharb/qs) from 6.5.2 to 6.5.3.
- [Release notes](https://github.com/ljharb/qs/releases)
- [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md)
- [Commits](ljharb/qs@v6.5.2...v6.5.3)

---
updated-dependencies:
- dependency-name: qs
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump express from 4.17.1 to 4.17.3 (#1409)

Bumps [express](https://github.com/expressjs/express) from 4.17.1 to 4.17.3.
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/master/History.md)
- [Commits](expressjs/express@4.17.1...4.17.3)

---
updated-dependencies:
- dependency-name: express
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump go.mongodb.org/mongo-driver from 1.2.0 to 1.5.1 (#1357)

Bumps [go.mongodb.org/mongo-driver](https://github.com/mongodb/mongo-go-driver) from 1.2.0 to 1.5.1.
- [Release notes](https://github.com/mongodb/mongo-go-driver/releases)
- [Commits](mongodb/mongo-go-driver@v1.2.0...v1.5.1)

---
updated-dependencies:
- dependency-name: go.mongodb.org/mongo-driver
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Minor typo correction (#1360)

* Remove @dataform/sql package and common_v1 example (#1415)

* Remove @dataform/sql package and common_v1 example

* Remove SQL package from common_v2 example

* Remove build imports from tests of @dataform/sql that weren't doing anything

* Inline timestamp definition in non BQ tests

* Fix timestamp function case

* Bump json5 from 1.0.1 to 1.0.2 (#1416)

Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](json5/json5@v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Remove dead code paths and those not relating to ELT management (#1414)

* Remove code paths not relating to ELT management

* Remove Dataform SQL package

* Remove unused workspace imports

* Remove common_v1 example

* Remove some v1

* Remove @dataform/sql package and common_v1 example

* Remove SQL package from common_v2 example

* Remove build imports from tests of @dataform/sql that weren't doing anything

* Inline timestamp definition in non BQ tests

* Fix timestamp function case

* Restore v1 backwards_compatibility tests

* Environments and schedules (#1418)

* Remove DB tools dependence on `/api` (#1417)

* Remove DB tools dependence on @dataform/api in prep for removal

* Remove unneccessary options

* Remove more

* More simplifying

* Fix import order

* Tweak postgres connection wait

* Remove console log

* Remove promise pool from presto test

* Remove @dataform/assertion-utils in favor of auto-assertions (#1419)

* Remove @dataform/assertion-utils in favor of auto-assertions

* Fix action count

* Fix quotes in tests

* Fix bazel build //... for our distro by bumping versions (#1421)

* Fix bazel build //... for our distro by bumping versions

* Bump bazel to 5.4.0

* Update contributing (#1425)

* Remove docs content (#1426)

* Remove docs content

* Add note to main readme about docs transition

* Fix contributing link

* Update base dataform image to use more recent Node version (#1427)

* Update base dataform image to use more recent Node version - also bump some required deps

* Bump go version too

* Upgrade vm2 version. (#1431)

* Added schema function (#1432)

* Removed redundant toResolvable calls

* Refactored resolve/normalize in session

* Added schema function to common context objects

* Removed unused session import

* Bumped minor version

* Simplified schema assertions in core.spec.ts

* Refactored normalize* => finalize* in session helpers

* Refactored with/without suffix tests to run as parameterized tests

* Removed redundant 'Test' import

* Bump ua-parser-js from 0.7.28 to 0.7.33 (#1433)

Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.28 to 0.7.33.
- [Release notes](https://github.com/faisalman/ua-parser-js/releases)
- [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md)
- [Commits](faisalman/ua-parser-js@0.7.28...0.7.33)

---
updated-dependencies:
- dependency-name: ua-parser-js
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Refactored name() function to finalize name (#1435)

* Database function (#1438)

* Refactored name() function to finalize name

* Added database() function

* Bumped minor version to 2.3.0

* Refactored database() to add an error when the database is undefined

* Inlined database & ref error messages

* Change sample command to run tests (#1439)

* Update contributing.md (#1446)

* Added includeDependents flag to run command

* Highlight that dev branches should branch off main

* Fix missing credentials error by adding it as the default option (#1447)

* fix missing include dependents (#1448)

* fix missing include dependents

* bump version

* Fix docker cmd for image (#1456)

* Fix docker cmd for image

* Replace with empty cmd instead of help

* Added enum for table's type field (#1453)

* added enum for table's type field

Signed-off-by: Nick Nalivaika <ikolina@google.com>

* update version

Signed-off-by: Nick Nalivaika <ikolina@google.com>

* simplify code by filling enumType field for tables when loading compiled graphs

* small fix for biquery adapter

* make linter happy

* fix integration tests

* do not call setOrValidateTableEnumType when check for table validity, just check enumType value

---------

Signed-off-by: Nick Nalivaika <ikolina@google.com>

* Adds a flag 'track' to allow users to configure analytics with flags (#1450)

* Adds a flag 'no-track' to allow users to configure analytics with flags

* Rework so that no-track bypasses settings.json

* Linting

* Move to --track, fix an issue with --track=true, doc changes

* Update boolean type

* Update version

* Remove code which always executes auto-assertions. (#1460)

* Remove code which always executes auto-assertions.

* fix failing test

* Throw an error for non-string `vars`. (#1461)

* Add job prefix option to the CLI (#1449)

* Add job prefix option to the CLI

* format

* Fix removal of dataform- prefix

* Fix import order

* Import order take 2

* Default empty execution options fix

* fix parameter placement

* Bump vm2 from 3.9.13 to 3.9.15 (#1473)

Bumps [vm2](https://github.com/patriksimek/vm2) from 3.9.13 to 3.9.15.
- [Release notes](https://github.com/patriksimek/vm2/releases)
- [Changelog](https://github.com/patriksimek/vm2/blob/master/CHANGELOG.md)
- [Commits](patriksimek/vm2@3.9.13...3.9.15)

---
updated-dependencies:
- dependency-name: vm2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump vm2 from 3.9.15 to 3.9.16 (#1476)

Bumps [vm2](https://github.com/patriksimek/vm2) from 3.9.15 to 3.9.16.
- [Release notes](https://github.com/patriksimek/vm2/releases)
- [Changelog](https://github.com/patriksimek/vm2/blob/master/CHANGELOG.md)
- [Commits](patriksimek/vm2@3.9.15...3.9.16)

---
updated-dependencies:
- dependency-name: vm2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump vm2 from 3.9.16 to 3.9.17 (#1478)

Bumps [vm2](https://github.com/patriksimek/vm2) from 3.9.16 to 3.9.17.
- [Release notes](https://github.com/patriksimek/vm2/releases)
- [Changelog](https://github.com/patriksimek/vm2/blob/master/CHANGELOG.md)
- [Commits](patriksimek/vm2@3.9.16...3.9.17)

---
updated-dependencies:
- dependency-name: vm2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Remove/update dependencies resulting in updated fsevents dependency version. (#1481)

* Add `schema` & `database` to contextFunctions in compile time (#1485)

* Upgrade vm2 to `3.9.19`. (#1491)

* Remove old vm2 dependency. (#1493)

* Bump loader-utils from 1.2.3 to 1.4.2 (#1492)

Bumps [loader-utils](https://github.com/webpack/loader-utils) from 1.2.3 to 1.4.2.
- [Release notes](https://github.com/webpack/loader-utils/releases)
- [Changelog](https://github.com/webpack/loader-utils/blob/v1.4.2/CHANGELOG.md)
- [Commits](webpack/loader-utils@v1.2.3...v1.4.2)

---
updated-dependencies:
- dependency-name: loader-utils
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump minimatch from 3.0.4 to 3.1.2 (#1495)

Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.0.4 to 3.1.2.
- [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md)
- [Commits](isaacs/minimatch@v3.0.4...v3.1.2)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Release `2.5.0`: to allow use of methods added to SQLX in #1485. (#1498)

* Separate sqlx build target into sqlx and format (#1499)

* Separate sqlx build target into sqlx and format

* Fix build dependencies that used //sqlx

* Update sql-formatter & specify SQL language according to warehouse (#1490)

* Update sql-formatter

* Fix placeholder to be treated as a identifier

* Pass language argument & tweak tests

* Add test cases for named arguments & QUALIFY clause

* Pass language according to warehouse from cli

* Include thrown error message while parsing dataform.json in format

* Revert using ErrorWithCause & just include message

* Move warehouse and sql language mapping

* Add user-defined type guard to handle WarehouseType

* Update format subcommand to use WarehouseType

* Bump minor version to 2.6.0

* Fix trailing ;

* Fix code format & tslint issues

* Bump snowflake-sdk from 1.6.12 to 1.6.21 (#1500)

Bumps [snowflake-sdk](https://github.com/snowflakedb/snowflake-connector-nodejs) from 1.6.12 to 1.6.21.
- [Release notes](https://github.com/snowflakedb/snowflake-connector-nodejs/releases)
- [Commits](snowflakedb/snowflake-connector-nodejs@v1.6.12...v1.6.21)

---
updated-dependencies:
- dependency-name: snowflake-sdk
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump semver from 7.3.8 to 7.5.2 (#1507)

Bumps [semver](https://github.com/npm/node-semver) from 7.3.8 to 7.5.2.
- [Release notes](https://github.com/npm/node-semver/releases)
- [Changelog](https://github.com/npm/node-semver/blob/main/CHANGELOG.md)
- [Commits](npm/node-semver@v7.3.8...v7.5.2)

---
updated-dependencies:
- dependency-name: semver
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump fast-xml-parser from 4.2.4 to 4.2.5 (#1508)

Bumps [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) from 4.2.4 to 4.2.5.
- [Release notes](https://github.com/NaturalIntelligence/fast-xml-parser/releases)
- [Changelog](https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/CHANGELOG.md)
- [Commits](NaturalIntelligence/fast-xml-parser@v4.2.4...v4.2.5)

---
updated-dependencies:
- dependency-name: fast-xml-parser
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Fix image link in readme.md (#1506)

* Enable formatting for triple-quoted strings (#1505)

* Add test cases for tirple-quoted string

* Add a todo test case for formatting

* Enhance lexer to handle triple-quoted string

* Fix tslint issues

* Fix typos

* Bump protobufjs from 7.0.0 to 7.2.4 (#1510)

Bumps [protobufjs](https://github.com/protobufjs/protobuf.js) from 7.0.0 to 7.2.4.
- [Release notes](https://github.com/protobufjs/protobuf.js/releases)
- [Changelog](https://github.com/protobufjs/protobuf.js/blob/master/CHANGELOG.md)
- [Commits](protobufjs/protobuf.js@protobufjs-v7.0.0...protobufjs-v7.2.4)

---
updated-dependencies:
- dependency-name: protobufjs
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update version.bzl (#1516)

* Include multiline string literals when creating statements (#1520)

* Include multiline string literals when creating statements

* Bump version to 2.6.2

* Remove unused tools and add vscode package-lock.json (#1521)

* Revert "Update entry point to new worker bundle locale"

This reverts commit 7c970c3.

* Revert "Revert "Update entry point to new worker bundle locale""

This reverts commit 6fdb5f6.

* Fix merge to be from main_v1

* Progress re-adding sandbox/vm bundle

* Some tweaks as a hacky way to make deps work

* Move to minimal bash invocation example

* Cleanup to minimal node invocation

* Checkpoint

* Tests nearly working

* Can run compile, but tests failing

* Exit process to avoid sandbox breakage

* Tests passing with tight policies

* Make sandbox2 usage configurable

* Remove some unneeded tests

* Remove linting

* Disable integration, cli tests

* Review comments

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Nick Nalivaika <ikolina@google.com>
Co-authored-by: Elias Kassell <elias@dataform.co>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: diasdauletov <110160920+diasdauletov@users.noreply.github.com>
Co-authored-by: BenBirt <benbirt@google.com>
Co-authored-by: ghh <ghh@dataform.co>
Co-authored-by: Dolan <dolanstanley@gmail.com>
Co-authored-by: Stuart Lewis <75398266+stulew93@users.noreply.github.com>
Co-authored-by: Joshua Brandon <joshuaabrandon@gmail.com>
Co-authored-by: Alito Alvarez <alitoalvarez@google.com>
Co-authored-by: Andres Lowrie <andres.lowrie@gmail.com>
Co-authored-by: Nick Nalivayka <ni_kolya93@mail.ru>
Co-authored-by: George McGowan <zerogravitas@google.com>
Co-authored-by: pokutuna <mail@pokutuna.com>
Co-authored-by: VIKRAM SINGH <hkvikramsingh@google.com>
  • Loading branch information
15 people committed Aug 31, 2023
1 parent c05ded7 commit 112dad4
Show file tree
Hide file tree
Showing 15 changed files with 1,277 additions and 768 deletions.
7 changes: 7 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ build:remote-cache --remote_instance_name=projects/dataform-corp/instances/dataf
build:remote-cache --remote_timeout=3600
build:remote-cache --auth_enabled=true
build:remote-cache --google_default_credentials=true

# Build in C++17 mode without a custom CROSSTOOL
build --cxxopt=-std=c++17

# TODO(https://github.com/bazelbuild/bazel/issues/8672): Remove this workaround
# This will become the default in Bazel 4.0
build --incompatible_linkopts_to_linklibs
54 changes: 52 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
workspace(name = "df")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

http_archive(
name = "bazel_skylib",
Expand Down Expand Up @@ -33,6 +35,54 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

git_repository(
name = "com_google_sandboxed_api",
commit = "19fd11b91e6678db2fcfe69dd4037605730f5317",
remote = "https://github.com/google/sandboxed-api.git",
shallow_since = "1610629882 -0800",
)

http_archive(
name = "enum34_archive",
build_file = "@com_google_sandboxed_api//sandboxed_api/bazel/external:enum34.BUILD",
sha256 = "8ad8c4783bf61ded74527bffb48ed9b54166685e4230386a9ed9b1279e2df5b1",
strip_prefix = "enum34-1.1.6",
urls = ["https://files.pythonhosted.org/packages/bf/3e/31d502c25302814a7c2f1d3959d2a3b3f78e509002ba91aea64993936876/enum34-1.1.6.tar.gz"],
)

load("@com_google_sandboxed_api//sandboxed_api/bazel:sapi_deps.bzl", "sapi_deps")

sapi_deps()

http_archive(
name = "net_zlib",
build_file = "@com_google_sandboxed_api//sandboxed_api:bazel/external/zlib.BUILD",
patch_args = ["-p1"],
patches = ["@com_google_sandboxed_api//sandboxed_api:bazel/external/zlib.patch"],
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
strip_prefix = "zlib-1.2.11",
urls = [
"https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz",
"https://www.zlib.net/zlib-1.2.11.tar.gz",
],
)

maybe(
http_archive,
name = "com_google_googletest",
sha256 = "a6ab7c7d6fd4dd727f6012b5d85d71a73d3aa1274f529ecd4ad84eb9ec4ff767",
strip_prefix = "googletest-dcc92d0ab6c4ce022162a23566d44f673251eee4",
urls = ["https://github.com/google/googletest/archive/dcc92d0ab6c4ce022162a23566d44f673251eee4.zip"],
)

maybe(
http_archive,
name = "com_google_benchmark",
sha256 = "7f45be0bff07d787d75c3864212e9ea5ebba57593b2e487c783d11da70ef6857",
strip_prefix = "benchmark-56898e9a92fba537671d5462df9c5ef2ea6a823a",
urls = ["https://github.com/google/benchmark/archive/56898e9a92fba537671d5462df9c5ef2ea6a823a.zip"],
)

http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "d14076339deb08e5460c221fae5c5e9605d2ef4848eee1f0c81c9ffdc1ab31c1",
Expand Down Expand Up @@ -124,9 +174,9 @@ load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")

container_deps()

load("@io_bazel_rules_docker//repositories:pip_repositories.bzl", "pip_deps")
load("@io_bazel_rules_docker//repositories:py_repositories.bzl", "py_deps")

pip_deps()
py_deps()

load(
"@io_bazel_rules_docker//container:container.bzl",
Expand Down
8 changes: 8 additions & 0 deletions api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ ts_library(
["**/*.ts"],
exclude = ["utils/**/*.*"],
),
data = [
"@nodejs_linux_amd64//:node_bin",
"//sandbox:compile_executor",
"//sandbox/worker:worker_bundle.js",
"//sandbox/worker:node_modules"
],
deps = [
"//api/utils",
"//common/errors",
Expand All @@ -32,6 +38,7 @@ ts_library(
"@npm//@types/pg-query-stream",
"@npm//@types/semver",
"@npm//@types/ssh2",
"@npm//@types/uuid",
"@npm//cron-parser",
"@npm//deepmerge",
"@npm//get-port",
Expand All @@ -41,6 +48,7 @@ ts_library(
"@npm//mssql",
"@npm//object-hash",
"@npm//pg",
"@npm//uuid",
"@npm//pg-query-stream",
"@npm//presto-client",
"@npm//pretty-ms",
Expand Down
101 changes: 54 additions & 47 deletions api/commands/compile.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import * as fs from "fs";
import * as path from "path";
import * as net from "net";
import { promisify } from "util";
import * as os from "os";

import { ChildProcess, fork } from "child_process";
import { ChildProcess, fork, spawn } from "child_process";
import deepmerge from "deepmerge";
import { validWarehouses } from "df/api/dbadapters";
import { coerceAsError, ErrorWithCause } from "df/common/errors/errors";
import { decode64 } from "df/common/protos";
import { decode64, encode64 } from "df/common/protos";
import { dataform } from "df/protos/ts";
import { v4 as uuid } from "uuid";

// Project config properties that are required.
const mandatoryProps: Array<keyof dataform.IProjectConfig> = ["warehouse", "defaultSchema"];
Expand All @@ -20,13 +24,14 @@ const simpleCheckProps: Array<keyof dataform.IProjectConfig> = [
"defaultSchema"
];

export class CompilationTimeoutError extends Error {}
export class CompilationTimeoutError extends Error { }

export async function compile(
compileConfig: dataform.ICompileConfig = {}
compileConfig: dataform.ICompileConfig = {},
useSandbox2?: boolean,
): Promise<dataform.CompiledGraph> {
// Resolve the path in case it hasn't been resolved already.
path.resolve(compileConfig.projectDir);
compileConfig = { ...compileConfig, projectDir: path.resolve(compileConfig.projectDir) }

try {
// check dataformJson is valid before we try to compile
Expand All @@ -40,67 +45,70 @@ export async function compile(
);
}

const result = await CompileChildProcess.forkProcess().compile(compileConfig);
var result: string = "";

if (compileConfig.useMain) {
const decodedResult = decode64(dataform.CoreExecutionResponse, result);
return dataform.CompiledGraph.create(decodedResult.compile.compiledGraph);
const socketPath = `/tmp/${uuid()}.sock`;

if (fs.existsSync(socketPath)) {
fs.unlinkSync(socketPath);
}
const server = net.createServer((socket) => {
socket.on("data", (buf) => {
result += buf.toString();
});
});

server.listen(socketPath);

await CompileChildProcess.forkProcess(socketPath, { ...compileConfig, useMain: false }, useSandbox2).timeout(compileConfig.timeoutMillis || 5000);

return decode64(dataform.CompiledGraph, result);
await promisify(server.close.bind(server))();

if (result.startsWith("ERROR:")) {
throw coerceAsError(JSON.parse(result.substring(6)));
}
const decodedResult = decode64(dataform.CompiledGraph, result);
return decodedResult;
}

export class CompileChildProcess {
public static forkProcess() {
// Runs the worker_bundle script we generate for the package (see packages/@dataform/cli/BUILD)
// if it exists, otherwise run the bazel compile loader target.
const findForkScript = () => {
try {
const workerBundlePath = require.resolve("./worker_bundle");
return workerBundlePath;
} catch (e) {
return require.resolve("../../sandbox/vm/compile_loader");
}
};
const forkScript = findForkScript();
return new CompileChildProcess(
fork(require.resolve(forkScript), [], { stdio: [0, 1, 2, "ipc", "pipe"] })
);
public static forkProcess(socket: string, compileConfig: dataform.ICompileConfig, useSandbox2: boolean) {
const platformPath = os.platform() === "darwin" ? "nodejs_darwin_amd64" : "nodejs_linux_amd64";
const nodePath = path.join(process.env.RUNFILES, "df", `external/${platformPath}/bin/nodejs/bin/node`);
const workerRootPath = path.join(process.env.RUNFILES, "df", "sandbox/worker");
const sandboxerPath = path.join(process.env.RUNFILES, "df", `sandbox/compile_executor`);
if (useSandbox2) {
return new CompileChildProcess(
spawn(sandboxerPath, [nodePath, workerRootPath, socket, encode64(dataform.CompileConfig, compileConfig), compileConfig.projectDir], { stdio: [0, 1, 2, "ipc", "pipe"] })
);
} else {
return new CompileChildProcess(
spawn(nodePath, [path.join(workerRootPath, "worker_bundle.js"), socket, encode64(dataform.CompileConfig, compileConfig)], { stdio: [0, 1, 2, "ipc", "pipe"] })
);
}
}
private readonly childProcess: ChildProcess;

constructor(childProcess: ChildProcess) {
this.childProcess = childProcess;
}

public async compile(compileConfig: dataform.ICompileConfig) {
public async timeout(timeoutMillis: number) {
const compileInChildProcess = new Promise<string>(async (resolve, reject) => {
this.childProcess.on("error", (e: Error) => reject(coerceAsError(e)));

this.childProcess.on("message", (messageOrError: string | Error) => {
if (typeof messageOrError === "string") {
resolve(messageOrError);
return;
}
reject(coerceAsError(messageOrError));
});

this.childProcess.on("close", exitCode => {
this.childProcess.on("exit", exitCode => {
if (exitCode !== 0) {
reject(new Error(`Compilation child process exited with exit code ${exitCode}.`));
}
resolve("Compilation completed successfully");
});

// Trigger the child process to start compiling.
this.childProcess.send(compileConfig);
});
let timer;
const timeout = new Promise(
(resolve, reject) =>
(timer = setTimeout(
() => reject(new CompilationTimeoutError("Compilation timed out")),
compileConfig.timeoutMillis || 5000
))
(timer = setTimeout(
() => reject(new CompilationTimeoutError("Compilation timed out")),
timeoutMillis
))
);
try {
await Promise.race([timeout, compileInChildProcess]);
Expand All @@ -119,9 +127,8 @@ export class CompileChildProcess {
export const checkDataformJsonValidity = (dataformJsonParsed: { [prop: string]: any }) => {
const invalidWarehouseProp = () => {
return dataformJsonParsed.warehouse && !validWarehouses.includes(dataformJsonParsed.warehouse)
? `Invalid value on property warehouse: ${
dataformJsonParsed.warehouse
}. Should be one of: ${validWarehouses.join(", ")}.`
? `Invalid value on property warehouse: ${dataformJsonParsed.warehouse
}. Should be one of: ${validWarehouses.join(", ")}.`
: null;
};
const invalidProp = () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/@dataform/cli/worker.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import { listenForCompileRequest } from "df/sandbox/vm/compile";
listenForCompileRequest();
import { compileAndSend } from "df/sandbox/vm/compile";

compileAndSend(process.argv[2], process.argv[3]);
26 changes: 26 additions & 0 deletions sandbox/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package(default_visibility = ["//visibility:public"])

load("@com_google_sandboxed_api//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")

cc_binary(
name = "compile_executor",
srcs = ["compile_executor.cc"],
args = [
"$(location @nodejs_linux_amd64//:node_bin)",
"$(location //sandbox/worker:worker_bundle.js)",
],
copts = sapi_platform_copts(),
data = [
"@nodejs_linux_amd64//:node_bin",
"//sandbox/worker:worker_bundle.js",
"//sandbox/worker:node_modules",
],
deps = [
"@bazel_tools//tools/cpp/runfiles",
"@com_google_absl//absl/base:core_headers",
"@com_google_sandboxed_api//sandboxed_api/sandbox2",
"@com_google_sandboxed_api//sandboxed_api/sandbox2:comms",
"@com_google_sandboxed_api//sandboxed_api/sandbox2/util:bpf_helper",
"@com_google_sandboxed_api//sandboxed_api/util:runfiles",
],
)

0 comments on commit 112dad4

Please sign in to comment.