Skip to content

Commit

Permalink
Add 'stream sharing' feature, allowing avoidance of multiple syn… (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
ca-johnson authored Aug 11, 2019
1 parent e61bc53 commit 45f3f06
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
11 changes: 10 additions & 1 deletion .buildkite/local-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ steps:
view: //depot/... ...
root: p4_workspace
parallel: 2
backup_changelists: yes
backup_changelists: yes

# - label: "Test Shared Streams"
# command: echo "Hello World"
# plugins:
# - ./.buildkite/plugins/perforce:
# p4port: localhost:1666
# p4user: banana
# stream: //stream-depot/main # will checkout to ../__stream_depot_main
# share_workspace: yes
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ steps:
parallel: 16
```

Share a stream workspace between pipelines. Useful to avoid syncing duplicate data with large workspaces.
Only allowed when there is a single buildkite agent running on the machine.

```yaml
steps:
plugins:
- ca-johnson/perforce:
stream: //dev/buildkite
share_workspace: true
```

## Triggering Builds

There are a few options for triggering builds that use this plugin, in this order from least valuable but most convenient to most valueable but least convenient.
Expand Down
23 changes: 22 additions & 1 deletion hooks/environment
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# Allow steps to pick up perforce configuration used by the plugin
export P4CONFIG=p4config
export P4CONFIG=p4config

# Allow sharing of perforce client workspaces for the same stream between pipelines
if [[ "${BUILDKITE_PLUGIN_PERFORCE_SHARE_WORKSPACE}" == true ]] ; then
echo "Workspace sharing enabled"

STREAM="${BUILDKITE_PLUGIN_PERFORCE_STREAM}"
if [[ -z "${STREAM}" ]] ; then
echo "Error: You must use stream workspaces to enable shared workspaces" >&2
exit 1
fi
if [[ "${BUILDKITE_AGENT_META_DATA_AGENT_COUNT}" -gt 1 ]] ; then
echo "Error: You cannot share stream workspaces when running more than one agent" >&2
exit 1
fi
# Sanitize //depot/stream-name to __depot_stream-name
SANITIZED_STREAM=$(echo $STREAM | python -c "import sys; print(sys.stdin.read().replace('/', '_'));")

PERFORCE_CHECKOUT_PATH="${BUILDKITE_BUILD_CHECKOUT_PATH}/../${SANITIZED_STREAM}"
export BUILDKITE_BUILD_CHECKOUT_PATH="${PERFORCE_CHECKOUT_PATH}"
echo "Changed BUILDKITE_BUILD_CHECKOUT_PATH to ${PERFORCE_CHECKOUT_PATH}"
fi
3 changes: 2 additions & 1 deletion python/perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def __del__(self):
self.perforce.disconnect()

def _get_clientname(self):
clientname = 'bk-p4-%s-%s' % (os.environ.get('BUILDKITE_AGENT_NAME', socket.gethostname()), os.environ.get('BUILDKITE_PIPELINE_SLUG', ''))
"""Get unique clientname for this host and location on disk"""
clientname = 'bk-p4-%s-%s' % (os.environ.get('BUILDKITE_AGENT_NAME', socket.gethostname()), os.path.basename(self.root))
return re.sub(r'\W', '-', clientname)

def _localize_view(self, view):
Expand Down

0 comments on commit 45f3f06

Please sign in to comment.