Skip to content

Events: GitHub Action for Docker #13

Events: GitHub Action for Docker

Events: GitHub Action for Docker #13

Workflow file for this run

name: Create and publish a Docker image
on:
push:
branches:
- 'main'
tags:
- 'dvalin-tools-event-agent:v*'
pull_request:
branches:
- 'main'
env:
REGISTRY: ghcr.io
IMAGE_NAME: dvalin-tools-event-agent
TAG_NAME: ${{ github.repository_owner }}/dvalin-tools-event-agent
COMMENT_ANCHOR: "<!--- This comment is auto-generated by a GitHub Action :: ${{ github.repository_owner }}/dvalin-tools-event-agent --->"
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
packages: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.TAG_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:dvalin-tools"
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: runtime-prod
build-args: |
DVALIN_REPO_ROOT_DIR=/usr/src/repo/dvalin-data
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: ${{ env.COMMENT_ANCHOR }}
- name: Add PR comment with Docker image info
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
${{ env.COMMENT_ANCHOR }}
:whale: Docker image for PR #${{ github.event.pull_request.number }} has been built and pushed!
![Static Badge][badge-docker-pr]
**Image:** `${{ env.REGISTRY }}/${{ env.TAG_NAME }}:pr-${{ github.event.pull_request.number }}`
**Docker Pull Command:**
```bash
docker pull ${{ env.REGISTRY }}/${{ env.TAG_NAME }}:pr-${{ github.event.pull_request.number }}
```
For more details, visit our [GitHub Packages][gh-packages].
[gh-packages]: https://github.com/${{ github.repository }}/pkgs/container/${{ env.IMAGE_NAME }}
[badge-docker-pr]: https://img.shields.io/badge/dvalin--tools--event--agent-PR--${{ github.event.pull_request.number }}-blue?logo=docker
reactions: rocket