diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 00000000..66ce767e --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,49 @@ +# Codespaces Configuration + +This directory contains the GitHub Codespaces dev container configuration. + +## Port Visibility + +Port 8080 may show as **private** in the PORTS panel, but this is usually not an issue - you can still access Jenkins using the forwarded URL. + +**Note:** The port visibility label in the UI can be misleading. Even when marked as "private", the Jenkins URL provided in the welcome message will work in your browser. Only change visibility to "public" if you need to share the URL with others. + +### Manual Steps (if needed for sharing): +1. Open the **PORTS** panel at the bottom of VS Code (next to TERMINAL) +2. Find port **8080** in the list +3. **Right-click** on port 8080 +4. Select **Port Visibility** → **Public** + +### Technical Details + +The `devcontainer.json` includes `"visibility": "public"` for port 8080, but GitHub Codespaces may not always apply this setting automatically. The setup script attempts to set visibility using the GitHub CLI, but this is optional since Codespaces authentication allows private port access. + +## Files + +- **devcontainer.json** - Dev container specification +- **setup.sh** - Initialization script (installs yq, configures URLs, creates welcome message) +- **welcome.txt** - Generated welcome message (not in git, created at runtime) +- **README.md** - This file + +## Accessing Jenkins + +After starting a tutorial with `docker compose --profile up -d`: +- Jenkins URL: `https://-8080.` (shown in PORTS panel) +- Default credentials: admin/admin + +**Important:** Open Jenkins in a regular browser tab, not the VS Code preview pane. The preview may show "Please reopen the preview" due to Jenkins security headers. Click the globe icon 🌐 in the PORTS panel or copy the URL to your browser. + +## Troubleshooting + +**Port 8080 refuses connection:** +- Verify Jenkins is running: `docker compose ps` +- Check logs: `docker compose logs jenkins_controller` +- Wait 1-2 minutes for Jenkins to fully start +- Port visibility (private/public) should not affect access for the Codespace owner + +**Welcome message not showing:** +- Run: `source ~/.bashrc` in your terminal +- Or open a new terminal window + +**yq not found:** +- Run: `bash .devcontainer/setup.sh` manually diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..f4faec26 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,54 @@ +{ + "name": "Jenkins Quickstart Tutorials", + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04", + + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:2": { + "version": "27.0", + "dockerDashComposeVersion": "v2" + }, + "ghcr.io/devcontainers/features/github-cli:1": { + "version": "2.62" + } + }, + + "onCreateCommand": "bash .devcontainer/setup.sh", + "postStartCommand": "cat .devcontainer/welcome.txt 2>/dev/null || echo 'Run: .devcontainer/setup.sh for tutorial instructions'", + + "forwardPorts": [8080, 3000, 5000], + + "portsAttributes": { + "8080": { + "label": "Jenkins Controller", + "onAutoForward": "openBrowser", + "protocol": "http", + "visibility": "public" + }, + "3000": { + "label": "Application Port (Node/Android/Go)", + "onAutoForward": "notify", + "protocol": "http" + }, + "5000": { + "label": "Application Port (Multi/.NET)", + "onAutoForward": "notify", + "protocol": "http" + } + }, + + "customizations": { + "vscode": { + "extensions": [ + "ms-azuretools.vscode-docker", + "redhat.vscode-yaml" + ], + "settings": { + "terminal.integrated.defaultProfile.linux": "bash" + } + } + }, + + "remoteUser": "vscode", + + "updateContentCommand": "echo 'Container updated successfully'" +} diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100644 index 00000000..0963dc04 --- /dev/null +++ b/.devcontainer/setup.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash +# GitHub Codespaces setup script for Jenkins Quickstart Tutorials +# This script configures the Codespace environment and prepares Jenkins URL configuration + +set -Eeuo pipefail # Exit on error, undefined variables, pipe failures + +echo "================================" +echo "Setting up Jenkins Tutorials Environment" +echo "================================" + +# Install yq (YAML processor) - required for JCasc configuration +echo "đŸ“Ļ Installing yq YAML processor..." +YQ_VERSION="${YQ_VERSION:-v4.44.3}" +YQ_URL="https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" + +# Try wget first, fall back to curl if unavailable +if command -v wget &> /dev/null; then + sudo wget -qO /usr/local/bin/yq "${YQ_URL}" +elif command -v curl &> /dev/null; then + sudo curl -fsSL -o /usr/local/bin/yq "${YQ_URL}" +else + echo "❌ Error: Neither wget nor curl found. Cannot download yq." + exit 1 +fi + +sudo chmod a+x /usr/local/bin/yq +yq --version + +# Verify Docker is available +echo "đŸŗ Verifying Docker installation..." +docker --version +docker compose version + +# Create secrets directory if it doesn't exist +echo "📁 Creating secrets directory..." +mkdir -p ./secrets + +# Run Codespaces URL configuration script +if [ -f "./dockerfiles/codespacesURL.sh" ]; then + echo "🔧 Configuring Jenkins URLs for Codespaces..." + chmod +x ./dockerfiles/codespacesURL.sh + ./dockerfiles/codespacesURL.sh +else + echo "âš ī¸ Warning: codespacesURL.sh not found, skipping URL configuration" +fi + +# Create welcome message for future terminal sessions +WELCOME_FILE=".devcontainer/welcome.txt" +cat > "$WELCOME_FILE" << 'WELCOME_EOF' + +================================ +🚀 Jenkins Quickstart Tutorials +================================ + +Available tutorial profiles: + â€ĸ default : Basic Jenkins with SSH agent + â€ĸ maven : Jenkins + Maven build environment + â€ĸ python : Jenkins + Python development + â€ĸ node : Jenkins + Node.js/npm + â€ĸ multi : Multibranch pipeline example + â€ĸ android : Android development + â€ĸ golang : Go development + â€ĸ cpp : C++ development + â€ĸ dotnet : .NET development + â€ĸ wizard : Jenkins setup wizard (learning) + +Quick Start: + docker compose --profile up -d + +Examples: + docker compose --profile maven up -d + docker compose --profile node up -d + +To build locally: + docker compose -f build-docker-compose.yaml --profile up -d + +WELCOME_EOF + +# Add Jenkins URL based on environment +if [ -n "${CODESPACE_NAME:-}" ] && [ -n "${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:-}" ]; then + echo "Jenkins will be accessible at:" >> "${WELCOME_FILE}" + echo " https://${CODESPACE_NAME}-8080.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" >> "${WELCOME_FILE}" +else + echo "Jenkins will be accessible at:" >> "${WELCOME_FILE}" + echo " http://localhost:8080" >> "${WELCOME_FILE}" +fi + +echo "" >> "${WELCOME_FILE}" +echo "Default credentials: admin/admin" >> "${WELCOME_FILE}" +echo "================================" >> "${WELCOME_FILE}" +echo "" >> "${WELCOME_FILE}" + +# Display the welcome message +cat "${WELCOME_FILE}" + +echo "✅ Setup Complete! Welcome message saved to ${WELCOME_FILE}" +echo "" + +# Add welcome message to .bashrc so it shows on every new terminal +# Use git rev-parse to find repo root dynamically instead of hardcoding path +REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" +WELCOME_PATH="${REPO_ROOT}/.devcontainer/welcome.txt" + +if ! grep -q "Jenkins Quickstart Tutorials Welcome" ~/.bashrc; then + echo "" >> ~/.bashrc + echo "# Jenkins Quickstart Tutorials Welcome" >> ~/.bashrc + echo "if [ -f \"${WELCOME_PATH}\" ]; then" >> ~/.bashrc + echo " cat \"${WELCOME_PATH}\"" >> ~/.bashrc + echo "fi" >> ~/.bashrc +fi + +# Set port 8080 visibility to public using gh CLI (if in Codespaces) +if [ -n "${CODESPACE_NAME:-}" ]; then + echo "🔓 Setting port 8080 visibility to public..." + # Check if gh CLI is authenticated before attempting to set port visibility + if gh auth status &>/dev/null; then + 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." + else + echo "âš ī¸ gh CLI not authenticated. Please set port 8080 to public manually in the PORTS panel." + fi +fi diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ba747743..28b03e88 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,6 +2,11 @@ # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates version: 2 +# Note: GitPod support is legacy (free tier sunset). Migrated to GitHub Codespaces. +# Codespaces uses devcontainer.json which Dependabot cannot monitor (not a Dockerfile). +# Codespaces dependencies (yq, devcontainer features) are tracked by UpdateCLI. +# See updatecli/updatecli.d/codespaces.yaml for automated updates. + # Enable version updates for GitHub Actions workflows updates: - package-ecosystem: "github-actions" @@ -62,4 +67,13 @@ updates: directory: "./dockerfiles/dotnet" schedule: interval: weekly - open-pull-requests-limit: 10 + open-pull-requests-limit: 10 + + # GitPod (legacy) - disabled, not actively maintained + - package-ecosystem: docker + directory: "./.gitpod" + schedule: + interval: weekly + open-pull-requests-limit: 0 + ignore: + - dependency-name: "gitpod/workspace-full" diff --git a/.gitignore b/.gitignore index b9c056c2..66a1bd3f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ secrets/* 03_maven_tutorial/secrets/* .tutorial_running.txt +# Local development files +CLAUDE.md +CONTEXT.md +.devcontainer/welcome.txt diff --git a/CODESPACES_MIGRATION_PLAN.md b/CODESPACES_MIGRATION_PLAN.md new file mode 100644 index 00000000..bb1cc251 --- /dev/null +++ b/CODESPACES_MIGRATION_PLAN.md @@ -0,0 +1,274 @@ +# GitHub Codespaces Migration Plan + +## Executive Summary + +This document outlines the migration plan from GitPod to GitHub Codespaces for the Jenkins quickstart tutorials repository. GitPod's free tier has sunset, making GitHub Codespaces the preferred cloud development environment for this project. + +## Current GitPod Configuration Analysis + +### Files Involved +1. `.gitpod.yml` - Main GitPod workspace configuration +2. `.gitpod/Dockerfile` - Custom Docker image with GitHub CLI +3. `dockerfiles/gitpodURL.sh` - URL configuration script for GitPod workspace URLs + +### Key Features +- **Base Image**: `gitpod/workspace-full:2025-10-13-11-42-09` +- **Additional Tools**: GitHub CLI (`gh`) +- **Initialization**: + - Downloads and installs `yq` (YAML processor) + - Runs `gitpodURL.sh` to configure Jenkins URLs for GitPod workspace +- **Port Exposure**: Port 8080 for Jenkins with auto-preview +- **Environment Variables**: `GITPOD_WORKSPACE_URL` used for URL rewriting + +### What gitpodURL.sh Does +- Extracts hostname from `GITPOD_WORKSPACE_URL` +- Updates `dockerfiles/jenkins.yaml` with GitPod-specific URL format +- Configures Jenkins location URL as `https://8080-$service_url/` +- Disables reverse proxy setup warning in Jenkins +- Displays helpful instructions for available profiles + +## GitHub Codespaces Configuration Requirements + +### Dev Container Structure +GitHub Codespaces uses the dev container standard with these key files: +- `.devcontainer/devcontainer.json` - Main configuration file +- `.devcontainer/Dockerfile` (optional) - Custom container image + +### Codespaces Environment Variables +- `CODESPACE_NAME` - Unique name of the codespace +- `GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN` - Domain for port forwarding +- Format: `https://-.` + +## Migration Strategy + +### Phase 1: Create Dev Container Configuration + +#### 1.1 Create `.devcontainer/devcontainer.json` +```json +{ + "name": "Jenkins Quickstart Tutorials", + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/devcontainers/features/github-cli:1": {} + }, + "postCreateCommand": ".devcontainer/setup.sh", + "forwardPorts": [8080], + "portsAttributes": { + "8080": { + "label": "Jenkins Controller", + "onAutoForward": "openPreview" + } + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-azuretools.vscode-docker" + ] + } + } +} +``` + +#### 1.2 Create `.devcontainer/setup.sh` +- Install `yq` YAML processor +- Run equivalent of `gitpodURL.sh` but for Codespaces +- Set up environment + +#### 1.3 Create `.devcontainer/Dockerfile` (if needed) +- Base on Ubuntu or Debian +- Install required tools +- Ensure Docker Compose is available + +### Phase 2: Adapt URL Configuration Script + +#### 2.1 Create `dockerfiles/codespacesURL.sh` +```bash +#!/bin/bash + +# Set the path to the configuration file +config_file="/workspaces/quickstart-tutorials/dockerfiles/jenkins.yaml" + +# Build Codespaces URL from environment variables +if [ -n "$CODESPACE_NAME" ] && [ -n "$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN" ]; then + service_url="https://${CODESPACE_NAME}-8080.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" +else + # Fallback for local development + service_url="http://127.0.0.1:8080" +fi + +# Define an array of targets (same as GitPod script) +targets=("maven" "node" "python" "multi" "cpp" "dotnet" "default") + +# Display instructions +echo "Jenkins will be accessible here: $service_url" +for target in "${targets[@]}"; do + echo "To start the $target service, enter: docker compose --profile $target up" +done + +# Update Jenkins configuration +yq eval ".unclassified.location.url = \"$service_url/\"" "$config_file" > "$config_file.tmp" && mv "$config_file.tmp" "$config_file" + +# Suppress the Reverse Proxy setup warning +yq e -i ".jenkins.disabledAdministrativeMonitors = [\"hudson.diagnosis.ReverseProxySetupMonitor\"]" $config_file +``` + +#### 2.2 Update Docker Compose Files +Replace `GITPOD_WORKSPACE_URL` references with a generic `WORKSPACE_URL` variable that works for both: +- GitPod: Set from `GITPOD_WORKSPACE_URL` +- Codespaces: Constructed from `CODESPACE_NAME` and `GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN` + +### Phase 3: Update Documentation + +#### 3.1 Update README.md +- Add "GitHub Codespaces" section alongside existing GitPod section +- Provide Codespaces launch button: + ```markdown + [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/jenkins-docs/quickstart-tutorials) + ``` +- Update workspace access instructions + +#### 3.2 Update CLAUDE.md +- Add Codespaces configuration details +- Document environment variables +- Update troubleshooting section + +### Phase 4: Testing + +#### 4.1 Test Matrix +- [ ] Launch Codespace from main branch +- [ ] Verify dev container builds successfully +- [ ] Verify `yq` is installed +- [ ] Verify GitHub CLI (`gh`) is available +- [ ] Test each Docker Compose profile: + - [ ] maven + - [ ] python + - [ ] node + - [ ] multi + - [ ] default + - [ ] android + - [ ] golang + - [ ] cpp + - [ ] dotnet +- [ ] Verify Jenkins is accessible via forwarded port +- [ ] Verify Jenkins URL configuration is correct +- [ ] Test job creation and execution + +#### 4.2 Performance Validation +- Measure Codespace startup time vs GitPod +- Verify Docker-in-Docker performance +- Check resource allocation (2-core, 8GB minimum recommended) + +### Phase 5: Dual Support (Transition Period) + +Maintain both GitPod and Codespaces configurations during transition: +- Keep `.gitpod.yml` and `.gitpod/Dockerfile` +- Add `.devcontainer/` configuration +- Create generic scripts that detect environment and adapt + +### Phase 6: Deprecation (Optional) + +After successful migration and stabilization: +- Archive GitPod configuration files +- Update documentation to focus on Codespaces +- Add deprecation notice for GitPod setup + +## Implementation Checklist + +### Immediate Tasks +- [ ] Create `.devcontainer/` directory structure +- [ ] Implement `devcontainer.json` configuration +- [ ] Create setup scripts for Codespaces +- [ ] Adapt URL configuration for Codespaces environment +- [ ] Update Docker Compose files for dual environment support + +### Documentation Tasks +- [ ] Add Codespaces section to README.md +- [ ] Update CLAUDE.md with Codespaces details +- [ ] Create troubleshooting guide for Codespaces-specific issues +- [ ] Document differences between GitPod and Codespaces setups + +### Testing Tasks +- [ ] Create test Codespace from feature branch +- [ ] Validate all tutorial profiles +- [ ] Performance testing +- [ ] Document any issues or limitations + +### Deployment Tasks +- [ ] Merge feature branch after successful testing +- [ ] Update repository settings to enable Codespaces +- [ ] Configure Codespaces machine type defaults +- [ ] Update external documentation/tutorials if needed + +## Key Differences: GitPod vs Codespaces + +| Feature | GitPod | GitHub Codespaces | +|---------|--------|-------------------| +| Configuration File | `.gitpod.yml` | `.devcontainer/devcontainer.json` | +| Container Image | `.gitpod/Dockerfile` | `.devcontainer/Dockerfile` (optional) | +| Base Image | `gitpod/workspace-full` | `mcr.microsoft.com/devcontainers/base` or custom | +| Workspace Path | `/workspace/` | `/workspaces/` | +| URL Format | `https://8080-` | `https://-8080.` | +| Environment Var | `GITPOD_WORKSPACE_URL` | `CODESPACE_NAME` + `GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN` | +| Features | Manual installation | Dev container features (standardized) | +| Port Forwarding | Automatic with preview | Automatic with configurable visibility | + +## Potential Issues and Mitigations + +### Issue 1: Docker-in-Docker Performance +**Risk**: Nested Docker might be slower in Codespaces +**Mitigation**: Use Docker-in-Docker feature from dev containers catalog, which is optimized + +### Issue 2: Startup Time +**Risk**: Complex setup might slow Codespace creation +**Mitigation**: +- Use prebuild configuration for faster starts +- Optimize setup scripts +- Cache Docker images when possible + +### Issue 3: Port Forwarding Differences +**Risk**: URL format changes might break Jenkins configuration +**Mitigation**: Robust URL detection and configuration in setup script + +### Issue 4: Resource Limits +**Risk**: Default Codespace might not have enough resources +**Mitigation**: Document recommended machine type (4-core, 16GB for optimal performance) + +### Issue 5: Environment Variable Detection +**Risk**: Scripts might fail if environment variables are missing +**Mitigation**: Add fallback logic for local development and robust error handling + +## Success Criteria + +1. ✅ Codespace launches successfully with all tools installed +2. ✅ All Docker Compose profiles work correctly +3. ✅ Jenkins is accessible via port forwarding +4. ✅ Jenkins URL configuration is automatic and correct +5. ✅ Documentation is clear and comprehensive +6. ✅ No degradation in developer experience compared to GitPod +7. ✅ Startup time is acceptable (under 5 minutes) + +## Timeline Estimate + +- **Phase 1 (Dev Container)**: 2-3 hours +- **Phase 2 (URL Scripts)**: 1-2 hours +- **Phase 3 (Documentation)**: 1-2 hours +- **Phase 4 (Testing)**: 3-4 hours +- **Phase 5 (Dual Support)**: 1 hour +- **Total**: ~10-15 hours + +## Next Steps + +1. Create `.devcontainer/devcontainer.json` with basic configuration +2. Implement setup script with yq installation and URL configuration +3. Test with a single profile (e.g., maven) +4. Iterate and expand to all profiles +5. Update documentation +6. Submit PR for review + +## References + +- [GitHub Codespaces Documentation](https://docs.github.com/en/codespaces) +- [Dev Container Specification](https://containers.dev/) +- [Dev Container Features](https://github.com/devcontainers/features) +- [Docker-in-Docker Feature](https://github.com/devcontainers/features/tree/main/src/docker-in-docker) diff --git a/README.md b/README.md index 085eab68..e65b9eca 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,54 @@ This repository includes the files necessary for transitioning from `docker` to `docker compose` in our Jenkins tutorials and installation guides. -### How to Set Up the Repository in Gitpod? +### How to Set Up the Repository in GitHub Codespaces? (Recommended) + +GitHub Codespaces provides a cloud-based development environment with Docker pre-installed and configured. + +#### Quick Start +1. Click the button below to open this repository in GitHub Codespaces: + +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/jenkins-docs/quickstart-tutorials) + +2. Wait for the Codespace to build (first time: ~2-3 minutes, subsequent starts: ~30 seconds) +3. Once ready, the setup script will automatically install required tools +4. Follow the instructions in the terminal to start a tutorial + +#### What's Included? +- Docker and Docker Compose pre-installed +- `yq` YAML processor for configuration +- GitHub CLI (`gh`) for repository operations +- Automatic port forwarding for Jenkins (8080) and applications (3000, 5000) +- Jenkins URL automatically configured for Codespaces environment + +#### Free Tier +- 60 hours/month for free accounts (sufficient for all tutorials) +- 120 hours/month with [GitHub Student Developer Pack](https://education.github.com/pack) + +### How to Set Up the Repository in GitPod? (Legacy) + +**Note**: GitPod's free tier has sunset. We recommend using GitHub Codespaces instead. - To initialize your Gitpod workspace, prepend `gitpod.io/#` to any GitHub, GitLab, or Bitbucket repository URL. - Access our Gitpod workspace [here](https://gitpod.io/#https://github.com/jenkins-docs/quickstart-tutorials). - If you plan to use Gitpod regularly, we recommend installing the Gitpod extension. This extension adds a Gitpod button to every GitHub repository you visit, making it easy to launch a workspace. You can find the extension [here](https://chrome.google.com/webstore/detail/gitpod-online-ide/dodmmooeoklaejobgleioelladacbeki) for Chromium and [here](https://addons.mozilla.org/firefox/addon/gitpod/) for Firefox. -## Gitpod +## Cloud Development Environments + +### GitHub Codespaces + +GitHub Codespaces is a cloud-based development environment integrated with GitHub. It provides instant, configured development environments with Docker pre-installed, making it perfect for these Jenkins tutorials. + +**Benefits:** +- No local installation required +- Consistent environment for all users +- Free tier: 60 hours/month +- Accessible from any device with a browser +- Automatic backups via GitHub + +### GitPod (Legacy) -Gitpod is a cloud-based development environment designed for teams. It supports various IDEs, including VScode, IntelliJ, and many more, enabling efficient and secure software development. +Gitpod is a cloud-based development environment designed for teams. It supports various IDEs, including VScode, IntelliJ, and many more, enabling efficient and secure software development. However, the free tier is now limited to 10 hours/month. ### Steps to Run Examples from the Repository diff --git a/docker-compose.yaml b/docker-compose.yaml index 9fa37b8a..ab766f4a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -197,7 +197,7 @@ services: node: image: ${IMAGE_PREFIX}/${GHCR_USERNAME}/quickstart-tutorials/jenkinsci-tutorials:node_agent_${BRANCH_SUFFIX} environment: - - GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL} + - GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL:-} container_name: desktop-jenkins_agent-1-node profiles: - node @@ -221,7 +221,7 @@ services: android: image: ${IMAGE_PREFIX}/${GHCR_USERNAME}/quickstart-tutorials/jenkinsci-tutorials:android_agent_${BRANCH_SUFFIX} environment: - - GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL} + - GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL:-} container_name: desktop-jenkins_agent-1-android profiles: - android @@ -266,7 +266,7 @@ services: multi: image: ${IMAGE_PREFIX}/${GHCR_USERNAME}/quickstart-tutorials/jenkinsci-tutorials:node_agent_${BRANCH_SUFFIX} environment: - - GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL} + - GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL:-} container_name: desktop-jenkins_agent-1-multi profiles: - multi @@ -291,7 +291,7 @@ services: golang: image: ${IMAGE_PREFIX}/${GHCR_USERNAME}/quickstart-tutorials/jenkinsci-tutorials:golang_${BRANCH_SUFFIX} environment: - - GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL} + - GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL:-} container_name: desktop-jenkins_agent-1-golang profiles: - golang @@ -315,7 +315,7 @@ services: cpp: image: ${IMAGE_PREFIX}/${GHCR_USERNAME}/quickstart-tutorials/jenkinsci-tutorials:cpp_${BRANCH_SUFFIX} environment: - - GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL} + - GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL:-} container_name: desktop-jenkins_agent-1 profiles: - cpp @@ -339,7 +339,7 @@ services: dotnet: image: ${IMAGE_PREFIX}/${GHCR_USERNAME}/quickstart-tutorials/jenkinsci-tutorials:dotnet_${BRANCH_SUFFIX} environment: - - GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL} + - GITPOD_WORKSPACE_URL=${GITPOD_WORKSPACE_URL:-} container_name: desktop-jenkins_agent-1 profiles: - dotnet diff --git a/dockerfiles/codespacesURL.sh b/dockerfiles/codespacesURL.sh new file mode 100644 index 00000000..c12a9d34 --- /dev/null +++ b/dockerfiles/codespacesURL.sh @@ -0,0 +1,81 @@ +#!/usr/bin/env bash +# GitHub Codespaces URL configuration script for Jenkins +# This script configures Jenkins URLs to work with Codespaces port forwarding + +set -Eeuo pipefail # Exit on error, undefined variables, pipe failures + +# Resolve repo root and config file dynamically +REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" +config_file="${REPO_ROOT}/dockerfiles/jenkins.yaml" + +# Port configuration (default 8080) +PORT="${PORT:-8080}" + +# Check if running in GitHub Codespaces +if [ -n "${CODESPACE_NAME:-}" ] && [ -n "${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:-}" ]; then + # Build Codespaces URL from environment variables + service_url="https://${CODESPACE_NAME}-${PORT}.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" + echo "✅ Detected GitHub Codespaces environment" +else + # Fallback for local development + service_url="http://127.0.0.1:${PORT}" + echo "â„šī¸ Running in local environment" +fi + +# Define an array of available tutorial profiles +targets=("maven" "node" "python" "multi" "cpp" "dotnet" "golang" "android" "default" "wizard") + +# Display information to user +printf "\n" +printf "🚀 Jenkins Quickstart Tutorials Setup\n" +printf "======================================\n" +printf "\n" +printf "Once you run \033[42;30mdocker compose --profile up\033[0m,\n" +printf "Jenkins will be accessible at: \033[36m%s\033[0m\n" "${service_url}" +printf "\n" + +# Display available profiles with color formatting +printf "📚 Available tutorial profiles: " +first=true +for target in "${targets[@]}"; do + if [ "${first}" = true ]; then + printf "\033[36m%s\033[0m" "${target}" + first=false + else + printf ", \033[36m%s\033[0m" "${target}" + fi +done +printf "\n\n" +printf "Quick start commands:\n" +for target in "${targets[@]}"; do + printf " â€ĸ \033[42;30mdocker compose --profile %s up -d\033[0m - Start %s tutorial\n" "${target}" "${target}" +done +printf "\n" + +# Check if jenkins.yaml exists +if [ ! -f "${config_file}" ]; then + echo "âš ī¸ Warning: Jenkins configuration file not found at ${config_file}" + echo " Configuration will be done when Jenkins starts." + exit 0 +fi + +echo "🔧 Updating Jenkins configuration..." + +# Verify yq is available +if ! command -v yq &> /dev/null; then + echo "❌ Error: yq not found. Please install yq to update Jenkins configuration." + echo " Jenkins URL may need manual configuration." + exit 1 +fi + +# Use yq to update the Jenkins location URL in the configuration file +yq -i ".unclassified.location.url = \"${service_url}/\"" "${config_file}" + +# Suppress the Reverse Proxy setup warning for Codespaces +yq -i '.jenkins.disabledAdministrativeMonitors = ["hudson.diagnosis.ReverseProxySetupMonitor"]' "${config_file}" + +echo "✅ Jenkins configuration updated successfully" + +echo "" +echo "🎉 Setup complete! You're ready to start a tutorial." +echo "" diff --git a/updatecli/updatecli.d/codespaces.yaml b/updatecli/updatecli.d/codespaces.yaml new file mode 100644 index 00000000..a8ee9de5 --- /dev/null +++ b/updatecli/updatecli.d/codespaces.yaml @@ -0,0 +1,109 @@ +--- +name: 'deps(codespaces): bump devcontainer dependencies' + +scms: + default: + kind: github + spec: + user: "{{ .github.user }}" + email: "{{ .github.email }}" + owner: "{{ .github.owner }}" + repository: "{{ .github.repository }}" + token: "{{ requiredEnv .github.token }}" + username: "{{ .github.username }}" + branch: "{{ .github.branch }}" + +sources: + yq: + name: Get latest yq release + kind: githubrelease + spec: + owner: mikefarah + repository: yq + token: "{{ requiredEnv .github.token }}" + typefilter: + latest: true + transformers: + - trimprefix: "v" + + docker-version: + name: Get latest Docker stable version + kind: githubrelease + spec: + owner: moby + repository: moby + token: "{{ requiredEnv .github.token }}" + typefilter: + latest: true + transformers: + - trimprefix: "v" + - findsubmatch: + pattern: '^(\d+\.\d+)\.\d+$' + captureindex: 1 + + github-cli: + name: Get latest GitHub CLI release + kind: githubrelease + spec: + owner: cli + repository: cli + token: "{{ requiredEnv .github.token }}" + typefilter: + latest: true + transformers: + - trimprefix: "v" + +conditions: + dockerhub-image-exists: + name: Check if Docker version is available in devcontainer feature + kind: dockerimage + sourceid: docker-version + spec: + # The devcontainer feature uses standard docker versions + image: docker + tag: '{{ source "docker-version" }}' + +targets: + yq-setup-script: + name: '[.devcontainer/setup.sh] Bump yq version' + kind: file + sourceid: yq + scmid: default + spec: + file: .devcontainer/setup.sh + matchpattern: '(YQ_VERSION="\$\{YQ_VERSION:-v)([0-9.]+)(}")' + replacepattern: '${1}{{ source "yq" }}${3}' + + docker-feature-version: + name: '[.devcontainer/devcontainer.json] Bump Docker version' + kind: file + sourceid: docker-version + scmid: default + spec: + file: .devcontainer/devcontainer.json + matchpattern: '("version": ")([0-9.]+)(",)' + replacepattern: '${1}{{ source "docker-version" }}${3}' + search: + pattern: 'ghcr\.io/devcontainers/features/docker-in-docker' + + github-cli-feature-version: + name: '[.devcontainer/devcontainer.json] Bump GitHub CLI version' + kind: file + sourceid: github-cli + scmid: default + spec: + file: .devcontainer/devcontainer.json + matchpattern: '("version": ")([0-9.]+)(")' + replacepattern: '${1}{{ source "github-cli" }}${3}' + search: + pattern: 'ghcr\.io/devcontainers/features/github-cli' + +actions: + default: + kind: github/pullrequest + scmid: default + title: 'chore(deps): update Codespaces dependencies' + spec: + labels: + - dependencies + - codespaces