generated from grafana/grafana-starter-datasource-backend
-
Notifications
You must be signed in to change notification settings - Fork 68
157 lines (133 loc) · 5.07 KB
/
pull-request-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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Create Docker image for local testing
on:
pull_request:
types: [opened, reopened, synchronize]
branches:
- main
permissions:
pull-requests: write
issues: write
jobs:
build:
name: Build and archive plugin build artifacts
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- uses: actions/checkout@v4
- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version-file: '.nvmrc'
- name: Install Go environment
uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Install yarn dependencies
run: yarn install
env:
NODE_OPTIONS: '--max_old_space_size=4096'
- name: Build
run: go build -v ./...
- name: Build Frontend
run: yarn build
env:
NODE_OPTIONS: '--max_old_space_size=4096'
- name: Archive plugin build artifacts
uses: actions/upload-artifact@v4
with:
name: plugin-dist
path: |
dist
retention-days: 1
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
needs: build
steps:
- name: Download plugin build artifacts
uses: actions/download-artifact@v4
id: download
with:
name: plugin-dist
- name: Generate Dockerfile
shell: bash
run: |
echo "FROM grafana/grafana-oss:latest
# Make it as simple as possible to access the grafana instance for development purposes
# Do NOT enable these settings in a public facing / production grafana instance
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
ENV GF_AUTH_ANONYMOUS_ENABLED "true"
ENV GF_AUTH_BASIC_ENABLED "false"
# Set development mode so plugins can be loaded without the need to sign
ENV GF_DEFAULT_APP_MODE "development"
# TODO: Cleanup script should remove images from closed PRs using these labels
LABEL gh-sha="${{ github.event.pull_request.head.sha }}"
LABEL gh-repo="${{ github.event.repository.name }}"
LABEL gh-pr-number="${{ github.event.number }}"
# Copy plugin build artifacts into the image
COPY . /var/lib/grafana/plugins/${{ github.event.repository.name }}/" > Dockerfile
- name: Log in to Docker Hub
uses: docker/login-action@v3
if: github.event.pull_request.head.repo.full_name == github.repository
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
if: github.event.pull_request.head.repo.full_name == github.repository
with:
context: .
file: ./Dockerfile
push: true
tags: grafana/plugin-builds:${{ github.event.pull_request.head.sha }}pre
- name: Build Docker image for use with Docker save
uses: docker/build-push-action@v5
if: ${{github.event.pull_request.head.repo.full_name != github.repository}}
with:
context: .
file: ./Dockerfile
push: false
tags: grafana/plugin-builds:${{ github.event.pull_request.head.sha }}pre
- name: Save Docker image
shell: bash
run: docker save -o ${{ github.event.pull_request.head.sha }}pre.tar grafana/plugin-builds:${{ github.event.pull_request.head.sha }}pre
- name: Archive Docker image
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.pull_request.head.sha }}pre
path: ${{ github.event.pull_request.head.sha }}pre.tar
retention-days: 5
add_pr_comment:
name: Add PR comment
runs-on: ubuntu-latest
needs: push_to_registry
if: github.event.pull_request.head.repo.full_name == github.repository
steps:
- name: Find previous comment (if any)
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.number }}
body-includes: Use the following command to run this PR with Docker
- name: Update comment on PR
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
issue-number: ${{ github.event.number }}
body: |
Use the following command to run this PR with Docker at http://localhost:3000:
```
docker run --rm -p 3000:3000 grafana/plugin-builds:${{ github.event.pull_request.head.sha }}pre
```
- name: Add comment to PR
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.number }}
body: |
Use the following command to run this PR with Docker at http://localhost:3000:
```
docker run --rm -p 3000:3000 grafana/plugin-builds:${{ github.event.pull_request.head.sha }}pre