Skip to content

Commit de34c0e

Browse files
committed
debug vault daemon in CI
1 parent ba8a0dd commit de34c0e

3 files changed

Lines changed: 72 additions & 18 deletions

File tree

.github/workflows/build_and_test.yaml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ jobs:
1919
include:
2020
- python-version-short: "3.9"
2121
python-version: 3.9.21
22+
consul-version: "1.22.7-1"
2223
vault-version: "2.0.0-1"
2324
hvac-gh-tag: "v2.4.0"
2425
- python-version-short: "3.10"
2526
python-version: 3.10.16
27+
consul-version: "1.22.7-1"
2628
vault-version: "2.0.0-1"
2729
hvac-gh-tag: "v2.4.0"
2830
- python-version-short: "3.11"
2931
python-version: 3.11.11
32+
consul-version: "1.22.7-1"
3033
vault-version: "2.0.0-1"
3134
hvac-gh-tag: "v2.4.0"
3235
steps:
@@ -59,22 +62,7 @@ jobs:
5962
working-directory: pack
6063
shell: bash
6164
run: |
62-
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/hashicorp.gpg
63-
echo "deb [arch=amd64, signed-by=/etc/apt/trusted.gpg.d/hashicorp.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" \
64-
| sudo tee /etc/apt/sources.list.d/hashicorp.list
65-
66-
sudo apt update \
67-
-o Dir::Etc::sourceparts="-" \
68-
-o APT::Get::List-Cleanup="0" \
69-
-o Dir::Etc::sourcelist="sources.list.d/hashicorp.list"
70-
71-
sudo apt install consul vault=${{ matrix.vault-version }}
72-
73-
# We disble cap_ipc_lock here as its generally incompatabile with GitHub
74-
# Actions' runtime environments.
75-
sudo setcap cap_ipc_lock= /usr/bin/vault
76-
sudo systemctl restart consul vault
77-
sudo systemctl status consul vault
65+
${ROOT_DIR}/tests/scripts/install_vault ${{ matrix.vault-version }} ${{ matrix.consul-version }}
7866
7967
- name: Setup hvac symlinks
8068
shell: bash
@@ -94,6 +82,10 @@ jobs:
9482
9583
- name: Run pack tests
9684
uses: StackStorm-Exchange/ci/.github/actions/test@master
85+
env:
86+
VAULT_ADDR: "https://127.0.0.1:8200"
87+
VAULT_TOKEN: "root"
88+
VAULT_CACERT: "/home/vault/vault-ca.pem"
9789
with:
9890
enable-common-libs: false
9991

tests/scripts/install_vault

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
5+
# Installing consul and vault in the CI/CD environment is complex. That
6+
# complexity is now wrapped inside this shell script for a clearer CI/CD YAML.
7+
8+
VAULT_VERSION="$1"
9+
CONSUL_VERSION="$2"
10+
11+
# Get the hashicorp public signing key for the APT repo.
12+
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/hashicorp.gpg
13+
14+
# Configure the APT source list to trust the signing key
15+
sudo tee /etc/apt/sources.list.d/hashicorp.list <<<"deb [arch=amd64, signed-by=/etc/apt/trusted.gpg.d/hashicorp.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
16+
17+
# Update the package list
18+
sudo apt update -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0" -o Dir::Etc::sourcelist="sources.list.d/hashicorp.list"
19+
20+
# Install Vault and Consul
21+
#~ sudo apt install consul=${CONSUL_VERSION} vault=${VAULT_VERSION}
22+
sudo apt install vault=${VAULT_VERSION}
23+
24+
# We disble cap_ipc_lock here as its generally incompatabile with GitHub Actions' runtime environments.
25+
sudo setcap cap_ipc_lock= /usr/bin/vault
26+
27+
#~ # Consul needs to be explicitly configured to start in the CI/CD environment.
28+
#~ sudo mkdir -p /srv/consul && sudo chown -R consul:consul /srv/consul
29+
30+
#~ sudo tee /etc/consul.d/consul.hcl >/dev/null <<EOF
31+
#~ enable_debug = false
32+
#~ datacenter = "cicd"
33+
#~ data_dir = "/srv/consul"
34+
#~ ui_config{
35+
#~ enabled = false
36+
#~ }
37+
#~ server = true
38+
#~ bind_addr = "127.0.0.1"
39+
#~ client_addr = "127.0.0.1"
40+
#~ advertise_addr = "127.0.0.1"
41+
#~ retry_join = ["localhost"]
42+
#~ bootstrap_expect = 0
43+
#~ encrypt = "katpv2wgyY5Za8bGAHh7+URaeLJWh4g+gK0GBjmvQXA="
44+
#~ EOF
45+
46+
#~ sudo systemctl restart consul
47+
48+
# Run Vault dev instance for tests
49+
sudo mkdir -p /home/vault /etc/systemd/system/vault.service.d
50+
sudo chown -R vault:vault /home/vault
51+
52+
sudo tee /etc/systemd/system/vault.service.d/override.conf >/dev/null <<EOF
53+
[Service]
54+
ExecStart=
55+
ExecStart=/usr/bin/vault server -dev -dev-root-token-id root -dev-tls -dev-tls-cert-dir=/home/vault
56+
ProtectHome=no
57+
EOF
58+
sudo systemctl daemon-reload
59+
sudo systemctl restart vault

tests/vault_action_tests_base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from st2tests.base import BaseActionTestCase
22

3-
from tests.utils import get_config_file_path
3+
# #from tests.utils import get_config_file_path
44
from tests.utils.hvac_integration_test_case import HvacIntegrationTestCase
55

66

@@ -59,9 +59,12 @@ def tearDown(self):
5959

6060
def build_dummy_pack_config(self, url="https://localhost:8200"):
6161
# based on create_client() in hvac/tests/utils/__init__.py
62-
server_cert_path = get_config_file_path("server-cert.pem")
62+
# CI/CD only has a self-signed cert.
63+
# #server_cert_path = get_config_file_path("server-cert.pem")
64+
server_cert_path = False
6365

6466
token_result = self.client.auth.token.create(ttl=self.default_token_lease)
67+
print(f"token_result: {token_result}")
6568
token = token_result["auth"]["client_token"]
6669

6770
dummy_pack_config = {

0 commit comments

Comments
 (0)