Skip to content

Commit

Permalink
feat: add sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghislain89 committed Apr 16, 2024
1 parent 8e8f862 commit 134452e
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 2 deletions.
22 changes: 22 additions & 0 deletions .github/actions/archive-logs/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: 'Archive sandbox logs'
inputs:
test-object:
description: 'object under test'
required: true
runs:
using: 'composite'
steps:
- name: Save sandbox logs
uses: jwalton/gh-docker-logs@v2
with:
dest: './logs-${{ inputs.test-object }}'

- name: Compress logs
shell: bash
run: tar cvzf ./logs-${{ inputs.test-object }}.tgz ./logs-${{ inputs.test-object }}

- name: Upload logs
uses: actions/upload-artifact@v4
with:
name: logs-${{ inputs.test-object }}.tgz
path: ./logs-${{ inputs.test-object }}.tgz
18 changes: 18 additions & 0 deletions .github/actions/archive-volumes/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'Archive sandbox volume'
inputs:
test-object:
description: 'object under test'
required: true
runs:
using: 'composite'
steps:
- name: save volume
shell: bash
run: docker run --rm -v sandbox_sandbox:/bckp-vol -v ./:/bckp busybox tar -zcvf /bckp/devnet-vol.tar.gz /bckp-vol
working-directory: .github/actions/archive-volumes

- name: Upload Volume
uses: actions/upload-artifact@v4
with:
name: sandbox_volume_${{ inputs.test-object }}
path: .github/actions/archive-volumes/devnet-vol.tar.gz
15 changes: 15 additions & 0 deletions .github/actions/sandbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Start Devnet Container

- Starts a Devnet provider
- Optionally perform a few aditional migrations

## Examples

#### Typical Use Case

```yaml
- name: Start devnet
uses: ./.github/actions/devnet
with:
migrations: packages/apps/graph/cwd-extra-migrations
```
13 changes: 13 additions & 0 deletions .github/actions/sandbox/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: 'Start Kadena sandbox'
runs:
using: 'composite'
steps:
- name: Start sandbox
shell: bash
run: docker compose up -d
working-directory: .github/actions/sandbox

- name: Check sandbox health
shell: bash
run: ./healthcheck.sh
working-directory: .github/actions/sandbox
16 changes: 16 additions & 0 deletions .github/actions/sandbox/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3'
services:
devnet:
image: kadena/devnet@sha256:b63feb2de2a46c77199569845f9dc5e44609260dcf1e874b5fb04907d1426e64
ports:
- 8080:8080 # HTTP
- 5432:5432 # Postgres
- 9999:9999 # Info
- 1789:1789
environment:
- MINING_BATCH_PERIOD=0.05
- MINING_CONFIRMATION_PERIOD=1
volumes:
- sandbox:/data
volumes:
sandbox:
22 changes: 22 additions & 0 deletions .github/actions/sandbox/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
counter=0
max_attempts=30
retry_interval=10

while [[ $counter -lt $max_attempts ]]; do
echo "Checking sandbox health..."
response=$(curl -s 'http://localhost:9999/process/chainweb-data')
is_ready=$(echo "$response" | jq -r '.is_ready')

if [[ "$is_ready" == "Ready" ]]; then
echo "Sandbox healthy"
exit 0 # Success exit code
else
echo "Sandbox not healthy, retrying in $retry_interval seconds..."
sleep $retry_interval
counter=$((counter+1))
fi
done

echo "Sandbox not healthy after $max_attempts attempts, exiting."
exit 1 # Error exit code
24 changes: 22 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,28 @@ jobs:
- name: Runner setup
uses: ./.github/actions/runner-setup

- name: Build SpireKey
- name: Build
run: pnpm build

- name: Test SpireKey
- name: Test
run: pnpm test

e2e:
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 2
show-progress: false

- name: Runner setup
uses: ./.github/actions/runner-setup

- name: Setup Kadena sandbox
uses: ./.github/actions/sandbox

- name: end-to-end test
run: pnpm test

0 comments on commit 134452e

Please sign in to comment.