-
-
Save thecist/59a5a679b5ccf2b6122df7e89ca69fdf to your computer and use it in GitHub Desktop.
The core script used to deploy thecist's repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -e | |
| REPO_DIR="$1" | |
| TARGET_DIR="$2" | |
| PROJECT_NAME="$3" | |
| BRANCH="$4" | |
| if [[ -z "$REPO_DIR" || -z "$TARGET_DIR" || -z "$PROJECT_NAME" || -z "$BRANCH" ]]; then | |
| echo "Usage: _deploy-core <repo_dir> <target_dir> <project_name> <branch>" | |
| exit 1 | |
| fi | |
| export DEPLOY_REPO_DIR="$REPO_DIR" | |
| export DEPLOY_TARGET_DIR="$TARGET_DIR" | |
| export DEPLOY_PROJECT_NAME="$PROJECT_NAME" | |
| export DEPLOY_BRANCH="$BRANCH" | |
| echo "Deploying branch '$BRANCH' of '$REPO_DIR' to '$TARGET_DIR' with project '$PROJECT_NAME'..." | |
| mkdir -p "$TARGET_DIR" | |
| GIT_WORK_TREE="$TARGET_DIR" git --git-dir="$REPO_DIR" checkout -f "$BRANCH" | |
| cd "$TARGET_DIR" | |
| # Find prebuild script | |
| if [ -x "./scripts/production/pre-build" ]; then | |
| PREBUILD_SCRIPT="./scripts/production/pre-build" | |
| elif [ -x "./scripts/production/pre-build.sh" ]; then | |
| PREBUILD_SCRIPT="./scripts/production/pre-build.sh" | |
| else | |
| PREBUILD_SCRIPT="" | |
| fi | |
| if [ -x "$PREBUILD_SCRIPT" ]; then | |
| echo "Running prebuild script..." | |
| "$PREBUILD_SCRIPT" | |
| fi | |
| echo "Running docker compose --project-name ${PROJECT_NAME} up --build -d" | |
| docker compose --project-name "$PROJECT_NAME" up --build -d | |
| echo "Changing HEAD pointer back to main branch" | |
| git --git-dir="$REPO_DIR" symbolic-ref HEAD refs/heads/main | |
| echo "Deployment complete for $PROJECT_NAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment