|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +name: CI |
| 19 | + |
| 20 | +on: |
| 21 | + push: |
| 22 | + branches: ["main"] |
| 23 | + pull_request: |
| 24 | + branches: ["main"] |
| 25 | + |
| 26 | +permissions: |
| 27 | + contents: read |
| 28 | + |
| 29 | +env: |
| 30 | + CLOUDSTACK_API_URL: http://localhost:8080/client/api |
| 31 | + |
| 32 | +jobs: |
| 33 | + build: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + services: |
| 36 | + cloudstack-simulator: |
| 37 | + image: apache/cloudstack-simulator:4.20.0.0 |
| 38 | + ports: |
| 39 | + - 8080:5050 |
| 40 | + options: >- |
| 41 | + --health-cmd "curl -f http://localhost:5050 || exit 1" |
| 42 | + --health-interval 30s |
| 43 | + --health-timeout 10s |
| 44 | + --health-retries 5 |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v4 |
| 47 | + |
| 48 | + - name: Setup Go Environment & build code & mocks |
| 49 | + uses: ./.github/actions/setup-go-and-build |
| 50 | + |
| 51 | + - name: Set up CloudStack |
| 52 | + id: setup-cloudstack |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + set -e |
| 56 | +
|
| 57 | + # Deploy datacenter configuration |
| 58 | + container_id=$(docker container ls --format=json -l | jq -r .ID) |
| 59 | + if [ -z "$container_id" ] || [ "$container_id" = "null" ]; then |
| 60 | + echo "Failed to get CloudStack container ID" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + echo "Deploying CloudStack datacenter configuration..." |
| 65 | + docker exec "$container_id" python /root/tools/marvin/marvin/deployDataCenter.py -i /root/setup/dev/advanced.cfg |
| 66 | +
|
| 67 | + # Login and get API credentials |
| 68 | + echo "Logging into CloudStack..." |
| 69 | + session_key=$(curl -sf --location "${CLOUDSTACK_API_URL}" \ |
| 70 | + --header 'Content-Type: application/x-www-form-urlencoded' \ |
| 71 | + --data-urlencode 'command=login' \ |
| 72 | + --data-urlencode 'username=admin' \ |
| 73 | + --data-urlencode 'password=password' \ |
| 74 | + --data-urlencode 'response=json' \ |
| 75 | + --data-urlencode 'domain=/' -j -c cookies.txt | jq -r ".loginresponse.sessionkey") |
| 76 | +
|
| 77 | +
|
| 78 | + echo "::add-mask::$session_key" # Mask the session key |
| 79 | +
|
| 80 | + echo "Retrieving API keys..." |
| 81 | + CLOUDSTACK_USER_ID=$(curl -fs "${CLOUDSTACK_API_URL}?command=listUsers&response=json&sessionkey=${session_key}" -b cookies.txt | jq -r '.listusersresponse.user[0].id') |
| 82 | + api_key=$(curl -s "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json&sessionkey=${session_key}" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.apikey') |
| 83 | + secret_key=$(curl -fs "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json&sessionkey=${session_key}" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.secretkey') |
| 84 | +
|
| 85 | +
|
| 86 | + echo "::add-mask::$api_key" # Mask the API key |
| 87 | + echo "::add-mask::$secret_key" # Mask the secret key |
| 88 | +
|
| 89 | + echo "CLOUDSTACK_API_KEY=$api_key" >> $GITHUB_OUTPUT |
| 90 | + echo "CLOUDSTACK_SECRET_KEY=$secret_key" >> $GITHUB_OUTPUT |
| 91 | +
|
| 92 | + - name: Run tests |
| 93 | + run: | |
| 94 | + go test -v -timeout=30m ./ci/... |
| 95 | + env: |
| 96 | + CLOUDSTACK_API_URL: ${{ env.CLOUDSTACK_API_URL }} |
| 97 | + CLOUDSTACK_API_KEY: ${{ steps.setup-cloudstack.outputs.CLOUDSTACK_API_KEY }} |
| 98 | + CLOUDSTACK_SECRET_KEY: ${{ steps.setup-cloudstack.outputs.CLOUDSTACK_SECRET_KEY }} |
0 commit comments