-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow remote shared cache testing from a network isolated sandbox (#1498
) Creates the basic infrastructure needed to run postgres in an isolated test harness, runs the postgres tests in CI
- Loading branch information
1 parent
d7c516f
commit f2aed8e
Showing
9 changed files
with
193 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,3 +51,4 @@ compile_commands.json | |
/rust/entity/target/* | ||
/rust/log_viewer/target/* | ||
/rust/rsc/target/* | ||
/rust/rsc/vendor/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# Copyright 2024 SiFive, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You should have received a copy of LICENSE.Apache2 along with | ||
# this software. If not, you may obtain a copy at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
package build_wake | ||
|
||
from wake import _ | ||
from rust import findCargoPath | ||
|
||
def createFileOp dst = | ||
JObject ( | ||
"type" :-> JString "create-file", | ||
"destination" :-> JString dst, | ||
) | ||
|
||
def createDirOp dst = | ||
JObject ( | ||
"type" :-> JString "create-dir", | ||
"destination" :-> JString dst, | ||
) | ||
|
||
def tmpMountOp dst = | ||
JObject ( | ||
"type" :-> JString "tmpfs", | ||
"destination" :-> JString dst, | ||
) | ||
|
||
def bindMountOp src dst = | ||
JObject ( | ||
"type" :-> JString "bind", | ||
"source" :-> JString src, | ||
"destination" :-> JString dst, | ||
) | ||
|
||
def postgresSpecJson stdinFile cargoPath = | ||
JObject ( | ||
"label" :-> JString "postgres cargo test", | ||
"environment" :-> JArray (JString "PATH=/usr/lib64/ccache:/usr/bin:/usr/sbin:/bin:{dirname cargoPath}",), | ||
"command" :-> JArray (JString "bash", Nil), | ||
"user-id" :-> JInteger 0, | ||
"group-id" :-> JInteger 0, | ||
"visible" :-> JArray Nil, | ||
"directory" :-> JString ".", | ||
"stdin" :-> JString "{stdinFile}", | ||
"resources" :-> JArray Nil, | ||
"isolate-pids" :-> JBoolean True, | ||
"isolate-network" :-> JBoolean True, | ||
"usage" :-> JObject ( | ||
"status" :-> JInteger 0, | ||
"runtime" :-> JInteger 0, | ||
"cputime" :-> JInteger 0, | ||
"membytes" :-> JInteger 0, | ||
"inbytes" :-> JInteger 0, | ||
"outputs" :-> JInteger 0, | ||
), | ||
"mount-ops" :-> JArray ( | ||
tmpMountOp "/tmp", | ||
tmpMountOp "/root", | ||
createDirOp "rust/rsc/.cargo", | ||
createFileOp "rust/rsc/.cargo/config.toml", | ||
bindMountOp "rust/rsc/vendor-config.toml" "rust/rsc/.cargo/config.toml", | ||
), | ||
) | ||
|
||
export target testPostgres Unit = | ||
# First we define a few directories, using various | ||
# environment variables | ||
def dataDir = "/tmp/pg_data" | ||
|
||
require Pass postgresDir = match (getenv "POSTGRES_DIR") | ||
Some dir -> Pass "{dir}/bin" | ||
None -> | ||
require Some postgresPath = whichInEnvPath "postgres" | ||
else failWithError "could not find postgres on path" | ||
|
||
Pass (dirname postgresPath) | ||
|
||
require Pass cargoPath = findCargoPath Unit | ||
|
||
# This is normally unsafe but we're just using it for | ||
# a warning, you should never depend on the result here | ||
require _, _ = files "{@here}/vendor" `.*` | ||
else failWithError "You forgot to run `cargo vendor --locked` inside {@here}" | ||
|
||
# This script is piped in via stdin so that | ||
# as shells are opened one after the other, | ||
# the successive commands are run as intended | ||
def script = | ||
""" | ||
set -ex | ||
trap 'exit $(cat /tmp/status)' 0 | ||
unshare -U | ||
export HOME=/root | ||
mkdir %{dataDir} | ||
echo $? > /tmp/status | ||
%{postgresDir}/initdb -D %{dataDir} | ||
echo $? > /tmp/status | ||
%{postgresDir}/postgres -D %{dataDir} & | ||
trap "kill $!" 0 | ||
sleep 2s | ||
%{postgresDir}/createuser -h localhost root | ||
echo $? > /tmp/status | ||
%{postgresDir}/createdb -h localhost shim | ||
echo $? > /tmp/status | ||
cd %{@here} | ||
%{cargoPath} test | ||
echo $? > /tmp/status | ||
exit $(cat /tmp/status) # exit the unshare shell | ||
""" | ||
|
||
# Jobs require that we write stdin out to a file in order to | ||
# pipe it in | ||
|
||
require Pass scriptPath = write ".build/postgres-cargo.sh" script | ||
|
||
def _ = println "Cargo Path: {cargoPath}" | ||
def pgJson = postgresSpecJson scriptPath.getPathName cargoPath | ||
|
||
require Pass pgJsonPath = write ".build/postgres-cmd-spec.json" (prettyJSON pgJson) | ||
|
||
def emitVendorWarning status = | ||
require (Exited 0) = status | ||
else failWithError "cargo tests failed: Consider running `cargo vendor --locked` in {@here}" | ||
|
||
Pass status | ||
|
||
makeExecPlan ("{wakePath}/wakebox", "-p", pgJsonPath.getPathName, Nil) Nil | ||
| editPlanEnvironment (addEnvironmentPath "/usr/sbin") | ||
| setPlanPersistence ReRun | ||
| setPlanEcho logReport | ||
| runJobWith localRunner | ||
| getJobStatus | ||
| emitVendorWarning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[source.crates-io] | ||
replace-with = "vendored-sources" | ||
|
||
[source.vendored-sources] | ||
directory = "vendor" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters