Skip to content

Commit cbff4f4

Browse files
ci: add reusable cloudstack-setup action
1 parent 6a17bd9 commit cbff4f4

File tree

2 files changed

+111
-46
lines changed

2 files changed

+111
-46
lines changed

.github/workflows/acceptance.yml

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,61 +34,45 @@ concurrency:
3434
permissions:
3535
contents: read
3636

37+
env:
38+
CLOUDSTACK_API_URL: http://localhost:8080/client/api
39+
CLOUDSTACK_VERSIONS: "['4.18.2.0', '4.19.0.1']"
40+
3741
jobs:
38-
acceptance:
39-
name: Acceptance Tests (Terraform ${{ matrix.terraform-version }}, Cloudstack ${{ matrix.cloudstack-version }})
40-
runs-on: ubuntu-22.04
41-
env:
42-
CLOUDSTACK_API_URL: http://localhost:8080/client/api
42+
prepare-matrix:
43+
runs-on: ubuntu-latest
44+
outputs:
45+
cloudstack-versions: ${{ steps.set-versions.outputs.cloudstack-versions }}
46+
steps:
47+
- name: Set versions
48+
id: set-versions
49+
run: |
50+
echo "cloudstack-versions=${{ env.CLOUDSTACK_VERSIONS }}" >> $GITHUB_OUTPUT
51+
52+
acceptance-terraform:
53+
name: Acceptance Tests - Terraform ${{ matrix.terraform-version }}, Cloudstack ${{ matrix.cloudstack-version }}
54+
needs: [prepare-matrix]
55+
runs-on: ubuntu-latest
4356
steps:
4457
- uses: actions/checkout@v3
4558
- name: Set up Go
4659
uses: actions/setup-go@v3
4760
with:
4861
go-version-file: 'go.mod'
49-
- name: Wait Cloudstack to be ready
50-
run: |
51-
echo "Starting Cloudstack health check"
52-
T=0
53-
until [ $T -gt 20 ] || curl -sfL http://localhost:8080 --output /dev/null
54-
do
55-
echo "Waiting for Cloudstack to be ready..."
56-
((T+=1))
57-
sleep 30
58-
done
59-
- name: Setting up Cloudstack
60-
run: |
61-
docker exec $(docker container ls --format=json -l | jq -r .ID) python /root/tools/marvin/marvin/deployDataCenter.py -i /root/setup/dev/advanced.cfg
62-
curl -sf --location "${CLOUDSTACK_API_URL}" \
63-
--header 'Content-Type: application/x-www-form-urlencoded' \
64-
--data-urlencode 'command=login' \
65-
--data-urlencode 'username=admin' \
66-
--data-urlencode 'password=password' \
67-
--data-urlencode 'response=json' \
68-
--data-urlencode 'domain=/' -j -c cookies.txt --output /dev/null
69-
70-
CLOUDSTACK_USER_ID=$(curl -fs "${CLOUDSTACK_API_URL}?command=listUsers&response=json" -b cookies.txt | jq -r '.listusersresponse.user[0].id')
71-
CLOUDSTACK_API_KEY=$(curl -s "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.apikey')
72-
CLOUDSTACK_SECRET_KEY=$(curl -fs "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.secretkey')
73-
74-
echo "::add-mask::$CLOUDSTACK_API_KEY"
75-
echo "::add-mask::$CLOUDSTACK_SECRET_KEY"
76-
77-
echo "CLOUDSTACK_API_KEY=$CLOUDSTACK_API_KEY" >> $GITHUB_ENV
78-
echo "CLOUDSTACK_SECRET_KEY=$CLOUDSTACK_SECRET_KEY" >> $GITHUB_ENV
79-
echo "CLOUDSTACK_TEMPLATE_URL=http://dl.openvm.eu/cloudstack/macchinina/x86_64/macchinina-xen.vhd.bz2" >> $GITHUB_ENV
80-
- name: Install CMK
81-
run: |
82-
curl -sfL https://github.com/apache/cloudstack-cloudmonkey/releases/download/6.3.0/cmk.linux.x86-64 -o /usr/local/bin/cmk
83-
chmod +x /usr/local/bin/cmk
84-
- name: Create extra resources
85-
run: |
86-
cmk -u $CLOUDSTACK_API_URL -k $CLOUDSTACK_API_KEY -s $CLOUDSTACK_SECRET_KEY -o json create project name=terraform displaytext=terraform
62+
- name: Setup Cloudstack v${{ matrix.cloudstack-version }}
63+
uses: ./.github/workflows/setup-cloudstack
64+
id: setup-cloudstack
65+
with:
66+
cloudstack-version: ${{ matrix.cloudstack-version }}
8767
- uses: hashicorp/setup-terraform@v3
8868
with:
8969
terraform_version: ${{ matrix.terraform-version }}
9070
terraform_wrapper: false
9171
- name: Run acceptance test
72+
env:
73+
CLOUDSTACK_USER_ID: ${{ steps.setup-cloudstack.outputs.CLOUDSTACK_USER_ID }}
74+
CLOUDSTACK_API_KEY: ${{ steps.setup-cloudstack.outputs.CLOUDSTACK_API_KEY }}
75+
CLOUDSTACK_SECRET_KEY: ${{ steps.setup-cloudstack.outputs.CLOUDSTACK_SECRET_KEY }}
9276
run: |
9377
make testacc
9478
services:
@@ -102,6 +86,4 @@ jobs:
10286
terraform-version:
10387
- '1.7.*'
10488
- '1.8.*'
105-
cloudstack-version:
106-
- 4.18.2.0
107-
- 4.19.0.1
89+
cloudstack-version: ${{ fromJson(needs.prepare-matrix.outputs.cloudstack-versions) }}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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: Setup Cloudstack
19+
20+
inputs:
21+
cloudstack-version:
22+
description: 'Cloudstack version'
23+
required: true
24+
outputs:
25+
CLOUDSTACK_USER_ID:
26+
description: 'Cloudstack user id'
27+
value: ${{ steps.setup-cloudstack.outputs.user_id }}
28+
CLOUDSTACK_API_KEY:
29+
description: 'Cloudstack api key'
30+
value: ${{ steps.setup-cloudstack.outputs.api_key }}
31+
CLOUDSTACK_SECRET_KEY:
32+
description: 'Cloudstack secret key'
33+
value: ${{ steps.setup-cloudstack.outputs.secret_key }}
34+
CLOUDSTACK_API_URL:
35+
description: 'Cloudstack API URL'
36+
value: http://localhost:8080/client/api
37+
38+
runs:
39+
using: composite
40+
steps:
41+
- name: Wait Cloudstack to be ready
42+
shell: bash
43+
run: |
44+
echo "Starting Cloudstack health check"
45+
T=0
46+
until [ $T -gt 20 ] || curl -sfL http://localhost:8080 --output /dev/null
47+
do
48+
echo "Waiting for Cloudstack to be ready..."
49+
((T+=1))
50+
sleep 30
51+
done
52+
- name: Setting up Cloudstack
53+
id: setup-cloudstack
54+
shell: bash
55+
run: |
56+
docker exec $(docker container ls --format=json -l | jq -r .ID) python /root/tools/marvin/marvin/deployDataCenter.py -i /root/setup/dev/advanced.cfg
57+
curl -sf --location "${CLOUDSTACK_API_URL}" \
58+
--header 'Content-Type: application/x-www-form-urlencoded' \
59+
--data-urlencode 'command=login' \
60+
--data-urlencode 'username=admin' \
61+
--data-urlencode 'password=password' \
62+
--data-urlencode 'response=json' \
63+
--data-urlencode 'domain=/' -j -c cookies.txt --output /dev/null
64+
65+
CLOUDSTACK_USER_ID=$(curl -fs "${CLOUDSTACK_API_URL}?command=listUsers&response=json" -b cookies.txt | jq -r '.listusersresponse.user[0].id')
66+
CLOUDSTACK_API_KEY=$(curl -s "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.apikey')
67+
CLOUDSTACK_SECRET_KEY=$(curl -fs "${CLOUDSTACK_API_URL}?command=getUserKeys&id=${CLOUDSTACK_USER_ID}&response=json" -b cookies.txt | jq -r '.getuserkeysresponse.userkeys.secretkey')
68+
69+
echo "::add-mask::$CLOUDSTACK_API_KEY"
70+
echo "::add-mask::$CLOUDSTACK_SECRET_KEY"
71+
72+
echo "user_id=$CLOUDSTACK_USER_ID" >> $GITHUB_OUTPUT
73+
echo "api_key=$CLOUDSTACK_API_KEY" >> $GITHUB_OUTPUT
74+
echo "secret_key=$CLOUDSTACK_SECRET_KEY" >> $GITHUB_OUTPUT
75+
- name: Install CMK
76+
shell: bash
77+
run: |
78+
curl -sfL https://github.com/apache/cloudstack-cloudmonkey/releases/download/6.3.0/cmk.linux.x86-64 -o /usr/local/bin/cmk
79+
chmod +x /usr/local/bin/cmk
80+
- name: Create extra resources
81+
shell: bash
82+
run: |
83+
cmk -u $CLOUDSTACK_API_URL -k $CLOUDSTACK_API_KEY -s $CLOUDSTACK_SECRET_KEY -o json create project name=terraform displaytext=terraform

0 commit comments

Comments
 (0)