mirror of
https://github.com/acedanger/finance.git
synced 2025-12-05 22:50:12 -08:00
refactor: improve devcontainer configuration and documentation (#29)
- Fix container image labels to link with GitHub repository - Enhance build script with better error handling - Update documentation with cross-platform build instructions Part of #29
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
FROM mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye
|
FROM mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source="https://github.com/acedanger/finance"
|
LABEL org.opencontainers.image.source=https://github.com/acedanger/finance
|
||||||
LABEL org.opencontainers.image.description="Dev container for Finance App"
|
LABEL org.opencontainers.image.description="Development container for Finance application with Node.js, TypeScript, and dev tools"
|
||||||
|
|
||||||
# Install additional OS packages
|
# Install additional OS packages
|
||||||
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||||
|
|||||||
@@ -8,6 +8,15 @@ GITHUB_USERNAME=$1
|
|||||||
IMAGE_NAME="finance-devcontainer"
|
IMAGE_NAME="finance-devcontainer"
|
||||||
IMAGE_TAG="latest"
|
IMAGE_TAG="latest"
|
||||||
|
|
||||||
|
# Load environment variables from .env file if it exists
|
||||||
|
ENV_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/.env"
|
||||||
|
if [ -f "$ENV_FILE" ]; then
|
||||||
|
echo "Loading environment from $ENV_FILE"
|
||||||
|
# Use grep to find the PAT line and extract the value, handling both Unix and Windows line endings
|
||||||
|
GITHUB_PERSONAL_ACCESS_TOKEN=$(grep -a "^GITHUB_PERSONAL_ACCESS_TOKEN=" "$ENV_FILE" | sed 's/^GITHUB_PERSONAL_ACCESS_TOKEN=//' | tr -d '\r')
|
||||||
|
export GITHUB_PERSONAL_ACCESS_TOKEN
|
||||||
|
fi
|
||||||
|
|
||||||
# Check for required username argument
|
# Check for required username argument
|
||||||
if [ -z "${GITHUB_USERNAME:-}" ]; then
|
if [ -z "${GITHUB_USERNAME:-}" ]; then
|
||||||
echo "Error: GitHub username is required"
|
echo "Error: GitHub username is required"
|
||||||
@@ -24,31 +33,41 @@ for cmd in docker gh; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Verify PAT is loaded
|
||||||
|
if [ -z "${GITHUB_PERSONAL_ACCESS_TOKEN:-}" ]; then
|
||||||
|
echo "Error: GITHUB_PERSONAL_ACCESS_TOKEN is not set"
|
||||||
|
echo "Please ensure it is defined in $ENV_FILE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Check GitHub authentication
|
# Check GitHub authentication
|
||||||
if ! gh auth status >/dev/null 2>&1; then
|
if ! gh auth status >/dev/null 2>&1; then
|
||||||
echo "Error: Not authenticated with GitHub. Please run 'gh auth login' first"
|
echo "Error: Not authenticated with GitHub. Please run 'gh auth login' first"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Get absolute path to Dockerfile
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
|
||||||
|
DOCKERFILE_PATH="$SCRIPT_DIR/Dockerfile"
|
||||||
|
|
||||||
FULL_IMAGE_NAME="ghcr.io/$GITHUB_USERNAME/$IMAGE_NAME:$IMAGE_TAG"
|
FULL_IMAGE_NAME="ghcr.io/$GITHUB_USERNAME/$IMAGE_NAME:$IMAGE_TAG"
|
||||||
|
|
||||||
echo "=== Building Development Container ==="
|
echo "=== Building Development Container ==="
|
||||||
echo "Username: $GITHUB_USERNAME"
|
echo "Username: $GITHUB_USERNAME"
|
||||||
echo "Image: $FULL_IMAGE_NAME"
|
echo "Image: $FULL_IMAGE_NAME"
|
||||||
|
echo "Dockerfile: $DOCKERFILE_PATH"
|
||||||
|
echo "Using PAT: ${GITHUB_PERSONAL_ACCESS_TOKEN:0:4}... (first 4 chars)"
|
||||||
|
|
||||||
# Build the image
|
# Build the image
|
||||||
echo -e "\n=> Building image..."
|
echo -e "\n=> Building image..."
|
||||||
if ! docker build -t "$FULL_IMAGE_NAME" -f Dockerfile .; then
|
if ! docker build -t "$FULL_IMAGE_NAME" -f "$DOCKERFILE_PATH" "$SCRIPT_DIR"; then
|
||||||
echo "Error: Docker build failed"
|
echo "Error: Docker build failed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure logged into GitHub Container Registry
|
# Log in to GitHub Container Registry
|
||||||
echo -e "\n=> Ensuring GitHub Container Registry access..."
|
echo -e "\n=> Logging into GitHub Container Registry..."
|
||||||
if ! docker login ghcr.io -u "$GITHUB_USERNAME"; then
|
echo "$GITHUB_PERSONAL_ACCESS_TOKEN" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin
|
||||||
echo "Error: Failed to authenticate with GitHub Container Registry"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Push to GitHub Container Registry
|
# Push to GitHub Container Registry
|
||||||
echo -e "\n=> Pushing image to GitHub Container Registry..."
|
echo -e "\n=> Pushing image to GitHub Container Registry..."
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -15,16 +15,7 @@ This app is currently deployed using Cloudflare Pages. The logs can be viewed wi
|
|||||||
|
|
||||||
## Development Environment Setup
|
## Development Environment Setup
|
||||||
|
|
||||||
### Prerequisites
|
For detailed setup instructions, including container building, environment configuration, and troubleshooting, see [ENVIRONMENT_SETUP.md](ENVIRONMENT_SETUP.md).
|
||||||
- VS Code with Remote Containers extension
|
|
||||||
- Docker and Docker Compose
|
|
||||||
- Git
|
|
||||||
|
|
||||||
### Initial Setup
|
|
||||||
1. Clone the repository
|
|
||||||
2. Copy `.devcontainer/.env.example` to `.devcontainer/.env`
|
|
||||||
3. Update the environment variables in `.devcontainer/.env`
|
|
||||||
4. Open the project in VS Code and select "Reopen in Container" when prompted
|
|
||||||
|
|
||||||
### GitHub MCP Server
|
### GitHub MCP Server
|
||||||
The project uses GitHub's MCP server for development tasks. The server runs in a Docker container and is automatically configured when you open the project in a devcontainer.
|
The project uses GitHub's MCP server for development tasks. The server runs in a Docker container and is automatically configured when you open the project in a devcontainer.
|
||||||
|
|||||||
Reference in New Issue
Block a user