|  | 
|  | 1 | +#!/usr/bin/env bash | 
|  | 2 | +# GitHub Codespaces setup script for Jenkins Quickstart Tutorials | 
|  | 3 | +# This script configures the Codespace environment and prepares Jenkins URL configuration | 
|  | 4 | + | 
|  | 5 | +set -Eeuo pipefail  # Exit on error, undefined variables, pipe failures | 
|  | 6 | + | 
|  | 7 | +echo "================================" | 
|  | 8 | +echo "Setting up Jenkins Tutorials Environment" | 
|  | 9 | +echo "================================" | 
|  | 10 | + | 
|  | 11 | +# Install yq (YAML processor) - required for JCaC configuration | 
|  | 12 | +echo "📦 Installing yq YAML processor..." | 
|  | 13 | +YQ_VERSION="${YQ_VERSION:-v4.44.3}" | 
|  | 14 | +YQ_URL="https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" | 
|  | 15 | + | 
|  | 16 | +# Try wget first, fall back to curl if unavailable | 
|  | 17 | +if command -v wget &> /dev/null; then | 
|  | 18 | +    sudo wget -qO /usr/local/bin/yq "${YQ_URL}" | 
|  | 19 | +elif command -v curl &> /dev/null; then | 
|  | 20 | +    sudo curl -fsSL -o /usr/local/bin/yq "${YQ_URL}" | 
|  | 21 | +else | 
|  | 22 | +    echo "❌ Error: Neither wget nor curl found. Cannot download yq." | 
|  | 23 | +    exit 1 | 
|  | 24 | +fi | 
|  | 25 | + | 
|  | 26 | +sudo chmod a+x /usr/local/bin/yq | 
|  | 27 | +yq --version | 
|  | 28 | + | 
|  | 29 | +# Verify Docker is available | 
|  | 30 | +echo "🐳 Verifying Docker installation..." | 
|  | 31 | +docker --version | 
|  | 32 | +docker compose version | 
|  | 33 | + | 
|  | 34 | +# Create secrets directory if it doesn't exist | 
|  | 35 | +echo "📁 Creating secrets directory..." | 
|  | 36 | +mkdir -p ./secrets | 
|  | 37 | + | 
|  | 38 | +# Run Codespaces URL configuration script | 
|  | 39 | +if [ -f "./dockerfiles/codespacesURL.sh" ]; then | 
|  | 40 | +    echo "🔧 Configuring Jenkins URLs for Codespaces..." | 
|  | 41 | +    chmod +x ./dockerfiles/codespacesURL.sh | 
|  | 42 | +    ./dockerfiles/codespacesURL.sh | 
|  | 43 | +else | 
|  | 44 | +    echo "⚠️  Warning: codespacesURL.sh not found, skipping URL configuration" | 
|  | 45 | +fi | 
|  | 46 | + | 
|  | 47 | +# Create welcome message for future terminal sessions | 
|  | 48 | +WELCOME_FILE=".devcontainer/welcome.txt" | 
|  | 49 | +cat > "${WELCOME_FILE}" << 'WELCOME_EOF' | 
|  | 50 | +
 | 
|  | 51 | +================================ | 
|  | 52 | +🚀 Jenkins Quickstart Tutorials | 
|  | 53 | +================================ | 
|  | 54 | +
 | 
|  | 55 | +Available tutorial profiles: | 
|  | 56 | +  • default  : Basic Jenkins with SSH agent | 
|  | 57 | +  • maven    : Jenkins + Maven build environment | 
|  | 58 | +  • python   : Jenkins + Python development | 
|  | 59 | +  • node     : Jenkins + Node.js/npm | 
|  | 60 | +  • multi    : Multibranch pipeline example | 
|  | 61 | +  • android  : Android development | 
|  | 62 | +  • golang   : Go development | 
|  | 63 | +  • cpp      : C++ development | 
|  | 64 | +  • dotnet   : .NET development | 
|  | 65 | +  • wizard   : Jenkins setup wizard (learning) | 
|  | 66 | +
 | 
|  | 67 | +Quick Start: | 
|  | 68 | +  docker compose --profile <profile-name> up -d | 
|  | 69 | +
 | 
|  | 70 | +Examples: | 
|  | 71 | +  docker compose --profile maven up -d | 
|  | 72 | +  docker compose --profile node up -d | 
|  | 73 | +
 | 
|  | 74 | +To build locally: | 
|  | 75 | +  docker compose -f build-docker-compose.yaml --profile <profile-name> up -d | 
|  | 76 | +
 | 
|  | 77 | +WELCOME_EOF | 
|  | 78 | + | 
|  | 79 | +# Add Jenkins URL based on environment | 
|  | 80 | +if [ -n "${CODESPACE_NAME:-}" ] && [ -n "${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:-}" ]; then | 
|  | 81 | +    echo "Jenkins will be accessible at:" >> "${WELCOME_FILE}" | 
|  | 82 | +    echo "  https://${CODESPACE_NAME}-8080.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" >> "${WELCOME_FILE}" | 
|  | 83 | +else | 
|  | 84 | +    echo "Jenkins will be accessible at:" >> "${WELCOME_FILE}" | 
|  | 85 | +    echo "  http://localhost:8080" >> "${WELCOME_FILE}" | 
|  | 86 | +fi | 
|  | 87 | + | 
|  | 88 | +echo "" >> "${WELCOME_FILE}" | 
|  | 89 | +echo "Default credentials: admin/admin" >> "${WELCOME_FILE}" | 
|  | 90 | +echo "================================" >> "${WELCOME_FILE}" | 
|  | 91 | +echo "" >> "${WELCOME_FILE}" | 
|  | 92 | + | 
|  | 93 | +# Display the welcome message | 
|  | 94 | +cat "${WELCOME_FILE}" | 
|  | 95 | + | 
|  | 96 | +echo "✅ Setup Complete! Welcome message saved to ${WELCOME_FILE}" | 
|  | 97 | +echo "" | 
|  | 98 | + | 
|  | 99 | +# Add welcome message to .bashrc so it shows on every new terminal | 
|  | 100 | +# Use git rev-parse to find repo root dynamically instead of hardcoding path | 
|  | 101 | +REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" | 
|  | 102 | +WELCOME_PATH="${REPO_ROOT}/.devcontainer/welcome.txt" | 
|  | 103 | + | 
|  | 104 | +if ! grep -q "Jenkins Quickstart Tutorials Welcome" ~/.bashrc; then | 
|  | 105 | +    echo "" >> ~/.bashrc | 
|  | 106 | +    echo "# Jenkins Quickstart Tutorials Welcome" >> ~/.bashrc | 
|  | 107 | +    echo "if [ -f \"${WELCOME_PATH}\" ]; then" >> ~/.bashrc | 
|  | 108 | +    echo "    cat \"${WELCOME_PATH}\"" >> ~/.bashrc | 
|  | 109 | +    echo "fi" >> ~/.bashrc | 
|  | 110 | +fi | 
|  | 111 | + | 
|  | 112 | +# Set port 8080 visibility to public using gh CLI (if in Codespaces) | 
|  | 113 | +if [ -n "${CODESPACE_NAME:-}" ]; then | 
|  | 114 | +    echo "🔓 Setting port 8080 visibility to public..." | 
|  | 115 | +    # Check if gh CLI is authenticated before attempting to set port visibility | 
|  | 116 | +    if gh auth status &>/dev/null; then | 
|  | 117 | +        gh codespace ports visibility 8080:public -c "${CODESPACE_NAME}" 2>/dev/null || echo "⚠️  Could not set port visibility automatically. Please set port 8080 to public manually in the PORTS panel." | 
|  | 118 | +    else | 
|  | 119 | +        echo "⚠️  gh CLI not authenticated. Please set port 8080 to public manually in the PORTS panel." | 
|  | 120 | +    fi | 
|  | 121 | +fi | 
0 commit comments