blob: 7d53ab801c3bc16a7dfaee41002714bf5fc64126 [file]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: Setup Cloudstack
inputs:
cloudstack-version:
description: 'Cloudstack version'
required: true
outputs:
CLOUDSTACK_USER_ID:
description: 'Cloudstack user id'
value: ${{ steps.setup-cloudstack.outputs.user_id }}
CLOUDSTACK_API_KEY:
description: 'Cloudstack api key'
value: ${{ steps.setup-cloudstack.outputs.api_key }}
CLOUDSTACK_SECRET_KEY:
description: 'Cloudstack secret key'
value: ${{ steps.setup-cloudstack.outputs.secret_key }}
CLOUDSTACK_API_URL:
description: 'Cloudstack API URL'
value: http://localhost:8080/client/api
runs:
using: composite
steps:
- name: Wait Cloudstack to be ready
shell: bash
run: |
echo "Starting Cloudstack health check"
T=0
until [ $T -gt 20 ] || curl -sfL http://localhost:8080 --output /dev/null
do
echo "Waiting for Cloudstack to be ready..."
((T+=1))
sleep 30
done
# After loop, check if Cloudstack is up
if ! curl -sfSL http://localhost:8080 --output /dev/null; then
echo "Cloudstack did not become ready in time"
curl -v http://localhost:8080 || true
exit 22
fi
- name: Setting up Cloudstack
id: setup-cloudstack
shell: bash
run: |
set -euo pipefail
echo "Deploying Data Center..."
docker exec $(docker container ls --format=json -l | jq -r .ID) \
python /root/tools/marvin/marvin/deployDataCenter.py -i /root/setup/dev/advanced.cfg
# Get the container ID of the running simulator
CONTAINER_ID=$(docker ps --filter "ancestor=apache/cloudstack-simulator:${{ matrix.cloudstack-version }}" --format "{{.ID}}" | head -n1)
# Install CloudMonkey
docker exec $CONTAINER_ID bash -c "curl -sfSL https://github.com/apache/cloudstack-cloudmonkey/releases/download/6.4.0/cmk.linux.x86-64 -o /usr/local/bin/cmk && chmod +x /usr/local/bin/cmk"
# Write the CloudMonkey config file with a profile using user/pass
docker exec $CONTAINER_ID mkdir -p /root/.cmk
docker exec $CONTAINER_ID bash -c "printf '[core]\nprofile = localcloud\n\n[localcloud]\nurl = http://localhost:8080/client/api\nusername = admin\npassword = password\ndomain = /\napikey =\nsecretkey =\ntimeout = 3600\n' > /root/.cmk/config"
# Use CloudMonkey with the profile to list users and extract API key/secret key
docker exec $CONTAINER_ID cmk -p localcloud list users --output json > users.json
# Generate API keys
docker exec $CONTAINER_ID cmk -p localcloud registeruserKeys id=$(jq -r '.user[0].id' users.json) > api.json
# Extract the first user's keys (assuming admin is first)
CLOUDSTACK_API_KEY=$(jq -r '.userkeys.apikey' api.json)
CLOUDSTACK_SECRET_KEY=$(jq -r '.userkeys.secretkey' api.json)
CLOUDSTACK_USER_ID=$(jq -r '.user[0].id' users.json)
echo "::add-mask::$CLOUDSTACK_API_KEY"
echo "::add-mask::$CLOUDSTACK_SECRET_KEY"
echo "user_id=$CLOUDSTACK_USER_ID" >> $GITHUB_OUTPUT
echo "api_key=$CLOUDSTACK_API_KEY" >> $GITHUB_OUTPUT
echo "secret_key=$CLOUDSTACK_SECRET_KEY" >> $GITHUB_OUTPUT
- name: Install CMK
shell: bash
run: |
curl -sfSL https://github.com/apache/cloudstack-cloudmonkey/releases/download/6.4.0/cmk.linux.x86-64 -o /usr/local/bin/cmk
chmod +x /usr/local/bin/cmk
- name: Create extra resources
shell: bash
run: |
cmk -u $CLOUDSTACK_API_URL -k $CLOUDSTACK_API_KEY -s $CLOUDSTACK_SECRET_KEY -o json create project name=terraform displaytext=terraform