-
Notifications
You must be signed in to change notification settings - Fork 3
100 lines (84 loc) · 3.36 KB
/
deploy-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
IMAGE_NAME_DOUBLE_DASH: 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
reactions: rocket
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 }}`
Install from the command line
```bash
docker pull ${{ env.REGISTRY }}/${{ env.TAG_NAME }}:pr-${{ github.event.pull_request.number }}
```
Use as base image in Dockerfile:
```Dockerfile
FROM ${{ 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/${{ env.IMAGE_NAME_DOUBLE_DASH }}-PR--${{ github.event.pull_request.number }}-blue?logo=docker