Startr.sh
Building an App or Site?
We are the Best way to Build and Launch
Just run the following line in your terminal to get startred ;)
bash <(curl -sL startr.sh)
Building an App or Site?
Just run the following line in your terminal to get startred ;)
bash <(curl -sL startr.sh)
With Startr.sh, creating Docker images for your projects is streamlined and efficient.
Follow best practices and use popular frameworks like Python, Django, Flask, Node, and Startr.Style CSS.
After countless projects and years of experience, we provide you the tools and insights to launch your projects quickly and reliably.
#!/bin/bash
#
# Version 1.7.0
#
# Copyright (c) Startr LLC. All rights reserved.
# This script is licensed under the GNU Affero General Public License v3.0.
# For more information, see https://www.gnu.org/licenses/agpl-3.0.en.html
#
# Combined Build and Build 'n' Run Script
# This script builds a Docker image for the
# current project and optionally runs it.
#
# `curl startr.sh|bash` to run this script
# or pass arguments such as `build` or `run`
#
# `curl startr.sh|bash -s build` to build
#
ascii_art="
_____ _ _ _
/ ___|| | | | | |
\ --. | |_ __ _ _ __ | |_ _ __ ___ | |__
\`--. \| __| / _\` || '__|| __|| '__| / __|| '_ \
/\__/ /| |_ | (_| || | | |_ | | _ \__ \| | | |
\____/ \__| \__,_||_| \__||_| (_)|___/|_| |_|
_____ _ _ _ _ _ _ _ _
/ ____| | | | (_) (*) | | (H) | | | |
| (___ | |_ __ _ _ __| |_ _ _ __ __ _ _ __ _ __ ___ _ ___ ___| |_ ___ _ __ _ __ _| |__ | |_
\___ \| __/ _\` | '__| __| | '_ \ / _\` | | '_ \| '__/ _ \| |/ _ \/ __| __/ __| | '__| |/ _\` | '_ \| __|
____) | || (_| | | | |_| | | | | (_| | | |_) | | | (_) | | __/ (__| |_\__ \ | | | | (_| | | | | |_
|_____/ \__\__,_|_| \__|_|_| |_|\__, | | .__/|_| \___/| |\___|\___|\__|___/ |_| |_|\__, |_| |_|\__|
__/ | | | _/ | __/ |
|___/ |_| |__/ |___/
"
about_startr="
Startr is a command line tool that streamlines your project setup,
ensuring everything is in place so you can focus on development.
- Project Folder Check
Verifies your project folder is correctly set up.
- Dockerfile Check and Creation
Ensures a Dockerfile exists in your project folder.
If not, we creates one automatically.
"
# Function to convert RGB to ANSI escape code
rgb_to_ansi() {
printf "\033[38;2;%d;%d;%dm" "$1" "$2" "$3"
}
# Function to interpolate between two values
interpolate() {
local start=$1
local end=$2
local factor=$3
echo "$(( start + (end - start) * factor / 100 ))"
}
# Function to apply gradient coloring to ASCII art
apply_gradient() {
local lines=()
while IFS= read -r line; do
lines+=("$line")
done
local total_lines=${#lines[@]}
local start_colors=(255 0 0) # Red
local mid_colors=(128 128 255) # Blue
local end_colors=(128 0 128) # Purple
for i in "${!lines[@]}"; do
local factor=$(( i * 200 / (total_lines - 1) )) # factor range: 0 to 200
local r g b
if (( factor <= 100 )); then
r=$(interpolate "${start_colors[0]}" "${mid_colors[0]}" "$factor")
g=$(interpolate "${start_colors[1]}" "${mid_colors[1]}" "$factor")
b=$(interpolate "${start_colors[2]}" "${mid_colors[2]}" "$factor")
else
factor=$(( factor - 100 ))
r=$(interpolate "${mid_colors[0]}" "${end_colors[0]}" "$factor")
g=$(interpolate "${mid_colors[1]}" "${end_colors[1]}" "$factor")
b=$(interpolate "${mid_colors[2]}" "${end_colors[2]}" "$factor")
fi
local color
color=$(rgb_to_ansi "$r" "$g" "$b")
echo -e "${color}${lines[i]}\033[0m"
done
}
# Apply gradient to the ASCII art and display it
echo "$ascii_art" | apply_gradient
# Print the about message
echo -e "$about_startr"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Emojis
BUILD_EMOJI='🛠️'
RUN_EMOJI='🚀'
SUCCESS_EMOJI='✅'
ERROR_EMOJI='❌'
# Function to ask the user for input
ask_for_input() {
echo -e "${YELLOW}You haven't specified runtime arguments. Let's set them up interactively.${NC}"
echo -e "${BLUE}Choose one of the following options:${NC}"
echo -e "${BLUE}1. build - Build the Docker image only.${NC}"
echo -e "${BLUE}2. build_and_run - (Default) Build the Docker image and run the container.${NC}"
echo -e "${BLUE}3. run - Run the container using the existing image.${NC}"
echo -e "${BLUE}Enter your choice (build/build_and_run/run) [default: build_and_run]:${NC}"
read -r JOB_INPUT
# Default to "build_and_run" if nothing is entered
if [ -z "$JOB_INPUT" ]; then
JOB="build_and_run"
else
JOB=$JOB_INPUT
fi
while [[ "$JOB" != "build" && "$JOB" != "build_and_run" && "$JOB" != "run" ]]; do
echo -e "${RED}Invalid input. Please enter 'build', 'build_and_run', or 'run':${NC}"
read -r JOB
done
echo -e "${BLUE}Do you want to specify a platform? (Enter the platform or leave blank for none):${NC}"
read -r PLATFORM
}
# Function to provide information on repositories
explain_repo() {
echo -e "${YELLOW}A git repository is a virtual storage of your project. It allows you to save versions of your code, which you can access when needed.${NC}"
echo -e "${YELLOW}For more information, visit: https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control${NC}"
echo -e "${BLUE}Would you like to clone the example repository 'https://github.com/Startr/WEB-flask'? (y/n):${NC}"
read -r CLONE_REPO
if [ "$CLONE_REPO" == "y" ]; then
git clone https://github.com/Startr/WEB-flask
cd WEB-flask
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to clone the repository. Please check your internet connection and try again.${NC}"
exit 1
fi
cd WEB-flask || exit
echo -e "${GREEN}Repository cloned and switched to WEB-flask directory.${NC}"
else
echo -e ""
echo -e "${BLUE}Would you like to set up a git flow repository in this directory? (y/n):${NC}"
echo -e ""
echo -e "${YELLOW}Note: Git flow is a branching model for Git, which helps with managing your repository.${NC}"
echo -e "${YELLOW} You will need to have git flow installed on your system.${NC}"
read -r SETUP_REPO
echo -e ""
if [ "$SETUP_REPO" == "y" ]; then
git flow init
else
echo -e "OK... You'll need to set up a git repository before running this script."
echo -e "${RED}Please set up a git repository before running this script.${NC}"
exit 1
fi
fi
}
# Check if in a git repository
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
echo -e "${RED}You are not in a git repository.${NC}"
explain_repo
fi
# Check if arguments are provided
if [ "$#" -lt 1 ]; then
ask_for_input
else
JOB=$1
if [ "$JOB" != "build" ] && [ "$JOB" != "build_and_run" ] && [ "$JOB" != "run" ]; then
echo -e "${RED}Invalid argument for JOB: $JOB. Use 'build', 'build_and_run', or 'run'.${NC}"
exit 1
fi
PLATFORM=$2
fi
# Function to create a default Dockerfile based on project type
create_dockerfile() {
PROJECT_TYPE=$1
if [ "$PROJECT_TYPE" == "python-pipenv" ]; then
cat > Dockerfile < Dockerfile < Dockerfile <