137 lines
4.7 KiB
YAML
137 lines
4.7 KiB
YAML
name: Docker Build & Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, develop ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: host
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
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: 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: 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 - try without insecure flag first
|
|
REGISTRY="$GITEA_LOCAL_IP:3000"
|
|
echo "Attempting login to local registry: $REGISTRY"
|
|
|
|
# First try normal login
|
|
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 "Normal login failed, trying HTTPS domain 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
|
|
echo "✅ Domain registry login successful"
|
|
} || {
|
|
echo "❌ All login attempts failed"
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
- 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
|
|
runs-on: host
|
|
if: github.ref == 'refs/heads/main'
|
|
|
|
steps:
|
|
- name: Deploy application
|
|
run: |
|
|
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" |