|
| 1 | +name: Build and Push Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - 'v*.*.*' |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +env: |
| 15 | + IMAGE_NAME: secops-mcp-server |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-and-push: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + packages: write |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Set up Docker Buildx |
| 29 | + uses: docker/setup-buildx-action@v3 |
| 30 | + |
| 31 | + - name: Log in to private registry |
| 32 | + uses: docker/login-action@v3 |
| 33 | + with: |
| 34 | + registry: ${{ secrets.DOCKER_REGISTRY_URL }} |
| 35 | + username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} |
| 36 | + password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} |
| 37 | + |
| 38 | + - name: Extract metadata (tags, labels) for Docker |
| 39 | + id: meta |
| 40 | + uses: docker/metadata-action@v5 |
| 41 | + with: |
| 42 | + images: ${{ secrets.DOCKER_REGISTRY_URL }}/${{ env.IMAGE_NAME }} |
| 43 | + tags: | |
| 44 | + # Tag with branch name for branch pushes |
| 45 | + type=ref,event=branch |
| 46 | + # Tag with PR number for pull requests |
| 47 | + type=ref,event=pr |
| 48 | + # Tag with semver for version tags |
| 49 | + type=semver,pattern={{version}} |
| 50 | + type=semver,pattern={{major}}.{{minor}} |
| 51 | + type=semver,pattern={{major}} |
| 52 | + # Tag with 'latest' for main branch |
| 53 | + type=raw,value=latest,enable={{is_default_branch}} |
| 54 | + # Tag with short SHA |
| 55 | + type=sha,prefix={{branch}}- |
| 56 | +
|
| 57 | + - name: Build and push Docker image |
| 58 | + uses: docker/build-push-action@v6 |
| 59 | + with: |
| 60 | + context: . |
| 61 | + file: ./Dockerfile |
| 62 | + push: ${{ github.event_name != 'pull_request' }} |
| 63 | + tags: ${{ steps.meta.outputs.tags }} |
| 64 | + labels: ${{ steps.meta.outputs.labels }} |
| 65 | + cache-from: type=gha |
| 66 | + cache-to: type=gha,mode=max |
| 67 | + platforms: linux/amd64,linux/arm64 |
| 68 | + |
| 69 | + - name: Image digest |
| 70 | + run: echo "Image pushed with digest ${{ steps.build-push.outputs.digest }}" |
0 commit comments