From 9e5c6feb477bfad49b7e3f9237645d1391be15e7 Mon Sep 17 00:00:00 2001 From: SBCrumb Date: Tue, 16 Sep 2025 15:29:22 -0400 Subject: [PATCH] adding docker workflow --- .gitea/workflows/ci-dev.yml | 36 +++++++++++++++++ .gitea/workflows/ci.yml | 52 ++++++++++++++++++++++++ docs/DOCKER_HUB_SETUP.md | 79 +++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 docs/DOCKER_HUB_SETUP.md diff --git a/.gitea/workflows/ci-dev.yml b/.gitea/workflows/ci-dev.yml index a130e41..8aacf6d 100644 --- a/.gitea/workflows/ci-dev.yml +++ b/.gitea/workflows/ci-dev.yml @@ -195,6 +195,42 @@ jobs: echo "" echo "🚀 Usage: docker pull $LOCAL_REGISTRY/jskala/nfoguard:dev" + - name: Push DEV to Docker Hub + if: github.ref == 'refs/heads/dev' + run: | + echo "=== Pushing DEV image to Docker Hub ===" + + if echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin; then + echo "✅ Docker Hub login successful" + + DOCKER_HUB_REPO="${{ secrets.DOCKER_HUB_USERNAME }}/nfoguard" + + # Tag and push dev image + docker tag nfoguard:dev "$DOCKER_HUB_REPO:dev" + docker tag nfoguard:dev "$DOCKER_HUB_REPO:dev-${{ github.sha }}" + + echo "=== Pushing DEV tags to Docker Hub ===" + if timeout 300 docker push "$DOCKER_HUB_REPO:dev"; then + echo "✅ DEV tag pushed to Docker Hub" + + if timeout 180 docker push "$DOCKER_HUB_REPO:dev-${{ github.sha }}"; then + echo "✅ DEV SHA tag pushed to Docker Hub" + else + echo "⚠️ DEV SHA tag push failed" + fi + else + echo "❌ Failed to push DEV to Docker Hub" + exit 1 + fi + + echo "" + echo "🎉 DEV image available on Docker Hub!" + echo "📦 DEV image: ${{ secrets.DOCKER_HUB_USERNAME }}/nfoguard:dev" + else + echo "❌ Docker Hub login failed for DEV push" + exit 1 + fi + deploy-dev: needs: build-dev runs-on: host diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 154e27c..5b6517a 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -194,6 +194,58 @@ jobs: echo "🎉 Build workflow completed (using LOCAL network only)!" + - name: Login and Push to Docker Hub + run: | + echo "=== Pushing to Docker Hub ===" + + # Login to Docker Hub + if echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin; then + echo "✅ Docker Hub login successful" + + # Tag images for Docker Hub + DOCKER_HUB_REPO="${{ secrets.DOCKER_HUB_USERNAME }}/nfoguard" + docker tag nfoguard:latest "$DOCKER_HUB_REPO:latest" + docker tag nfoguard:latest "$DOCKER_HUB_REPO:${{ github.sha }}" + docker tag nfoguard:latest "$DOCKER_HUB_REPO:v$(cat VERSION)" + + echo "Images tagged for Docker Hub: $DOCKER_HUB_REPO" + + # Push to Docker Hub + echo "=== Pushing latest tag to Docker Hub ===" + if timeout 300 docker push "$DOCKER_HUB_REPO:latest"; then + echo "✅ Latest tag pushed to Docker Hub" + + echo "=== Pushing version tag to Docker Hub ===" + if timeout 180 docker push "$DOCKER_HUB_REPO:v$(cat VERSION)"; then + echo "✅ Version tag pushed to Docker Hub" + else + echo "⚠️ Version tag push failed" + fi + + echo "=== Pushing SHA tag to Docker Hub ===" + if timeout 180 docker push "$DOCKER_HUB_REPO:${{ github.sha }}"; then + echo "✅ SHA tag pushed to Docker Hub" + else + echo "⚠️ SHA tag push failed" + fi + + else + echo "❌ Failed to push to Docker Hub" + exit 1 + fi + + else + echo "❌ Docker Hub login failed" + exit 1 + fi + + echo "" + echo "🎉 Successfully pushed to both registries!" + echo "" + echo "📦 Available images:" + echo " Local Gitea: 192.168.253.221:3000/jskala/nfoguard:latest" + echo " Docker Hub: ${{ secrets.DOCKER_HUB_USERNAME }}/nfoguard:latest" + deploy: needs: build runs-on: host diff --git a/docs/DOCKER_HUB_SETUP.md b/docs/DOCKER_HUB_SETUP.md new file mode 100644 index 0000000..d6b67c0 --- /dev/null +++ b/docs/DOCKER_HUB_SETUP.md @@ -0,0 +1,79 @@ +# Docker Hub Integration Setup + +## Required Secrets + +Add these secrets to your Gitea repository settings: + +### 1. DOCKER_HUB_USERNAME +- Your Docker Hub username (e.g., "jskala") + +### 2. DOCKER_HUB_TOKEN +- Your Docker Hub access token (NOT your password) + +## Creating a Docker Hub Access Token + +1. Go to [Docker Hub](https://hub.docker.com/) +2. Sign in to your account +3. Click your avatar → **Account Settings** +4. Go to **Security** tab +5. Click **New Access Token** +6. Name it: `NFOGuard-CI` +7. Permissions: **Read, Write, Delete** +8. Click **Generate** +9. **Copy the token immediately** (you won't see it again) + +## Adding Secrets to Gitea + +1. Go to your NFOguard repository in Gitea +2. Click **Settings** → **Secrets** +3. Add the following secrets: + - **Name**: `DOCKER_HUB_USERNAME` + - **Value**: Your Docker Hub username + + - **Name**: `DOCKER_HUB_TOKEN` + - **Value**: The access token you generated + +## What Gets Published + +### Main Branch (Production) +- `yourusername/nfoguard:latest` +- `yourusername/nfoguard:v1.5.2` (version from VERSION file) +- `yourusername/nfoguard:sha-abc123` (git commit SHA) + +### Dev Branch +- `yourusername/nfoguard:dev` +- `yourusername/nfoguard:dev-sha-abc123` + +## Usage Examples + +Once set up, users can pull from either registry: + +```bash +# From your local Gitea registry (fast for you) +docker pull 192.168.253.221:3000/jskala/nfoguard:latest + +# From Docker Hub (public access) +docker pull yourusername/nfoguard:latest + +# Dev versions +docker pull yourusername/nfoguard:dev +``` + +## Testing the Setup + +After adding the secrets, push a commit to trigger the CI: + +```bash +git add . +git commit -m "Add Docker Hub CI integration" +git push origin main +``` + +Watch the Actions tab in Gitea to see both registries being pushed to successfully! + +## Benefits + +- **Local**: Ultra-fast local builds and deployment +- **Public**: Anyone can use `docker pull yourusername/nfoguard:latest` +- **Redundancy**: Multiple image sources +- **Versioning**: Proper semantic versioning across both registries \ No newline at end of file