|
| 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 |
0 commit comments