Skip to content

Commit 280914f

Browse files
authored
Add mbx-ci, sdk-ci and slack installation scripts (#4)
* Add slack message templates * add scripts helpers from sdkcicd
1 parent 8a248be commit 280914f

File tree

3 files changed

+163
-0
lines changed

3 files changed

+163
-0
lines changed

install-mbx-ci.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
if [[ "${MBX_CI_ALLOW_INSTALL_FAILLURE}" == "true" ]]; then
4+
echo "WARNING: Failures allowed. Command will exit with code 0, whatever happens."
5+
fi
6+
7+
system=$(uname -s | tr '[:upper:]' '[:lower:]')
8+
arch=$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
9+
filename="mbx-ci-${system}-${arch}"
10+
target="${MBX_CI_INSTALL_DIR}/mbx-ci"
11+
12+
if [ ! -x "$target" ]; then
13+
mkdir -p "$MBX_CI_INSTALL_DIR"
14+
if ! curl -L -f --retry 3 "${MBX_CI_URL}/${filename}" -o "$target"; then
15+
if [[ "${MBX_CI_ALLOW_INSTALL_FAILLURE}" != "true" ]]; then
16+
exit 1
17+
fi
18+
fi
19+
chmod 755 "$target"
20+
else
21+
echo "mbx-ci already installed in ${MBX_CI_INSTALL_DIR}"
22+
fi
23+
24+
{
25+
echo 'export MBX_CI_DOMAIN=o619qyc20d.execute-api.us-east-1.amazonaws.com'
26+
echo 'export AWS_SDK_LOAD_CONFIG=1'
27+
echo "export PATH=\$PATH:${MBX_CI_INSTALL_DIR}"
28+
} >> "${BASH_ENV:-/tmp/bash_env}"
29+
30+
if ! source "${BASH_ENV:-/tmp/bash_env}"; then
31+
if [[ "${MBX_CI_ALLOW_INSTALL_FAILLURE}" != "true" ]]; then
32+
exit 1
33+
fi
34+
fi
35+
36+
if ! mbx-ci --version || ! mbx-ci --help; then
37+
if [[ "${MBX_CI_ALLOW_INSTALL_FAILLURE}" != "true" ]]; then
38+
exit 1
39+
fi
40+
fi
41+
42+
exit 0

install-sdk-ci.sh

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/bash
2+
3+
SDK_CI_INSTALL_STRATEGY="${SDK_CI_INSTALL_STRATEGY:-executable}"
4+
5+
if [[ "$SDK_CI_ALLOW_FAILURE" == "true" ]]; then
6+
echo "WARNING: Failures allowed. Command will exit with code 0, whatever happens."
7+
fi
8+
9+
main() {
10+
if command -v sdk-ci &>/dev/null; then
11+
echo "sdk-ci already installed"
12+
exit 0
13+
fi
14+
15+
if [[ "$SDK_CI_INSTALL_STRATEGY" == "executable" ]]; then
16+
curl -sL --retry 3 https://raw.githubusercontent.com/mapbox/sdk-cicd-public/main/download-scripts.sh | bash
17+
source $BASH_ENV
18+
19+
# Function to set PIP_PATH based on the Python command
20+
set_pip_path_from_python() {
21+
# Check if the python command has pip available
22+
if $1 -m pip --version &>/dev/null; then
23+
PIP_PATH="$1 -m pip"
24+
return 0
25+
fi
26+
return 1
27+
}
28+
29+
# Check if pip is available
30+
if command -v pip3 &>/dev/null; then
31+
PIP_PATH=$(command -v pip3)
32+
elif command -v pip &>/dev/null; then
33+
PIP_PATH=$(command -v pip)
34+
elif set_pip_path_from_python python3; then
35+
:
36+
elif set_pip_path_from_python python; then
37+
:
38+
else
39+
echo "pip is not installed and cannot be found under python or python3."
40+
fi
41+
42+
install_certifi_cmd="$PIP_PATH --disable-pip-version-check install --upgrade certifi"
43+
$install_certifi_cmd --user || $install_certifi_cmd || true
44+
45+
if (python3 "${SDK_CICD_PUBLIC_SCRIPTS_PATH}/install_cli_executable.py" \
46+
--owner mapbox \
47+
--repo sdk-cicd \
48+
--version $SDK_CI_VERSION \
49+
--token="$(mbx-ci github reader token)" \
50+
--asset_name="sdk-ci-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/').tar.gz" \
51+
--output_dir "${HOME}/sdk-ci" && source $BASH_ENV && sdk-ci --version); then
52+
exit 0
53+
else
54+
rm -rf "${HOME}/sdk-ci"
55+
echo "sdk-ci executable installation unsuccessful, fallback to installation from source"
56+
export SDK_CI_INSTALL_STRATEGY="https_api"
57+
fi
58+
fi
59+
60+
TEMP_DIR="/tmp/"
61+
62+
SDK_CI_VENV_DIR="${TEMP_DIR%/}/venv_sdk_ci"
63+
venv_create_cmd="python3 -m venv ${SDK_CI_VENV_DIR}"
64+
65+
echo "Creating venv at ${SDK_CI_VENV_DIR} ..."
66+
install_python3_venv_cmd="sudo apt-get install --no-install-recommends python3-venv -y"
67+
# Check if the virtual environment directory exists.
68+
if ! test -d "${SDK_CI_VENV_DIR}/bin/python"; then
69+
echo "Virtual environment directory does not exist. Attempting to create..."
70+
# Attempt to create the virtual environment.
71+
if ! $venv_create_cmd; then
72+
echo "Failed to create virtual environment. Trying to install python3-venv..."
73+
# Update the system's package lists.
74+
sudo apt-get update || true
75+
# Install python3-venv package.
76+
if sudo apt-get install python3-venv -y; then
77+
echo "Successfully installed python3-venv. Attempting to create virtual environment again..."
78+
# Attempt to create the virtual environment again.
79+
if ! $venv_create_cmd; then
80+
echo "Failed to create the virtual environment after installing python3-venv."
81+
else
82+
echo "Successfully created the virtual environment."
83+
fi
84+
else
85+
echo "Failed to install python3-venv."
86+
fi
87+
else
88+
echo "Virtual environment created successfully."
89+
fi
90+
else
91+
echo "Virtual environment directory already exists."
92+
fi
93+
94+
echo "Activating venv..."
95+
. $SDK_CI_VENV_DIR/bin/activate
96+
97+
pip3 --disable-pip-version-check install wheel
98+
if [[ "$SDK_CI_INSTALL_STRATEGY" == "git_ssh" ]]; then
99+
pip3 --disable-pip-version-check install git+ssh://[email protected]/mapbox/sdk-cicd.git@$SDK_CI_VERSION
100+
elif [[ "$SDK_CI_INSTALL_STRATEGY" == "git_https" ]]; then
101+
GITHUB_ACCESS_TOKEN=$(mbx-ci github reader token)
102+
pip3 --disable-pip-version-check install git+https://x-access-token:${GITHUB_ACCESS_TOKEN}@github.com/mapbox/sdk-cicd.git@$SDK_CI_VERSION
103+
elif [[ "$SDK_CI_INSTALL_STRATEGY" == "https_api" ]]; then
104+
GITHUB_ACCESS_TOKEN=$(mbx-ci github reader token)
105+
pip3 --disable-pip-version-check install https://x-access-token:${GITHUB_ACCESS_TOKEN}@api.github.com/repos/mapbox/sdk-cicd/tarball/$SDK_CI_VERSION
106+
fi
107+
pip3 --disable-pip-version-check freeze >$SDK_CI_VENV_DIR/requirements.txt
108+
echo "Deps written to $SDK_CI_VENV_DIR/requirements.txt"
109+
cat $SDK_CI_VENV_DIR/requirements.txt
110+
111+
deactivate
112+
113+
echo "Adding to PATH..."
114+
echo 'export PATH=$PATH:'"${SDK_CI_VENV_DIR}/bin" >>$BASH_ENV
115+
}
116+
main || $SDK_CI_ALLOW_FAILURE

setup-slack-templates.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export basic_fail_1="{\n\t\"text\": \"CircleCI job failed.\",\n\t\"blocks\": [\n\t\t{\n\t\t\t\"type\": \"header\",\n\t\t\t\"text\": {\n\t\t\t\t\"type\": \"plain_text\",\n\t\t\t\t\"text\": \"Job Failed. :red_circle:\",\n\t\t\t\t\"emoji\": true\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t\"type\": \"section\",\n\t\t\t\"fields\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Job*: ${CIRCLE_JOB}\"\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"type\": \"section\",\n\t\t\t\"fields\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Project*: $CIRCLE_PROJECT_REPONAME\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Branch*: $CIRCLE_BRANCH\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Author*: $CIRCLE_USERNAME\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"accessory\": {\n\t\t\t\t\"type\": \"image\",\n\t\t\t\t\"image_url\": \"https://assets.brandfolder.com/otz5mn-bw4j2w-6jzqo8/original/circle-logo-badge-black.png\",\n\t\t\t\t\"alt_text\": \"CircleCI logo\"\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t\"type\": \"section\",\n\t\t\t\"fields\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Mentions*: $SLACK_PARAM_MENTIONS\"\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"type\": \"actions\",\n\t\t\t\"elements\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"button\",\n\t\t\t\t\t\"action_id\": \"basic_fail_view\",\n\t\t\t\t\t\"text\": {\n\t\t\t\t\t\t\"type\": \"plain_text\",\n\t\t\t\t\t\t\"text\": \"View Job\"\n\t\t\t\t\t},\n\t\t\t\t\t\"url\": \"${CIRCLE_BUILD_URL}\"\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t]\n}\n"
2+
export basic_on_hold_1="{\n\t\"text\": \"CircleCI job on hold, waiting for approval.\",\n\t\"blocks\": [\n\t\t{\n\t\t\t\"type\": \"header\",\n\t\t\t\"text\": {\n\t\t\t\t\"type\": \"plain_text\",\n\t\t\t\t\"text\": \"ON HOLD - Awaiting Approval :raised_hand:\",\n\t\t\t\t\"emoji\": true\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t\"type\": \"section\",\n\t\t\t\"fields\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Project*: $CIRCLE_PROJECT_REPONAME\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Branch*: $CIRCLE_BRANCH\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Author*: $CIRCLE_USERNAME\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"accessory\": {\n\t\t\t\t\"type\": \"image\",\n\t\t\t\t\"image_url\": \"https://assets.brandfolder.com/otz5mn-bw4j2w-6jzqo8/original/circle-logo-badge-black.png\",\n\t\t\t\t\"alt_text\": \"CircleCI logo\"\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t\"type\": \"section\",\n\t\t\t\"fields\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Mentions*: $SLACK_PARAM_MENTIONS\"\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"type\": \"actions\",\n\t\t\t\"elements\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"button\",\n\t\t\t\t\t\"action_id\": \"basic_on_hold_view\",\n\t\t\t\t\t\"text\": {\n\t\t\t\t\t\t\"type\": \"plain_text\",\n\t\t\t\t\t\t\"text\": \"View Workflow\"\n\t\t\t\t\t},\n\t\t\t\t\t\"url\": \"${SLACK_PARAM_CIRCLECI_HOST}/workflow-run/${CIRCLE_WORKFLOW_ID}\"\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t]\n}\n"
3+
export basic_success_1="{\n\t\"text\": \"CircleCI job succeeded!\",\n\t\"blocks\": [\n\t\t{\n\t\t\t\"type\": \"header\",\n\t\t\t\"text\": {\n\t\t\t\t\"type\": \"plain_text\",\n\t\t\t\t\"text\": \"Job Succeeded. :white_check_mark:\",\n\t\t\t\t\"emoji\": true\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t\"type\": \"section\",\n\t\t\t\"fields\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Job*: ${CIRCLE_JOB}\"\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"type\": \"section\",\n\t\t\t\"fields\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Project*: $CIRCLE_PROJECT_REPONAME\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Branch*: $CIRCLE_BRANCH\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Commit*: $CIRCLE_SHA1\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Author*: $CIRCLE_USERNAME\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"accessory\": {\n\t\t\t\t\"type\": \"image\",\n\t\t\t\t\"image_url\": \"https://assets.brandfolder.com/otz5mn-bw4j2w-6jzqo8/original/circle-logo-badge-black.png\",\n\t\t\t\t\"alt_text\": \"CircleCI logo\"\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t\"type\": \"section\",\n\t\t\t\"fields\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Mentions*: $SLACK_PARAM_MENTIONS\"\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"type\": \"actions\",\n\t\t\t\"elements\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"button\",\n\t\t\t\t\t\"action_id\": \"basic_success_view\",\n\t\t\t\t\t\"text\": {\n\t\t\t\t\t\t\"type\": \"plain_text\",\n\t\t\t\t\t\t\"text\": \"View Job\"\n\t\t\t\t\t},\n\t\t\t\t\t\"url\": \"${CIRCLE_BUILD_URL}\"\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t]\n}\n"
4+
export success_tagged_deploy_1="{\n\t\"text\": \"CircleCI job succeeded!\",\n\t\"blocks\": [\n\t\t{\n\t\t\t\"type\": \"header\",\n\t\t\t\"text\": {\n\t\t\t\t\"type\": \"plain_text\",\n\t\t\t\t\"text\": \"Deployment Successful! :tada:\",\n\t\t\t\t\"emoji\": true\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t\"type\": \"section\",\n\t\t\t\"fields\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Project*: $CIRCLE_PROJECT_REPONAME\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*When*: $(date +'%m/%d/%Y %T')\"\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"mrkdwn\",\n\t\t\t\t\t\"text\": \"*Tag*: $CIRCLE_TAG\"\n\t\t\t\t}\n\t\t\t],\n\t\t\t\"accessory\": {\n\t\t\t\t\"type\": \"image\",\n\t\t\t\t\"image_url\": \"https://assets.brandfolder.com/otz5mn-bw4j2w-6jzqo8/original/circle-logo-badge-black.png\",\n\t\t\t\t\"alt_text\": \"CircleCI logo\"\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\t\"type\": \"actions\",\n\t\t\t\"elements\": [\n\t\t\t\t{\n\t\t\t\t\t\"type\": \"button\",\n\t\t\t\t\t\"action_id\": \"success_tagged_deploy_view\",\n\t\t\t\t\t\"text\": {\n\t\t\t\t\t\t\"type\": \"plain_text\",\n\t\t\t\t\t\t\"text\": \"View Job\"\n\t\t\t\t\t},\n\t\t\t\t\t\"url\": \"${CIRCLE_BUILD_URL}\"\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t]\n}\n"
5+

0 commit comments

Comments
 (0)