Skip to content

Commit 792b094

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

File tree

10 files changed

+493
-6
lines changed

10 files changed

+493
-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: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
# Mask non-empty values
33+
jq -r 'to_entries[] | select(.value != "") | "::add-mask::\(.value)"' <<<"${IBM_WARP_VM_CONFIG}"
34+
# Append KEY=VALUE lines to GITHUB_ENV
35+
jq -r 'to_entries[] | "\(.key)=\(.value)"' <<<"${IBM_WARP_VM_CONFIG}" >>"$GITHUB_ENV"
36+
37+
38+
- name: Authenticate with IBM Cloud
39+
env:
40+
IBM_CLOUD_API_KEY: ${{ secrets.IBM_CLOUD_API_KEY }}
41+
run: |
42+
ibmcloud login --apikey "${IBM_CLOUD_API_KEY}" -r "${REGION}" >/dev/null
43+
ibmcloud target -r "${REGION}" >/dev/null
44+
45+
- name: Clean up floating IPs
46+
run: |
47+
echo "🔍 Looking for floating IP"
48+
FLOATING_IP_ID=$(ibmcloud is floating-ips --output json | jq -r --arg name "${FLOATING_IP_NAME}" '.[] | select(.name == $name) | .id' | head -n1)
49+
50+
if [ -n "${FLOATING_IP_ID}" ] && [ "${FLOATING_IP_ID}" != "null" ]; then
51+
echo "🗑️ Releasing floating IP"
52+
ibmcloud is floating-ip-release "${FLOATING_IP_ID}" --force >/dev/null
53+
echo "✅ Floating IP released successfully"
54+
else
55+
echo "ℹ️ No floating IP found"
56+
fi
57+
58+
- name: Clean up IBM VM
59+
run: |
60+
echo "🔍 Looking for IBM VM to delete..."
61+
INSTANCE_ID=$(ibmcloud is instances --output json | jq -r --arg name "${INSTANCE_NAME}" '.[] | select(.name == $name) | .id')
62+
63+
if [ -z "${INSTANCE_ID}" ] || [ "${INSTANCE_ID}" = "null" ]; then
64+
echo "⚠️ No VM found with name"
65+
echo "This might be expected if the VM was already deleted or never created."
66+
exit 0
67+
fi
68+
69+
echo "🔎 Found VM"
70+
echo "🗑️ Deleting IBM VM..."
71+
ibmcloud is instance-delete "${INSTANCE_ID}" --force >/dev/null
72+
echo "✅ IBM VM deleted successfully"
73+
74+
# Wait and verify deletion
75+
sleep 10
76+
VERIFY_ID=$(ibmcloud is instances --output json | jq -r --arg name "${INSTANCE_NAME}" '.[] | select(.name == $name) | .id' 2>/dev/null || echo "")
77+
78+
if [ -z "${VERIFY_ID}" ] || [ "${VERIFY_ID}" = "null" ]; then
79+
echo "✅ Verified: VM has been completely removed"
80+
else
81+
echo "⚠️ VM deletion initiated but may still be in progress"
82+
fi
83+
84+
- name: Workflow cleanup
85+
if: always()
86+
run: |
87+
# Logout from IBM Cloud
88+
ibmcloud logout > /dev/null 2>&1 || true
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
# Mask non-empty values
34+
jq -r 'to_entries[] | select(.value != "") | "::add-mask::\(.value)"' <<<"${IBM_WARP_VM_CONFIG}"
35+
# Append KEY=VALUE lines to GITHUB_ENV
36+
jq -r 'to_entries[] | "\(.key)=\(.value)"' <<<"${IBM_WARP_VM_CONFIG}" >>"$GITHUB_ENV"
37+
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: Extract IBM COS credentials from JSON secret
47+
env:
48+
IBM_COS_WRITER_CREDENTIALS: ${{ secrets.IBM_COS_WRITER_CREDENTIALS }}
49+
run: |
50+
# Mask non-empty values
51+
jq -r 'to_entries[] | select(.value != "") | "::add-mask::\(.value)"' <<<"${IBM_COS_WRITER_CREDENTIALS}"
52+
# Append KEY=VALUE lines to GITHUB_ENV
53+
jq -r 'to_entries[] | "\(.key)=\(.value)"' <<<"${IBM_COS_WRITER_CREDENTIALS}" >>"$GITHUB_ENV"
54+
55+
56+
- name: Create user-data with secrets
57+
env:
58+
SLACK_NIGHTLY_RESULTS_URL: ${{ secrets.SLACK_NIGHTLY_RESULTS_URL }}
59+
run: |
60+
# Mask sensitive values
61+
[ -n "${SLACK_NIGHTLY_RESULTS_URL:-}" ] && echo "::add-mask::$SLACK_NIGHTLY_RESULTS_URL"
62+
export SLACK_NIGHTLY_RESULTS_URL
63+
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY WARP_LOGS_BUCKET IBM_COS_ENDPOINT
64+
65+
# Use envsubst to replace variables in the config
66+
envsubst < .github/ibm-warp-runner-config.yaml > /tmp/ibm-warp-runner-config-with-secrets.yaml
67+
68+
- name: Provision IBM VM
69+
run: |
70+
if ! ibmcloud is instance-create \
71+
"${INSTANCE_NAME}" \
72+
"${VPC_NAME}" \
73+
"${ZONE}" \
74+
"${INSTANCE_PROFILE}" \
75+
"${SUBNET_ID}" \
76+
--image "${IMAGE_ID}" \
77+
--sgs "${SECURITY_GROUP_ID}" \
78+
--user-data @/tmp/ibm-warp-runner-config-with-secrets.yaml \
79+
> /dev/null 2>&1
80+
then
81+
echo "❌ Failed to provision IBM VM"
82+
exit 1
83+
fi
84+
echo "✅ IBM VM provisioned successfully"
85+
86+
- name: Reserve and bind a floating IP
87+
run: |
88+
89+
VM_JSON=$(ibmcloud is instance "${INSTANCE_NAME}" --output json)
90+
NIC_ID=$(echo "${VM_JSON}" | jq -r '.primary_network_attachment.virtual_network_interface.id')
91+
92+
# Reserve a floating IP in the same zone as the VM
93+
if ! ibmcloud is floating-ip-reserve \
94+
"${FLOATING_IP_NAME}" \
95+
--nic "${NIC_ID}" \
96+
> /dev/null 2>&1
97+
then
98+
echo "❌ Failed to reserve and bind floating IP"
99+
exit 1
100+
fi
101+
echo "✅ Floating IP reserved and bound successfully"
102+
103+
- name: Cleanup
104+
if: always()
105+
run: |
106+
# Remove temporary user-data file
107+
rm -f /tmp/ibm-warp-runner-config-with-secrets.yaml
108+
# Logout from IBM Cloud
109+
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)