Events: GitHub Action for Docker #8
Workflow file for this run
This file contains 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: 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 }}/${{ env.IMAGE_NAME }} | ||
Check failure on line 16 in .github/workflows/deploy-image.yml GitHub Actions / Create and publish a Docker imageInvalid workflow file
|
||
COMMENT_ANCHOR: "<!--- This comment is auto-generated by a GitHub Action :: ${{ env.TAG_NAME }} --->" | ||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: 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@v4 | ||
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 |