Skip to content

Commit ffb8b50

Browse files
committed
Initial commit
Signed-off-by: Ben <[email protected]>
1 parent b4e2f4d commit ffb8b50

File tree

10 files changed

+496
-6
lines changed

10 files changed

+496
-6
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#cloud-config
2+
package_update: true
3+
packages: [docker.io, git, make, unzip, jq, curl, ca-certificates, nodejs, npm]
4+
5+
write_files:
6+
- path: /etc/warp.env
7+
permissions: '0600'
8+
content: |
9+
NODE_PATH=/usr/local/lib/node_modules
10+
SLACK_NIGHTLY_RESULTS_URL=${SLACK_NIGHTLY_RESULTS_URL}
11+
AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
12+
AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
13+
WARP_LOGS_BUCKET=${WARP_LOGS_BUCKET}
14+
IBM_COS_ENDPOINT=${IBM_COS_ENDPOINT}
15+
16+
runcmd:
17+
# Schedule VM shutdown after 4 hours (240 minutes) as a safety measure
18+
- [ shutdown, -P, '+240' ]
19+
# Add ubuntu user to docker group for container access
20+
- [ usermod, -aG, docker, ubuntu ]
21+
# Enable and start Docker daemon
22+
- [ systemctl, enable, --now, docker ]
23+
# Install Slack webhook package globally for the notifier script
24+
- [ npm, -g, install, '@slack/webhook' ]
25+
# Download, extract and install AWS CLI v2
26+
- [ curl, -sS, https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip, -o, awscliv2.zip ]
27+
- [ unzip, awscliv2.zip ]
28+
- [ ./aws/install ]
29+
# Create tests directory with proper ownership and permissions
30+
- [ install, -d, -m, '755', -o, ubuntu, -g, ubuntu, /home/ubuntu/tests ]
31+
# Clone NooBaa core repository for testing
32+
- [ git, clone, https://github.com/noobaa/noobaa-core.git, /home/ubuntu/tests/noobaa-core ]
33+
# Install warp runner script to system path with proper permissions
34+
- [ install, -m, '755', -o, ubuntu, -g, ubuntu, /home/ubuntu/tests/noobaa-core/tools/ibm_runner_helpers/run_containerized_warp_on_cloud_runner.sh, /usr/local/bin/ ]
35+
# Install Slack notifier script to system path with proper permissions
36+
- [ install, -m, '755', -o, ubuntu, -g, ubuntu, /home/ubuntu/tests/noobaa-core/tools/ibm_runner_helpers/slack_notifier.js, /usr/local/bin/ ]
37+
# Execute the main warp testing script (this will run the tests and handle results)
38+
- [ /usr/local/bin/run_containerized_warp_on_cloud_runner.sh ]
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Nightly IBM Warp VM Cleanup
2+
3+
on:
4+
schedule:
5+
# Run daily at 4 AM UTC (4 hours after the nightly provisioning at midnight)
6+
- cron: '0 4 * * *'
7+
workflow_dispatch: # Allow manual triggering for on-demand cleanup
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
cleanup-ibm-vm:
14+
name: Clean up IBM Warp VM
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 10
17+
defaults:
18+
run:
19+
shell: bash -euo pipefail {0}
20+
21+
steps:
22+
- name: Install IBM Cloud CLI + VPC plugin
23+
run: |
24+
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh >/dev/null
25+
ibmcloud plugin install vpc-infrastructure -f >/dev/null
26+
ibmcloud --version
27+
28+
- name: Mask and export VM config from JSON secret
29+
env:
30+
IBM_WARP_VM_CONFIG: ${{ secrets.IBM_WARP_VM_CONFIG }}
31+
run: |
32+
# Parse JSON -> KEY=VALUE lines, mask each VALUE before adding to env
33+
jq -r 'to_entries[] | "\(.key)=\(.value)"' <<<"${IBM_WARP_VM_CONFIG}" |
34+
while IFS='=' read -r k v; do
35+
[ -n "$v" ] && echo "::add-mask::$v"
36+
printf '%s=%s\n' "$k" "$v" >> "${GITHUB_ENV}"
37+
done
38+
39+
- name: Authenticate with IBM Cloud
40+
env:
41+
IBM_CLOUD_API_KEY: ${{ secrets.IBM_CLOUD_API_KEY }}
42+
run: |
43+
ibmcloud login --apikey "${IBM_CLOUD_API_KEY}" -r "${REGION}" >/dev/null
44+
ibmcloud target -r "${REGION}" >/dev/null
45+
46+
- name: Clean up floating IPs
47+
run: |
48+
echo "🔍 Looking for floating IP"
49+
FLOATING_IP_ID=$(ibmcloud is floating-ips --output json | jq -r --arg name "${FLOATING_IP_NAME}" '.[] | select(.name == $name) | .id' | head -n1)
50+
51+
if [ -n "${FLOATING_IP_ID}" ] && [ "${FLOATING_IP_ID}" != "null" ]; then
52+
echo "🗑️ Releasing floating IP"
53+
ibmcloud is floating-ip-release "${FLOATING_IP_ID}" --force >/dev/null
54+
echo "✅ Floating IP released successfully"
55+
else
56+
echo "ℹ️ No floating IP found"
57+
fi
58+
59+
- name: Clean up IBM VM
60+
run: |
61+
echo "🔍 Looking for IBM VM to delete..."
62+
INSTANCE_ID=$(ibmcloud is instances --output json | jq -r --arg name "${INSTANCE_NAME}" '.[] | select(.name == $name) | .id')
63+
64+
if [ -z "${INSTANCE_ID}" ] || [ "${INSTANCE_ID}" = "null" ]; then
65+
echo "⚠️ No VM found with name"
66+
echo "This might be expected if the VM was already deleted or never created."
67+
exit 0
68+
fi
69+
70+
echo "🔎 Found VM"
71+
echo "🗑️ Deleting IBM VM..."
72+
ibmcloud is instance-delete "${INSTANCE_ID}" --force >/dev/null
73+
echo "✅ IBM VM deleted successfully"
74+
75+
# Wait and verify deletion
76+
sleep 10
77+
VERIFY_ID=$(ibmcloud is instances --output json | jq -r --arg name "${INSTANCE_NAME}" '.[] | select(.name == $name) | .id' 2>/dev/null || echo "")
78+
79+
if [ -z "${VERIFY_ID}" ] || [ "${VERIFY_ID}" = "null" ]; then
80+
echo "✅ Verified: VM has been completely removed"
81+
else
82+
echo "⚠️ VM deletion initiated but may still be in progress"
83+
fi
84+
85+
- name: Workflow cleanup
86+
if: always()
87+
run: |
88+
# Logout from IBM Cloud
89+
ibmcloud logout > /dev/null 2>&1 || true
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Nightly Warp IBM VM Provisioning
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' # Midnight UTC
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read # required for actions/checkout
10+
11+
jobs:
12+
provision-ibm-vm:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 10
15+
defaults:
16+
run:
17+
shell: bash -euo pipefail {0}
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Install IBM Cloud CLI + VPC plugin
24+
run: |
25+
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh >/dev/null
26+
ibmcloud plugin install vpc-infrastructure -f >/dev/null
27+
ibmcloud --version
28+
29+
- name: Mask and export VM config from JSON secret
30+
env:
31+
IBM_WARP_VM_CONFIG: ${{ secrets.IBM_WARP_VM_CONFIG }}
32+
run: |
33+
# Parse JSON -> KEY=VALUE lines, mask each VALUE before adding to env
34+
jq -r 'to_entries[] | "\(.key)=\(.value)"' <<<"${IBM_WARP_VM_CONFIG}" |
35+
while IFS='=' read -r k v; do
36+
[ -n "$v" ] && echo "::add-mask::$v"
37+
printf '%s=%s\n' "$k" "$v" >> "${GITHUB_ENV}"
38+
done
39+
40+
- name: Authenticate with IBM Cloud
41+
env:
42+
IBM_CLOUD_API_KEY: ${{ secrets.IBM_CLOUD_API_KEY }}
43+
run: |
44+
ibmcloud login --apikey "${IBM_CLOUD_API_KEY}" -r "${REGION}" >/dev/null
45+
ibmcloud target -r "${REGION}" >/dev/null
46+
47+
- name: Extract IBM COS credentials from JSON secret
48+
env:
49+
IBM_COS_WRITER_CREDENTIALS: ${{ secrets.IBM_COS_WRITER_CREDENTIALS }}
50+
run: |
51+
# Parse JSON -> KEY=VALUE lines, mask each VALUE before adding to env
52+
jq -r 'to_entries[] | "\(.key)=\(.value)"' <<<"${IBM_COS_WRITER_CREDENTIALS}" |
53+
while IFS='=' read -r k v; do
54+
[ -n "$v" ] && echo "::add-mask::$v"
55+
printf '%s=%s\n' "$k" "$v" >> "${GITHUB_ENV}"
56+
done
57+
58+
- name: Create user-data with secrets
59+
env:
60+
SLACK_NIGHTLY_RESULTS_URL: ${{ secrets.SLACK_NIGHTLY_RESULTS_URL }}
61+
run: |
62+
# Mask sensitive values
63+
[ -n "${SLACK_NIGHTLY_RESULTS_URL:-}" ] && echo "::add-mask::$SLACK_NIGHTLY_RESULTS_URL"
64+
export SLACK_NIGHTLY_RESULTS_URL
65+
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY WARP_LOGS_BUCKET IBM_COS_ENDPOINT
66+
67+
# Use envsubst to replace variables in the config
68+
envsubst < .github/ibm-warp-runner-config.yaml > /tmp/ibm-warp-runner-config-with-secrets.yaml
69+
70+
- name: Provision IBM VM
71+
run: |
72+
if ! ibmcloud is instance-create \
73+
"${INSTANCE_NAME}" \
74+
"${VPC_NAME}" \
75+
"${ZONE}" \
76+
"${INSTANCE_PROFILE}" \
77+
"${SUBNET_ID}" \
78+
--image "${IMAGE_ID}" \
79+
--sgs "${SECURITY_GROUP_ID}" \
80+
--user-data @/tmp/ibm-warp-runner-config-with-secrets.yaml \
81+
> /dev/null 2>&1
82+
then
83+
echo "❌ Failed to provision IBM VM"
84+
exit 1
85+
fi
86+
echo "✅ IBM VM provisioned successfully"
87+
88+
- name: Reserve and bind a floating IP
89+
run: |
90+
91+
VM_JSON=$(ibmcloud is instance "${INSTANCE_NAME}" --output json)
92+
NIC_ID=$(echo "${VM_JSON}" | jq -r '.primary_network_attachment.virtual_network_interface.id')
93+
94+
# Reserve a floating IP in the same zone as the VM
95+
if ! ibmcloud is floating-ip-reserve \
96+
"${FLOATING_IP_NAME}" \
97+
--nic "${NIC_ID}" \
98+
> /dev/null 2>&1
99+
then
100+
echo "❌ Failed to reserve and bind floating IP"
101+
exit 1
102+
fi
103+
echo "✅ Floating IP reserved and bound successfully"
104+
105+
- name: Cleanup
106+
if: always()
107+
run: |
108+
# Remove temporary user-data file
109+
rm -f /tmp/ibm-warp-runner-config-with-secrets.yaml
110+
# Logout from IBM Cloud
111+
ibmcloud logout > /dev/null 2>&1 || true

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,15 @@ test-warp: tester
357357
@$(call create_docker_network)
358358
@$(call run_postgres)
359359
@echo "\033[1;34mRunning warp tests\033[0m"
360-
$(CONTAINER_ENGINE) run $(CPUSET) --privileged --user root --network noobaa-net --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" --env "POSTGRES_HOST=coretest-postgres-$(GIT_COMMIT)-$(NAME_POSTFIX)" --env "POSTGRES_USER=noobaa" --env "DB_TYPE=postgres" --env "POSTGRES_DBNAME=coretest" -v $(PWD)/logs:/logs $(TESTER_TAG) "./src/test/external_tests/warp/run_warp_on_test_container.sh"
360+
$(CONTAINER_ENGINE) run $(CPUSET) --privileged --user root --network noobaa-net --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" --env "POSTGRES_HOST=coretest-postgres-$(GIT_COMMIT)-$(NAME_POSTFIX)" --env "POSTGRES_USER=noobaa" --env "DB_TYPE=postgres" --env "POSTGRES_DBNAME=coretest" -v $(PWD)/logs:/logs $(TESTER_TAG) bash -c "./src/test/external_tests/warp/run_warp_on_test_container.sh $(WARP_ARGS)"
361361
@$(call stop_noobaa)
362362
@$(call stop_postgres)
363363
@$(call remove_docker_network)
364364
.PHONY: test-warp
365365

366366
test-nc-warp: tester
367367
@echo "\033[1;34mRunning warp tests on NC environment\033[0m"
368-
$(CONTAINER_ENGINE) run $(CPUSET) --privileged --user root --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" -v $(PWD)/logs:/logs $(TESTER_TAG) "./src/test/external_tests/warp/run_nc_warp_on_test_container.sh"
368+
$(CONTAINER_ENGINE) run $(CPUSET) --privileged --user root --name noobaa_$(GIT_COMMIT)_$(NAME_POSTFIX) --env "SUPPRESS_LOGS=$(SUPPRESS_LOGS)" -v $(PWD)/logs:/logs $(TESTER_TAG) bash -c "./src/test/external_tests/warp/run_nc_warp_on_test_container.sh $(WARP_ARGS)"
369369
.PHONY: test-nc-warp
370370

371371
test-mint: tester

0 commit comments

Comments
 (0)