Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
buildstream
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
BuildStream
buildstream
Commits
58b38f32
Commit
58b38f32
authored
6 years ago
by
Benjamin Schubert
Browse files
Options
Downloads
Patches
Plain Diff
First draft for docker sandbox
parent
2a0676c3
No related branches found
No related tags found
No related merge requests found
Pipeline
#39345556
failed
6 years ago
Stage: prepare
Stage: test
Stage: post
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
buildstream/_platform/linux.py
+4
-0
4 additions, 0 deletions
buildstream/_platform/linux.py
buildstream/sandbox/_sandboxdocker.py
+87
-0
87 additions, 0 deletions
buildstream/sandbox/_sandboxdocker.py
with
91 additions
and
0 deletions
buildstream/_platform/linux.py
+
4
−
0
View file @
58b38f32
...
...
@@ -63,6 +63,10 @@ class Linux(Platform):
self
.
_linux32
=
False
def
create_sandbox
(
self
,
*
args
,
**
kwargs
):
# FIXME: we need a better way rather than hijacking
# the normal setup process
from
..sandbox._sandboxdocker
import
SandboxDocker
return
SandboxDocker
(
*
args
,
**
kwargs
)
if
not
self
.
_local_sandbox_available
:
return
self
.
_create_dummy_sandbox
(
*
args
,
**
kwargs
)
else
:
...
...
This diff is collapsed.
Click to expand it.
buildstream/sandbox/_sandboxdocker.py
0 → 100755
+
87
−
0
View file @
58b38f32
import
os
import
sys
import
stat
import
signal
import
subprocess
from
contextlib
import
contextmanager
,
ExitStack
import
psutil
import
tempfile
import
docker
from
.._exceptions
import
SandboxError
from
..
import
utils
from
..
import
_signals
from
._mounter
import
Mounter
from
._mount
import
MountMap
from
.
import
Sandbox
,
SandboxFlags
DOCKERFILE
=
"""
FROM scratch
ADD . /
"""
.
strip
()
class
SandboxDocker
(
Sandbox
):
def
run
(
self
,
command
,
flags
,
*
,
cwd
=
None
,
env
=
None
):
client
=
docker
.
from_env
()
stdout
,
stderr
=
self
.
_get_output
()
# Fallback to the sandbox default settings for
# the cwd and env.
#
cwd
=
self
.
_get_work_directory
(
cwd
=
cwd
)
env
=
self
.
_get_environment
(
cwd
=
cwd
,
env
=
env
)
# Convert single-string argument to a list
if
isinstance
(
command
,
str
):
command
=
[
command
]
if
not
self
.
_has_command
(
command
[
0
],
env
):
raise
SandboxError
(
"
Staged artifacts do not provide command
"
"'
{}
'"
.
format
(
command
[
0
]),
reason
=
'
missing-command
'
)
# Create the mount map, this will tell us where
# each mount point needs to be mounted from and to
mount_map
=
MountMap
(
self
,
flags
&
SandboxFlags
.
ROOT_READ_ONLY
)
root_mount_source
=
mount_map
.
get_mount_source
(
"
/
"
)
with
open
(
os
.
path
.
join
(
root_mount_source
,
"
Dockerfile
"
),
"
w
"
)
as
fp
:
fp
.
write
(
DOCKERFILE
)
image
,
_
=
client
.
images
.
build
(
path
=
root_mount_source
)
volumes
=
{}
mount_source_overrides
=
self
.
_get_mount_sources
()
for
mark
in
self
.
_get_marked_directories
():
mount_point
=
mark
[
"
directory
"
]
if
mount_point
in
mount_source_overrides
:
mount_source
=
mount_source_overrides
[
mount_point
]
else
:
mount_source
=
mount_map
.
get_mount_source
(
mount_point
)
volumes
[
mount_source
]
=
{
"
bind
"
:
mount_point
}
# TODO: we need to handle root that is RO
# TODO: we need to handle cwd
# TODO: we need to handle env
# TODO: we need to support specific user uid/gid
# TODO: we need to support interactive mode
args
=
{
"
image
"
:
image
,
"
command
"
:
command
,
"
detach
"
:
True
,
"
volumes
"
:
volumes
,
}
container
=
client
.
containers
.
run
(
**
args
)
# TODO: we need to handle signals and react accordingly
status
=
container
.
wait
()
self
.
_vdir
.
_mark_changed
()
return
status
[
"
StatusCode
"
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment