Update workflow (#15) #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker Publish | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'suricata/Dockerfile' | |
| - 'webapp/Dockerfile' | |
| - 'grafana/Dockerfile' | |
| - 'pcap_broker/Dockerfile' | |
| - 'suricata/**' | |
| - 'webapp/**' | |
| - 'grafana/**' | |
| - 'pcap_broker/**' | |
| - '.github/workflows/docker-publish.yml' | |
| release: | |
| types: | |
| - published | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: docker.io | |
| IMAGE_NAME: ${{ github.repository_owner }} | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - dockerfile: ./suricata/Dockerfile | |
| image_name: digger-suricata | |
| context: . | |
| - dockerfile: ./webapp/Dockerfile | |
| image_name: digger-webapp | |
| context: ./webapp | |
| - dockerfile: ./grafana/Dockerfile | |
| image_name: digger-grafana | |
| context: ./grafana | |
| - dockerfile: ./pcap_broker/Dockerfile | |
| image_name: digger-pcap-broker | |
| context: ./pcap_broker | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Convert repository name to lowercase | |
| id: lowercase | |
| run: echo "image_name=${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]' >> $GITHUB_OUTPUT | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ steps.lowercase.outputs.image_name }}/${{ matrix.image_name }} | |
| tags: | | |
| type=ref,event=branch | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=sha,prefix={{branch}}- | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ${{ matrix.context }} | |
| file: ${{ matrix.dockerfile }} | |
| push: ${{ secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != '' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ steps.lowercase.outputs.image_name }}/${{ matrix.image_name }}:buildcache | |
| cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ steps.lowercase.outputs.image_name }}/${{ matrix.image_name }}:buildcache,mode=max | |
| summary: | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| if: always() | |
| steps: | |
| - name: Create job summary | |
| run: | | |
| echo "## Docker Images Published" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "The following images have been built and pushed:" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- \`docker.io/pwnzer0tt1/digger-suricata\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- \`docker.io/pwnzer0tt1/digger-webapp\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- \`docker.io/pwnzer0tt1/digger-grafana\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- \`docker.io/pwnzer0tt1/digger-pcap-broker\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Tags applied:**" >> $GITHUB_STEP_SUMMARY | |
| echo "- Branch name (for push events)" >> $GITHUB_STEP_SUMMARY | |
| echo "- Semantic version (for releases)" >> $GITHUB_STEP_SUMMARY | |
| echo "- Commit SHA" >> $GITHUB_STEP_SUMMARY | |
| echo "- \`latest\` (for main branch)" >> $GITHUB_STEP_SUMMARY |