mirror of
https://github.com/acedanger/finance.git
synced 2025-12-05 22:50:12 -08:00
feat: enhance devcontainer build script with better error handling (#29)
- Add tool availability checks - Add GitHub authentication verification - Improve error messages and user feedback - Add clear next steps for users Part of #29
This commit is contained in:
@@ -1,28 +1,73 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit on error, undefined variables, and pipe failures
|
||||
set -euo pipefail
|
||||
|
||||
# Configuration
|
||||
GITHUB_USERNAME=$1
|
||||
IMAGE_NAME="finance-devcontainer"
|
||||
IMAGE_TAG="latest"
|
||||
|
||||
if [ -z "$GITHUB_USERNAME" ]; then
|
||||
# Check for required username argument
|
||||
if [ -z "${GITHUB_USERNAME:-}" ]; then
|
||||
echo "Error: GitHub username is required"
|
||||
echo "Usage: $0 <github_username>"
|
||||
echo "Example: $0 acedanger"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for required tools
|
||||
for cmd in docker gh; do
|
||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||
echo "Error: $cmd is required but not installed"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# Check GitHub authentication
|
||||
if ! gh auth status >/dev/null 2>&1; then
|
||||
echo "Error: Not authenticated with GitHub. Please run 'gh auth login' first"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FULL_IMAGE_NAME="ghcr.io/$GITHUB_USERNAME/$IMAGE_NAME:$IMAGE_TAG"
|
||||
|
||||
echo "=== Building Development Container ==="
|
||||
echo "Username: $GITHUB_USERNAME"
|
||||
echo "Image: $FULL_IMAGE_NAME"
|
||||
|
||||
# Build the image
|
||||
echo "Building image: $FULL_IMAGE_NAME"
|
||||
docker build -t $FULL_IMAGE_NAME -f Dockerfile .
|
||||
echo -e "\n=> Building image..."
|
||||
if ! docker build -t "$FULL_IMAGE_NAME" -f Dockerfile .; then
|
||||
echo "Error: Docker build failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure logged into GitHub Container Registry
|
||||
echo -e "\n=> Ensuring GitHub Container Registry access..."
|
||||
if ! docker login ghcr.io -u "$GITHUB_USERNAME"; then
|
||||
echo "Error: Failed to authenticate with GitHub Container Registry"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Push to GitHub Container Registry
|
||||
echo "Pushing image to GHCR..."
|
||||
docker push $FULL_IMAGE_NAME
|
||||
echo -e "\n=> Pushing image to GitHub Container Registry..."
|
||||
if ! docker push "$FULL_IMAGE_NAME"; then
|
||||
echo "Error: Failed to push image"
|
||||
echo "Please check your GitHub PAT has the required permissions:"
|
||||
echo " - read:packages"
|
||||
echo " - write:packages"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Done! Now update your devcontainer.json to use this image:"
|
||||
echo "Replace the 'build' section with:"
|
||||
echo -e "\n=== Success! ==="
|
||||
echo "The development container image has been built and pushed"
|
||||
echo -e "\nTo use this image, update your devcontainer.json with:"
|
||||
echo '{
|
||||
"image": "'$FULL_IMAGE_NAME'"
|
||||
}'
|
||||
}'
|
||||
|
||||
echo -e "\nNext steps:"
|
||||
echo "1. Update .devcontainer/devcontainer.json with the image reference above"
|
||||
echo "2. Rebuild your development container in VS Code"
|
||||
echo " (Command Palette -> 'Dev Containers: Rebuild Container')"
|
||||
Reference in New Issue
Block a user