Remove the build and cloud run experiments

This commit is contained in:
DominicJamesWhite 2025-04-10 19:41:40 +02:00
parent 17f96adf51
commit 09c29cb078
2 changed files with 0 additions and 190 deletions

View File

@ -1,38 +0,0 @@
name: Build and Push Docker Image
on:
push:
branches:
- main
permissions:
contents: read
packages: write
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/dominicjameswhite/canyonchat
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

View File

@ -1,152 +0,0 @@
name: Deploy Cloud Run Services
# Trigger manually from the Actions tab
on:
workflow_dispatch:
env:
GCP_PROJECT_ID: funny-new-goose
GCP_REGION: us-central1 # Or choose another region if needed
GAR_LOCATION: us-central1 # Location of the Artifact Registry repository
GAR_REPOSITORY: github-actions-builds # Name of the Artifact Registry repository
IMAGE_NAME: canyonchat # Name for the Docker image
jobs:
deploy:
runs-on: ubuntu-latest
# Environment variables for the job
env:
SERVICE_CONFIG: ${{ vars.SERVICE_CONFIG }} # Read from GitHub Actions Variable (contains list of service names)
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} # Read from GitHub Actions Secret
CLOUD_RUN_ENV_VARS: ${{ secrets.CLOUD_RUN_ENV_VARS }} # Read from GitHub Actions Secret (contains structured env vars for all services)
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install yq (YAML Processor)
run: |
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
shell: bash
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ env.GCP_SA_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Google Artifact Registry
run: gcloud auth configure-docker ${{ env.GAR_LOCATION }}-docker.pkg.dev --quiet
shell: bash
- name: Build and Push Docker Image
id: build-push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy Services Script
id: deploy
run: |
# Define the image URI based on the build step
BUILT_IMAGE_URI="${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}"
echo "Using built image: $BUILT_IMAGE_URI"
echo "Parsing SERVICE_CONFIG variable:"
echo "${{ env.SERVICE_CONFIG }}"
# Validate SERVICE_CONFIG YAML structure
if ! echo "${{ env.SERVICE_CONFIG }}" | yq '.services | length >= 0' > /dev/null 2>&1; then
echo "::error::SERVICE_CONFIG variable is empty or not valid YAML containing a '.services' array."
exit 1
fi
service_count=$(echo "${{ env.SERVICE_CONFIG }}" | yq '.services | length')
if [ "$service_count" -eq 0 ]; then
echo "No services found in SERVICE_CONFIG. Exiting."
exit 0
fi
echo "Found $service_count services to process."
# Validate CLOUD_RUN_ENV_VARS secret structure
if ! echo "${{ env.CLOUD_RUN_ENV_VARS }}" | yq '.' > /dev/null 2>&1; then
echo "::error::CLOUD_RUN_ENV_VARS secret is empty or not valid YAML/JSON."
exit 1
fi
# Loop through service names defined in SERVICE_CONFIG variable
echo "${{ env.SERVICE_CONFIG }}" | yq -r '.services[]' | while IFS= read -r service_name; do
echo "" # Newline for readability
echo "--- Processing service: $service_name ---"
if [ -z "$service_name" ] || [ "$service_name" == "null" ]; then
echo "::warning::Skipping service with missing or null name in SERVICE_CONFIG."
continue
fi
# --- Extract and Format environment variables for this service ---
# Use yq to extract the object for the current service_name from the CLOUD_RUN_ENV_VARS secret,
# then convert it to KEY=value pairs, and join them with commas.
formatted_env_vars=$(echo "${{ env.CLOUD_RUN_ENV_VARS }}" | yq e ".${service_name} | select(.) | to_entries | map(.key + \"=\\\"\" + .value + \"\\\"\") | join(\",\")" -) # Use yq eval 'e'
if [ -z "$formatted_env_vars" ] || [ "$formatted_env_vars" == "null" ]; then
echo "::warning::No environment variables found for service '$service_name' in CLOUD_RUN_ENV_VARS secret, or the service key doesn't exist."
formatted_env_vars="" # Deploy with no env vars if none found
else
echo "Formatted env vars for gcloud: $formatted_env_vars"
# Mask sensitive values in log output (simple masking, might not catch all formats)
masked_vars=$(echo "$formatted_env_vars" | sed -E 's/(=[^,]+)/=***/g')
echo "Formatted env vars (masked): $masked_vars"
fi
# --- Normalize service name for Cloud Run ---
# Lowercase, replace underscores/spaces with hyphens, remove invalid chars, limit length
normalized_service_name=$(echo "$service_name" | tr '[:upper:]' '[:lower:]' | sed -e 's/[_ ]/-/g' -e 's/[^a-z0-9-]//g')
# Remove leading/trailing hyphens
normalized_service_name=$(echo "$normalized_service_name" | sed -e 's/^-*//' -e 's/-*$//')
# Ensure it's not empty after normalization
if [ -z "$normalized_service_name" ]; then
echo "::error::Service name '$service_name' resulted in an empty string after normalization. Skipping."
continue
fi
# Truncate to 63 characters (Cloud Run limit)
normalized_service_name=${normalized_service_name:0:63}
echo "Normalized service name for Cloud Run: $normalized_service_name"
# --- Deploy using gcloud ---
echo "Deploying $normalized_service_name to $GCP_REGION using image $BUILT_IMAGE_URI..."
gcloud run deploy "$normalized_service_name" \
--image="$BUILT_IMAGE_URI" \
--project="$GCP_PROJECT_ID" \
--region="$GCP_REGION" \
--set-env-vars="$formatted_env_vars" \
--allow-unauthenticated \
--platform=managed \
--quiet # Avoid interactive prompts
if [ $? -ne 0 ]; then
echo "::error::Failed to deploy service $normalized_service_name."
# Optionally exit the loop/workflow on failure:
# exit 1
else
echo "Successfully deployed/updated service $normalized_service_name."
fi
echo "-------------------------------------"
done
shell: bash