-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Automattic/add/artifact-support
Add artifact support
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash -eu | ||
|
||
# Usage | ||
# download_artifact $file_name [$destination] | ||
# | ||
# $file_name should be the name of the file - it'll automatically be combined with the current build ID to differentiate between | ||
# the same file in different jobs. It'll be identical to the `basename` of whatever you passed to `store_artifact`. | ||
# | ||
# $destination is an optional argument – by default, `download_artifact` will download the artifact to the present working directory, | ||
# but if you'd like it stored elsewhere, just pass the path as the second argument. | ||
|
||
ARTIFACT_FILE_NAME=${1-} | ||
|
||
if [ -z "$ARTIFACT_FILE_NAME" ]; then | ||
echo "You must pass the name of the file you want to download" | ||
exit 1 | ||
fi | ||
|
||
BUCKET=${ARTIFACTS_S3_BUCKET-} | ||
|
||
if [ -z "$BUCKET" ]; then | ||
echo "You must pass set the \`ARTIFACTS_S3_BUCKET\` environment variable with the S3 bucket you'd like to use" | ||
exit 2 | ||
fi | ||
|
||
OUTPUT_PATH=${2-.} | ||
|
||
KEY="$BUILDKITE_BUILD_ID/$ARTIFACT_FILE_NAME" | ||
|
||
# If the bucket has transfer acceleration enabled, use it! | ||
ACCELERATION_STATUS=$(aws s3api get-bucket-accelerate-configuration --bucket $BUCKET | jq '.Status' -r || true) | ||
|
||
if [ "$ACCELERATION_STATUS" = "Enabled" ]; then | ||
echo "Downloading with transfer acceleration" | ||
aws s3 cp "s3://$BUCKET/$KEY" $OUTPUT_PATH --endpoint-url https://s3-accelerate.amazonaws.com | ||
else | ||
aws s3 cp "s3://$BUCKET/$KEY" $OUTPUT_PATH | ||
fi | ||
|
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,40 @@ | ||
#!/bin/bash -eu | ||
|
||
# Usage | ||
# store_artifact $file_path | ||
# | ||
# $file_path is the path to a file on disk. It'll automatically be combined with the current build ID to differentiate between | ||
# the same file in different jobs so that it can be correctly re-downloaded within the same job. | ||
|
||
ARTIFACT_PATH=$1 | ||
|
||
if [ -z "$ARTIFACT_PATH" ]; then | ||
echo "You must pass the file you want to be stored" | ||
exit 1 | ||
fi | ||
|
||
if [ ! -f "$ARTIFACT_PATH" ]; then | ||
echo "No file found at $ARTIFACT_PATH" | ||
exit 2 | ||
fi | ||
|
||
BUCKET=${ARTIFACTS_S3_BUCKET-} | ||
|
||
if [ -z "$BUCKET" ]; then | ||
echo "You must pass set the \`ARTIFACTS_S3_BUCKET\` environment variable with the S3 bucket you'd like to use" | ||
exit 3 | ||
fi | ||
|
||
BASENAME=$(basename $ARTIFACT_PATH) | ||
KEY="$BUILDKITE_BUILD_ID/$BASENAME" | ||
|
||
# If the bucket has transfer acceleration enabled, use it! | ||
ACCELERATION_STATUS=$(aws s3api get-bucket-accelerate-configuration --bucket $BUCKET | jq '.Status' -r || true) | ||
|
||
if [ "$ACCELERATION_STATUS" = "Enabled" ]; then | ||
echo "Uploading with transfer acceleration" | ||
aws s3 cp $ARTIFACT_PATH "s3://$BUCKET/$KEY" --endpoint-url https://s3-accelerate.amazonaws.com | ||
else | ||
aws s3 cp $ARTIFACT_PATH "s3://$BUCKET/$KEY" | ||
fi | ||
|