mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Deploy cloud-init script to S3 for following usage
This commit is contained in:
parent
5f9704a3c1
commit
b4cc55ea34
1
tests/ci/worker/.gitignore
vendored
Normal file
1
tests/ci/worker/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
generated_*init_runner.sh
|
85
tests/ci/worker/deploy-runner-init.sh
Executable file
85
tests/ci/worker/deploy-runner-init.sh
Executable file
@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 ENVIRONMENT" >&2
|
||||
echo "Valid values for ENVIRONMENT: staging, production" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
staging|production)
|
||||
ENVIRONMENT="$1" ;;
|
||||
--help)
|
||||
usage ;;
|
||||
*)
|
||||
echo "Invalid argument" >&2
|
||||
usage ;;
|
||||
esac
|
||||
|
||||
cd "$(dirname "$0")" || exit 1
|
||||
SOURCE_SCRIPT='init_runner.sh'
|
||||
|
||||
check_response() {
|
||||
# Are we even in the interactive shell?
|
||||
[ -t 1 ] || return 1
|
||||
local request
|
||||
request="$1"
|
||||
read -rp "$request (y/N): " response
|
||||
case "$response" in
|
||||
[Yy])
|
||||
return 0
|
||||
# Your code to continue goes here
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
check_dirty() {
|
||||
if [ -n "$(git status --porcelain=v2 "$SOURCE_SCRIPT")" ]; then
|
||||
echo "The $SOURCE_SCRIPT has uncommited changes, won't deploy it" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
GIT_HASH=$(git log -1 --format=format:%H)
|
||||
|
||||
header() {
|
||||
cat << EOF
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo 'The $ENVIRONMENT script is generated from $SOURCE_SCRIPT, commit $GIT_HASH'
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
body() {
|
||||
local first_line
|
||||
first_line=$(sed -n '/^# THE SCRIPT START$/{=;q}' "$SOURCE_SCRIPT")
|
||||
if [ -z "$first_line" ]; then
|
||||
echo "The pattern '# THE SCRIPT START' is not found in $SOURCE_SCRIPT" >&2
|
||||
exit 1
|
||||
fi
|
||||
tail "+$first_line" "$SOURCE_SCRIPT"
|
||||
}
|
||||
|
||||
GENERATED_FILE="generated_${ENVIRONMENT}_${SOURCE_SCRIPT}"
|
||||
|
||||
{ header && body; } > "$GENERATED_FILE"
|
||||
|
||||
echo "The file $GENERATED_FILE is generated"
|
||||
|
||||
if check_response "Display the content of $GENERATED_FILE?"; then
|
||||
if [ -z "$PAGER" ]; then
|
||||
less "$GENERATED_FILE"
|
||||
else
|
||||
$PAGER "$GENERATED_FILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
check_dirty
|
||||
|
||||
S3_OBJECT=${S3_OBJECT:-s3://github-runners-data/cloud-init/${ENVIRONMENT}.sh}
|
||||
if check_response "Deploy the generated script to $S3_OBJECT?"; then
|
||||
aws s3 mv "$GENERATED_FILE" "$S3_OBJECT"
|
||||
fi
|
@ -1,4 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cat > /dev/null << 'EOF'
|
||||
The following content is embedded into the s3 object via the script
|
||||
deploy-runner-init.sh {staging,production}
|
||||
with additional helping information
|
||||
|
||||
In the `user data` you should define as the following
|
||||
with appropriate <ENVIRONMENT> as 'staging' or 'production':
|
||||
|
||||
### COPY AFTER
|
||||
Content-Type: multipart/mixed; boundary="//"
|
||||
MIME-Version: 1.0
|
||||
|
||||
--//
|
||||
Content-Type: text/cloud-config; charset="us-ascii"
|
||||
MIME-Version: 1.0
|
||||
Content-Transfer-Encoding: 7bit
|
||||
Content-Disposition: attachment; filename="cloud-config.txt"
|
||||
|
||||
#cloud-config
|
||||
cloud_final_modules:
|
||||
- [scripts-user, always]
|
||||
|
||||
--//
|
||||
Content-Type: text/x-shellscript; charset="us-ascii"
|
||||
MIME-Version: 1.0
|
||||
Content-Transfer-Encoding: 7bit
|
||||
Content-Disposition: attachment; filename="userdata.txt"
|
||||
|
||||
#!/bin/bash
|
||||
aws s3 cp s3://github-runners-data/cloud-init/<ENVIRONMENT>.sh /tmp/cloud-init.sh
|
||||
chmod 0700 /tmp/cloud-init.sh
|
||||
exec bash /tmp/cloud-init.sh
|
||||
--//
|
||||
### COPY BEFORE
|
||||
EOF
|
||||
|
||||
# THE SCRIPT START
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
####################################
|
||||
|
Loading…
Reference in New Issue
Block a user