🤷♂️ don't try to login into registry because it hangs the step
All checks were successful
Build and Deploy Next.js Blog to Production / 🔍 Code Quality Checks (push) Successful in 9m44s
Build and Deploy Next.js Blog to Production / 🏗️ Build and Push Docker Image (push) Successful in 52s
Build and Deploy Next.js Blog to Production / 🚀 Deploy to Production (push) Successful in 50s
All checks were successful
Build and Deploy Next.js Blog to Production / 🔍 Code Quality Checks (push) Successful in 9m44s
Build and Deploy Next.js Blog to Production / 🏗️ Build and Push Docker Image (push) Successful in 52s
Build and Deploy Next.js Blog to Production / 🚀 Deploy to Production (push) Successful in 50s
This commit is contained in:
@@ -9,20 +9,16 @@
|
|||||||
# - PRODUCTION_HOST: IP address or hostname of production server
|
# - PRODUCTION_HOST: IP address or hostname of production server
|
||||||
# - PRODUCTION_USER: SSH username (e.g., 'deployer')
|
# - PRODUCTION_USER: SSH username (e.g., 'deployer')
|
||||||
# - SSH_PRIVATE_KEY: Private SSH key for authentication
|
# - SSH_PRIVATE_KEY: Private SSH key for authentication
|
||||||
# - REGISTRY_USERNAME: Docker registry username (optional, if registry requires auth)
|
|
||||||
# - REGISTRY_PASSWORD: Docker registry password (optional, if registry requires auth)
|
|
||||||
#
|
#
|
||||||
# Environment Variables (configured below):
|
# Environment Variables (configured below):
|
||||||
# - REGISTRY: Docker registry URL
|
# - REGISTRY: Docker registry URL
|
||||||
# - IMAGE_NAME: Docker image name
|
# - IMAGE_NAME: Docker image name
|
||||||
#
|
#
|
||||||
# Docker Registry Authentication Strategy:
|
# Docker Registry Configuration:
|
||||||
# - Registry login is OPTIONAL and conditional
|
# - Current registry (repository.workspace:5000) is INSECURE - no authentication required
|
||||||
# - Login only attempted if REGISTRY_USERNAME and REGISTRY_PASSWORD are configured
|
# - Registry login steps are SKIPPED to avoid 7+ minute timeout delays
|
||||||
# - Login failures are logged but do NOT fail the workflow
|
# - Docker push/pull operations work without credentials
|
||||||
# - Insecure/private registries (e.g., repository.workspace:5000) work without authentication
|
# - If switching to authenticated registry: uncomment login steps and configure secrets
|
||||||
# - If push/pull fails due to auth, the workflow will fail at that point (not at login)
|
|
||||||
# - This approach supports both authenticated and insecure registries without workflow changes
|
|
||||||
|
|
||||||
name: Build and Deploy Next.js Blog to Production
|
name: Build and Deploy Next.js Blog to Production
|
||||||
|
|
||||||
@@ -92,21 +88,32 @@ jobs:
|
|||||||
- name: 🔎 Checkout code
|
- name: 🔎 Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# Optional: Only needed if registry requires authentication
|
# Insecure registry configuration - no authentication required
|
||||||
# For insecure/private registries (e.g., repository.workspace:5000), login is not required
|
# The registry at repository.workspace:5000 does not require login
|
||||||
# Credentials are checked before attempting login to avoid unnecessary failures
|
# Docker push/pull operations work without credentials
|
||||||
- name: 🔐 Log in to Docker Registry (if credentials provided)
|
- name: ℹ️ Registry configuration (insecure - no login required)
|
||||||
run: |
|
run: |
|
||||||
if [ -n "${{ secrets.REGISTRY_USERNAME }}" ] && [ -n "${{ secrets.REGISTRY_PASSWORD }}" ]; then
|
echo "=== Docker Registry Configuration ==="
|
||||||
echo "Logging into ${{ env.REGISTRY }} with credentials..."
|
echo "Registry: ${{ env.REGISTRY }}"
|
||||||
if echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ env.REGISTRY }} -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin 2>/dev/null; then
|
echo "Type: Insecure (no authentication required)"
|
||||||
echo "✅ Login successful"
|
echo ""
|
||||||
else
|
echo "ℹ️ Skipping registry login - insecure registry allows push/pull without credentials"
|
||||||
echo "⚠️ Login failed, continuing anyway (registry might not require auth)"
|
echo ""
|
||||||
fi
|
echo "If your registry requires authentication in the future:"
|
||||||
else
|
echo " 1. Set REGISTRY_USERNAME and REGISTRY_PASSWORD secrets in Gitea"
|
||||||
echo "⚠️ No registry credentials provided - using insecure/public registry (no login required)"
|
echo " 2. Uncomment the login step below this message"
|
||||||
fi
|
echo " 3. Change registry URL to authenticated registry"
|
||||||
|
|
||||||
|
# Uncomment this step if registry requires authentication in the future
|
||||||
|
# - name: 🔐 Log in to Docker Registry
|
||||||
|
# timeout-minutes: 1
|
||||||
|
# run: |
|
||||||
|
# if [ -n "${{ secrets.REGISTRY_USERNAME }}" ] && [ -n "${{ secrets.REGISTRY_PASSWORD }}" ]; then
|
||||||
|
# echo "Attempting login to ${{ env.REGISTRY }}..."
|
||||||
|
# timeout 30s bash -c 'echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ env.REGISTRY }} -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin' || {
|
||||||
|
# echo "⚠️ Login failed - continuing anyway"
|
||||||
|
# }
|
||||||
|
# fi
|
||||||
|
|
||||||
- name: 🏗️ Build Docker image
|
- name: 🏗️ Build Docker image
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
@@ -160,34 +167,29 @@ jobs:
|
|||||||
- name: 🔎 Checkout code (for docker-compose file)
|
- name: 🔎 Checkout code (for docker-compose file)
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# Optional: Validate registry access if authentication is configured
|
# Verify Docker is accessible on production server
|
||||||
# For insecure registries, this step only logs status without failing workflow
|
# Registry authentication is not required for insecure registry
|
||||||
# Actual registry access is tested during image pull in deployment step
|
- name: ℹ️ Verify production server Docker access
|
||||||
- name: 🔐 Validate Registry Access on Production Server
|
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
env:
|
|
||||||
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
||||||
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
||||||
REGISTRY_URL: ${{ env.REGISTRY }}
|
|
||||||
with:
|
with:
|
||||||
host: ${{ vars.PRODUCTION_HOST }}
|
host: ${{ vars.PRODUCTION_HOST }}
|
||||||
username: ${{ vars.PRODUCTION_USER }}
|
username: ${{ vars.PRODUCTION_USER }}
|
||||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
port: 22
|
port: 22
|
||||||
envs: REGISTRY_PASSWORD,REGISTRY_USERNAME,REGISTRY_URL
|
|
||||||
script: |
|
script: |
|
||||||
echo "=== Validating Docker Registry access ==="
|
echo "=== Verifying Docker is accessible ==="
|
||||||
if [ -n "$REGISTRY_USERNAME" ] && [ -n "$REGISTRY_PASSWORD" ]; then
|
docker info > /dev/null 2>&1 || {
|
||||||
echo "Logging into $REGISTRY_URL with credentials..."
|
echo "❌ Docker is not running or user has no access"
|
||||||
if echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY_URL" -u "$REGISTRY_USERNAME" --password-stdin 2>/dev/null; then
|
echo "Please ensure Docker is installed and user is in docker group"
|
||||||
echo "✅ Registry authentication successful"
|
exit 1
|
||||||
else
|
}
|
||||||
echo "⚠️ Login failed - registry might not require authentication"
|
echo "✅ Docker is accessible"
|
||||||
fi
|
|
||||||
else
|
echo ""
|
||||||
echo "⚠️ No registry credentials configured - using insecure/public registry"
|
echo "=== Registry Configuration ==="
|
||||||
echo "ℹ️ Registry connectivity will be validated during image pull"
|
echo "Registry: ${{ env.REGISTRY }}"
|
||||||
fi
|
echo "Type: Insecure (no authentication)"
|
||||||
|
echo "ℹ️ Skipping registry login - push/pull will work without credentials"
|
||||||
|
|
||||||
- name: 📁 Ensure application directory structure
|
- name: 📁 Ensure application directory structure
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
@@ -254,18 +256,12 @@ jobs:
|
|||||||
echo "=== Starting deployment to production server ==="
|
echo "=== Starting deployment to production server ==="
|
||||||
cd /opt/mypage
|
cd /opt/mypage
|
||||||
|
|
||||||
# Log in to Docker registry (skip if credentials not configured)
|
# Registry configuration - insecure registry does not require authentication
|
||||||
# For insecure/private registries (repository.workspace:5000), login is optional
|
echo "=== Registry Configuration ==="
|
||||||
if [ -n "$REGISTRY_USERNAME" ] && [ -n "$REGISTRY_PASSWORD" ]; then
|
echo "Registry: $REGISTRY_URL"
|
||||||
echo "=== Logging in to Docker registry ==="
|
echo "Type: Insecure (no authentication required)"
|
||||||
if echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY_URL" -u "$REGISTRY_USERNAME" --password-stdin 2>/dev/null; then
|
echo "ℹ️ Skipping registry login"
|
||||||
echo "✅ Registry login successful"
|
echo ""
|
||||||
else
|
|
||||||
echo "⚠️ Login failed - continuing anyway (registry might not require auth)"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "⚠️ No registry credentials - using insecure/public registry (no login required)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Pull latest image from registry
|
# Pull latest image from registry
|
||||||
echo "=== Pulling latest Docker image ==="
|
echo "=== Pulling latest Docker image ==="
|
||||||
|
|||||||
Reference in New Issue
Block a user