Skip to content

Commit c649abf

Browse files
committed
Set authorized keys for deployment (if set)
1 parent f260548 commit c649abf

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/actions/deploy.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,22 @@ action_deploy() {
239239
--extra-vars @./.spin.yml \
240240
--extra-vars "spin_environment=$deployment_environment" \
241241
--extra-vars "spin_ci_folder=$SPIN_CI_FOLDER" \
242-
--tags "get-host" \
242+
--tags "get-host,get-authorized-keys" \
243243
"${SPIN_ANSIBLE_ARGS[@]}" \
244244
"${SPIN_UNPROCESSED_ARGS[@]}"
245245

246246
docker_swarm_manager=$(cat "$SPIN_CI_FOLDER/${deployment_environment_uppercase}_SSH_REMOTE_HOSTNAME")
247247

248+
# Read and export authorized keys
249+
if [[ -f "$SPIN_CI_FOLDER/AUTHORIZED_KEYS" ]]; then
250+
# Read the file content and escape newlines for Docker
251+
AUTHORIZED_KEYS=$(awk 1 ORS='\\n' "$SPIN_CI_FOLDER/AUTHORIZED_KEYS" | sed 's/\\n$//')
252+
export AUTHORIZED_KEYS
253+
echo "${BOLD}${BLUE}🔑 Authorized keys loaded and exported as AUTHORIZED_KEYS${RESET}"
254+
else
255+
echo "${BOLD}${YELLOW}⚠️ Warning: No AUTHORIZED_KEYS file found in $SPIN_CI_FOLDER${RESET}"
256+
fi
257+
248258
if [ $? -ne 0 ] || [ -z "$docker_swarm_manager" ]; then
249259
echo "${BOLD}${RED}❌ Error: Failed to get a valid swarm manager host for group '$deployment_environment'.${RESET}" >&2
250260
exit 1

0 commit comments

Comments
 (0)