DevOps Classroom notes 31/Jul/2026

Build and publish image to nexus matrix method

name: docker build and publish

on: 
  push:
    branches:
      - 'main'

  pull_request:
    branches: '*'
    types:
      - opened
      - closed
      - ready_for_review
      - assigned

  workflow_dispatch:
    inputs:
      docker_repo:
        default: datahub-docker
        description: user select
        type: choice
        options:
          - datahub-docker
          - datahub-docker-snapshot

env:
  docker_host: 3.208.29.184:8081
  repo_name: ${{ github.ref_name == 'main' && 'datahub-docker' || github.event_name == 'workflow_dispatch' && github.event.inputs.docker_repo ||  'datahub-docker-snapshot' }}

jobs:
  docker_buid_publish:
    runs-on: ubuntu-latest
    # if: ${{ github.ref_name == 'main' }}
    strategy:
      matrix:
        service:
          - api-service 
          - backend
          - frontend
    
    steps:
      - name: checkout repo branch
        uses: actions/checkout@v7

      - name:
        run: |
          sudo mkdir -p /etc/docker
          echo '{
            "insecure-registries" : ["3.208.29.184:8081"]
          }' | sudo tee /etc/docker/daemon.json
          sudo systemctl restart docker
      - name: Install docker
        uses: docker/setup-buildx-action@v3
        with:
          driver-opts:
            network=host
          config-inline: |
            [registry."3.208.29.184:8081"]
              http = true
              insecure = true
      - name: Login to Docker Hub
        uses: docker/login-action@v4
        with:
          registry: ${{ env.docker_host }}
          username: ${{ secrets.NEXUS_USERNAME }}
          password: ${{ secrets.NEXUS_PASSWORD }}

      - name: Build and push for Main
        if: ${{ github.ref_name == 'main' || github.event_name == 'workflow_dispatch'  }}
        uses: docker/build-push-action@v7
        with:
          context: ./${{ matrix.service }}
          file: ./${{ matrix.service }}/Dockerfile
          push: true
          tags: |
            ${{ env.docker_host }}/${{ env.repo_name }}/${{ matrix.service }}:${{ github.run_number }}
            ${{ env.docker_host }}/${{ env.repo_name }}/${{ matrix.service }}:latest
      - name: Build and push PR
        if: ${{ github.event_name == 'pull_request' && github.ref_name != 'main'}}
        uses: docker/build-push-action@v7
        with:
          context: ./${{ matrix.service }}
          file: ./${{ matrix.service }}/Dockerfile
          push: true
          tags: |
            ${{ env.docker_host }}/${{ env.repo_name }}/${{ matrix.service }}:${{ github.run_number }}
            ${{ env.docker_host }}/${{ env.repo_name }}/${{ matrix.service }}:latest

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube