Skip to content

Commit

Permalink
feat!: added spec2 support
Browse files Browse the repository at this point in the history
- removed artifacts
- new endpoints
  • Loading branch information
ddovbii authored Jun 23, 2022
2 parents d3c0e41 + d10a953 commit 373b83b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/commands/end-sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ steps:
name: End Torque Sandbox
command: |
curl --silent -X DELETE "$<<parameters.torque-url>>/api/spaces/$<<parameters.space>>/sandbox/$<<parameters.sandbox-id>>" \
--header "User-Agent: Torque-Plugin-CirceCI/1.0.X" \
--header "User-Agent: Torque-Plugin-CirceCI/1.1.X" \
--header "accept: text/plain" \
--header "Authorization: bearer $<<parameters.torque-token>>" || exit 1
47 changes: 25 additions & 22 deletions src/commands/start-sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ parameters:
Json format {'key1': 'value1', ..., 'keyN': 'valueN'}
type: string
default: "{}"
artifacts:
description: |
String with the list of artifacts.
Json format {'key1': 'value1', ..., 'keyN': 'valueN'}
type: string
default: "{}"
timeout:
description: >
Timeout for this step in minutes. If the sandbox will not be ready when the timeout is reached,
Expand All @@ -69,15 +63,14 @@ steps:
'blueprint_name':'<<parameters.blueprint>>',
'duration': '<<parameters.duration>>',
'inputs': <<parameters.inputs>>,
'artifacts': <<parameters.artifacts>>,
'automation': true
}"
)
echo $PAYLOAD
status_code=`curl --write-out "%{http_code}\n" --output result.txt \
--silent -X POST "$<<parameters.torque-url>>/api/spaces/$<<parameters.space>>/sandbox" \
--header "User-Agent: Torque-Plugin-CirceCI/1.0.X" \
--silent -X POST "$<<parameters.torque-url>>/api/spaces/$<<parameters.space>>/environments" \
--header "User-Agent: Torque-Plugin-CirceCI/1.1.X" \
--header "accept: text/plain" \
--header "Authorization: bearer $<<parameters.torque-token>>" \
--header "Content-Type: application/json" -d "$PAYLOAD"` || exit 1
Expand All @@ -96,26 +89,36 @@ steps:
echo "Waiting for sandbox $<<parameters.sandbox-id-variable>>"
timeout=`date --date="<<parameters.timeout>> minutes" +%s`
status=''
while [[ $(date +%s) -le $timeout && $status != "Active" ]]; do
prev_status=''
while [[ $(date +%s) -le $timeout ]]; do
url="$<<parameters.torque-url>>/api/spaces/$<<parameters.space>>/environments/$<<parameters.sandbox-id-variable>>"
echo "****"
sleep 25
details=`curl --silent \
-X GET "$<<parameters.torque-url>>/api/spaces/$<<parameters.space>>/sandbox/$<<parameters.sandbox-id-variable>>" \
--header "User-Agent: Torque-Plugin-CirceCI/1.0.X" \ \
-X GET "${url}" \
--header "User-Agent: Torque-Plugin-CirceCI/1.1.X" \
--header "accept: text/plain" \
--header "Authorization: bearer $<<parameters.torque-token>>"`
status=`echo $details | sed "s/.*\"sandbox_status\":\"//" | sed "s/\".*//"`
echo "Status is $status"
status=`echo $details | sed "s/.*\"computed_status\":\"//" | sed "s/\".*//"`
if [[ $status != $prev_status ]]; then
echo "Status is $status"
prev_status=$status
fi
if [[ $status == "Active" ]]; then
break
fi
if [[ $status == "Ended" ]]; then
echo "Error: sandbox is ended"
exit 1
fi
if [[ $status == "Active With Error" ]]; then
echo "Error: sandbox is active with error!"
exit 1
fi
sleep 20
done
if [[ $status != "Active" ]]; then
echo "Timeout was reached or Sandbox is active with errors"
exit 1
fi
echo "export <<parameters.sandbox-details-variable>>=$details" >> $BASH_ENV
var=1
for link in `echo $details | egrep -o '\["http?://[^ ]+*."\]' | sed 's/"//g' | tr -d '[],'`
do
echo "Writing quick link $link to environment variable SB_${<<parameters.sandbox-id-variable>>}_SHORTCUT_${var}"
echo "export SB_${<<parameters.sandbox-id-variable>>}_SHORTCUT_${var}=$link" >> $BASH_ENV
var=$((var+1))
done
3 changes: 1 addition & 2 deletions src/examples/fetch-info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: |
usage:
version: 2.1
orbs:
torque: quali/torque@1
torque: quali/torque@1.1
jobs:
build:
docker:
Expand All @@ -13,7 +13,6 @@ usage:
sandbox-name: "test-sandbox"
blueprint: "my-application"
inputs: "{'AWS_INSTANCE_TYPE': 'm5.large'}"
artifacts: "{'app-frontend':'latest/my-app.latest.tar.gz'}"
- run:
name: Fetch Details
command: echo "Sandbox ID is ${SANDBOX_ID}"
Expand Down
10 changes: 4 additions & 6 deletions src/examples/test-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ usage:
version: 2.1

orbs:
torque: quali/torque@1.0
torque: quali/torque@1.1
aws-s3: circleci/[email protected]
jobs:
build-and-publish:
Expand All @@ -32,14 +32,12 @@ usage:
sandbox-name: "test-sandbox"
blueprint: "my-web-application"
inputs: "{'AWS_INSTANCE_TYPE': 'm5.large'}"
artifacts: "{'webapp-frontend':'latest/my-webapp.latest.tar.gz'}"
steps:
- run: echo "Do some testing here"
- run:
command: |
echo "Getting application endpoint"
SB_ENDPOINT="SB_${SANDBOX_ID}_SHORTCUT_1"
echo "Checking ${!SB_ENDPOINT}"
curl --write-out "%{http_code}\n" --silent --output /dev/null "${!SB_ENDPOINT}"
echo "Getting sandbox details"
echo "You can process the json with jq and perform some tests"
echo "${SANDBOX_DETAILS}"
requires:
- build-and-publish
7 changes: 0 additions & 7 deletions src/jobs/sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ parameters:
Json format {'key1': 'value1', ..., 'keyN': 'valueN'}
type: string
default: "{}"
artifacts:
description: |
String with the list of artifacts.
Json format {'key1': 'value1', ..., 'keyN': 'valueN'}
type: string
default: "{}"
steps:
type: steps
description: Steps to execute once the Torque Sandbox is available
Expand All @@ -58,7 +52,6 @@ steps:
sandbox-name: <<parameters.sandbox-name>>
blueprint: <<parameters.blueprint>>
inputs: <<parameters.inputs>>
artifacts: <<parameters.artifacts>>
torque-token: <<parameters.torque-token>>
torque-url: <<parameters.torque-url>>
space: <<parameters.space>>
Expand Down

0 comments on commit 373b83b

Please sign in to comment.