-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·51 lines (42 loc) · 1.55 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/env bash
set -e
robot_key="${INPUT_NIXOS_ROBOT_KEY}"
deploy_service="${INPUT_NIXOS_DEPLOY_SERVICE}"
fixedhosts="${INPUT_NIXOS_DEPLOY_FIXED_HOSTS}"
fixedports="${INPUT_NIXOS_DEPLOY_FIXED_TUNNEL_PORTS}"
sshrelay_domain="${INPUT_NIXOS_DEPLOY_SSHRELAY_DOMAIN}"
sshrelay_user="${INPUT_NIXOS_DEPLOY_SSHRELAY_USER}"
sshrelay_port="${INPUT_NIXOS_DEPLOY_SSHRELAY_PORT}"
sshrelay_pubkey="${INPUT_NIXOS_DEPLOY_SSHRELAY_PUBLIC_KEY}"
umask 0077
action_dir="${GITHUB_ACTION_PATH}"
keyfile="${action_dir}/id_robot"
hostfile="${action_dir}/hosts.yml"
connection_timeout=120
echo "${robot_key}" > "${keyfile}"
chmod 0400 "${keyfile}"
mkdir --parent ~/.ssh
cat <<EOF > ~/.ssh/known_hosts
${sshrelay_domain} ${sshrelay_pubkey}
EOF
python3 "${action_dir}"/build_inventory.py \
--keyfile "${keyfile}" \
--timeout "${connection_timeout}" \
--eventlog "${GITHUB_EVENT_PATH}" \
--fixedhosts "${fixedhosts}" \
--fixedtunnelports "${fixedports}" \
--sshrelay_domain "${sshrelay_domain}" \
--sshrelay_user "${sshrelay_user}" \
--sshrelay_port "${sshrelay_port}" \
> "${hostfile}"
echo "Calling the Ansible playbook with the following inventory:"
cat "${hostfile}"
export ANSIBLE_PYTHON_INTERPRETER="auto_silent"
export ANSIBLE_HOST_KEY_CHECKING="False"
export ANSIBLE_SSH_RETRIES=5
ansible-playbook --forks 100 \
--timeout="${connection_timeout}" \
--key-file "${keyfile}" \
--inventory "${hostfile}" \
--extra-vars "nixos_deploy_service=${deploy_service}" \
"${action_dir}"/deploy.yml