update docker flow to local reg

This commit is contained in:
2025-09-09 16:07:16 -04:00
parent 39073dcb70
commit 626f9bd86e
2 changed files with 158 additions and 28 deletions
+127 -25
View File
@@ -1,46 +1,148 @@
name: Docker Build (local only)
name: Docker Build & Deploy
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build:
runs-on: host
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker preflight
- name: Checkout code
run: |
command -v docker
docker --version
docker info
echo "Current workspace: $(pwd)"
# Build and LOAD the image into the host's Docker (no registry)
- name: Build & load locally
uses: docker/build-push-action@v6
with:
context: .
push: false
load: true
tags: |
nfoguard:latest
# Clean workspace first
rm -rf * .git* 2>/dev/null || true
# Clone the repository since Gitea runner doesn't auto-checkout
echo "Cloning repository..."
git clone https://gitea.skalas.org/jskala/NFOguard.git /tmp/repo
cp -r /tmp/repo/* .
cp -r /tmp/repo/.* . 2>/dev/null || true
rm -rf /tmp/repo
echo "Repository cloned successfully"
ls -la
echo "Checking Dockerfile:"
head -30 Dockerfile
- name: Check Docker availability
run: |
echo "Checking Docker installation..."
which docker || (echo "Docker not found in PATH" && exit 1)
docker --version || (echo "Docker not available" && exit 1)
docker info || (echo "Docker daemon not running" && exit 1)
- name: Build Docker image
run: |
echo "Building Docker image..."
docker build -t nfoguard:latest .
docker tag nfoguard:latest nfoguard:${{ github.sha }}
echo "Docker image built and tagged successfully"
- name: Find local Gitea IP
run: |
echo "Using known local Gitea IP: 192.168.253.221"
GITEA_LOCAL_IP="192.168.253.221"
# Test connectivity to local IP
echo "Testing local connectivity..."
if timeout 3 curl -s "http://$GITEA_LOCAL_IP:3000" >/dev/null 2>&1; then
echo "✅ Local Gitea accessible at $GITEA_LOCAL_IP:3000"
else
echo "❌ Cannot reach local Gitea at $GITEA_LOCAL_IP:3000"
fi
# Test registry endpoint
if timeout 3 curl -s "http://$GITEA_LOCAL_IP:3000/v2/" >/dev/null 2>&1; then
echo "✅ Registry endpoint accessible"
else
echo "❌ Registry endpoint not accessible"
fi
# Export for other steps
echo "GITEA_LOCAL_IP=$GITEA_LOCAL_IP" >> $GITHUB_ENV
echo "Using Gitea at: $GITEA_LOCAL_IP"
- name: Configure Docker for insecure registry
run: |
echo "Configuring Docker to allow insecure registry..."
REGISTRY="$GITEA_LOCAL_IP:3000"
# Backup existing daemon.json if it exists
sudo cp /etc/docker/daemon.json /etc/docker/daemon.json.bak 2>/dev/null || true
# Create or update daemon.json to allow insecure registry
echo "{\"insecure-registries\":[\"$REGISTRY\"]}" | sudo tee /etc/docker/daemon.json
# Reload Docker daemon
sudo systemctl reload docker
sleep 3
echo "Docker configured for insecure registry: $REGISTRY"
- name: Login to Gitea registry
run: |
echo "Logging into Gitea container registry..."
export DOCKER_CONFIG=/tmp/docker-config
mkdir -p $DOCKER_CONFIG
# Use local IP for login (now configured as insecure registry)
REGISTRY="$GITEA_LOCAL_IP:3000"
echo "Attempting login to local registry: $REGISTRY"
echo "${{ secrets.token }}" | docker --config $DOCKER_CONFIG login "$REGISTRY" -u "${{ secrets.username }}" --password-stdin && {
echo "REGISTRY_URL=$REGISTRY" >> $GITHUB_ENV
echo "✅ Local registry login successful"
} || {
echo "❌ Local login failed, trying domain name as fallback..."
echo "${{ secrets.token }}" | docker --config $DOCKER_CONFIG login gitea.skalas.org -u "${{ secrets.username }}" --password-stdin
echo "REGISTRY_URL=gitea.skalas.org" >> $GITHUB_ENV
}
- name: Push to Gitea registry
run: |
echo "Pushing to Gitea container registry at: ${REGISTRY_URL:-gitea.skalas.org}"
export DOCKER_CONFIG=/tmp/docker-config
# Use the discovered registry URL or fallback to domain name
REGISTRY=${REGISTRY_URL:-gitea.skalas.org}
# Retag images for the correct registry
docker tag nfoguard:latest "$REGISTRY/jskala/nfoguard:latest"
docker tag nfoguard:latest "$REGISTRY/jskala/nfoguard:${{ github.sha }}"
echo "Pushing to $REGISTRY..."
timeout 300 docker --config $DOCKER_CONFIG push "$REGISTRY/jskala/nfoguard:latest" && {
echo "First image pushed successfully"
timeout 300 docker --config $DOCKER_CONFIG push "$REGISTRY/jskala/nfoguard:${{ github.sha }}" && {
echo "Both images pushed successfully!"
} || echo "Second push failed"
} || {
echo "Push failed. Registry: $REGISTRY"
echo "Images available:"
docker images | grep nfoguard
exit 1
}
deploy:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: host
if: github.ref == 'refs/heads/main'
steps:
- name: (Example) restart local container
- name: Deploy application
run: |
docker rm -f nfoguard || true
docker run -d --name nfoguard \
--restart unless-stopped \
-p 8080:8080 \
nfoguard:latest
echo "Deploying application..."
# Add your deployment commands here
# Examples:
# docker-compose pull
# docker-compose up -d
# or
# docker stop nfoguard || true
# docker run -d --name nfoguard -p 8080:8080 nfoguard:latest
echo "Deployment completed"
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
echo "=== Finding Gitea Local IP ==="
# Get local IP of gitea-lxc container
echo "1. Checking local IPs..."
ip addr show | grep -E "inet.*192\.|inet.*10\.|inet.*172\." || echo "No local IPs found"
echo "2. Trying to resolve gitea-lxc locally..."
ping -c 1 gitea-lxc 2>/dev/null | head -1 || echo "gitea-lxc not resolvable"
echo "3. Checking for Gitea process..."
ps aux | grep gitea || echo "No gitea process found"
echo "4. Checking what ports are listening..."
ss -tulpn | grep :3000 || echo "Port 3000 not listening"
ss -tulpn | grep :80 || echo "Port 80 not listening"
ss -tulpn | grep :443 || echo "Port 443 not listening"
echo "5. Testing local connection..."
LOCAL_IP=$(ip route get 8.8.8.8 | awk '{print $7; exit}')
echo "Local IP appears to be: $LOCAL_IP"
if [ ! -z "$LOCAL_IP" ]; then
echo "Testing HTTP connection to local IP..."
curl -s -o /dev/null -w "HTTP Status: %{http_code}\n" "http://$LOCAL_IP:3000/" || echo "Local HTTP not responding"
curl -s -o /dev/null -w "HTTP Status: %{http_code}\n" "http://$LOCAL_IP/" || echo "Local HTTP port 80 not responding"
fi