update docker flow to local reg
This commit is contained in:
+130
-28
@@ -1,46 +1,148 @@
|
|||||||
name: Docker Build (local only)
|
name: Docker Build & Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main, develop ]
|
branches: [ main, develop ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: host
|
runs-on: host
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
run: |
|
||||||
|
echo "Current workspace: $(pwd)"
|
||||||
|
|
||||||
|
# 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: Docker preflight
|
- name: Check Docker availability
|
||||||
run: |
|
run: |
|
||||||
command -v docker
|
echo "Checking Docker installation..."
|
||||||
docker --version
|
which docker || (echo "Docker not found in PATH" && exit 1)
|
||||||
docker info
|
docker --version || (echo "Docker not available" && exit 1)
|
||||||
|
docker info || (echo "Docker daemon not running" && exit 1)
|
||||||
|
|
||||||
# Build and LOAD the image into the host's Docker (no registry)
|
- name: Build Docker image
|
||||||
- name: Build & load locally
|
run: |
|
||||||
uses: docker/build-push-action@v6
|
echo "Building Docker image..."
|
||||||
with:
|
docker build -t nfoguard:latest .
|
||||||
context: .
|
docker tag nfoguard:latest nfoguard:${{ github.sha }}
|
||||||
push: false
|
echo "Docker image built and tagged successfully"
|
||||||
load: true
|
|
||||||
tags: |
|
- name: Find local Gitea IP
|
||||||
nfoguard:latest
|
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:
|
deploy:
|
||||||
needs: build
|
needs: build
|
||||||
if: github.ref == 'refs/heads/main'
|
|
||||||
runs-on: host
|
runs-on: host
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: (Example) restart local container
|
- name: Deploy application
|
||||||
run: |
|
run: |
|
||||||
docker rm -f nfoguard || true
|
echo "Deploying application..."
|
||||||
docker run -d --name nfoguard \
|
# Add your deployment commands here
|
||||||
--restart unless-stopped \
|
# Examples:
|
||||||
-p 8080:8080 \
|
# docker-compose pull
|
||||||
nfoguard:latest
|
# docker-compose up -d
|
||||||
|
# or
|
||||||
|
# docker stop nfoguard || true
|
||||||
|
# docker run -d --name nfoguard -p 8080:8080 nfoguard:latest
|
||||||
|
echo "Deployment completed"
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user