Skip to content

Commit 9522a87

Browse files
committed
Add Dockerfile and GHA recipe to publish container images to GHCR
1 parent c494229 commit 9522a87

File tree

6 files changed

+135
-1
lines changed

6 files changed

+135
-1
lines changed

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*
2+
3+
!*.py
4+
!*.rst
5+
!*.txt
6+
!*.cfg
7+
!*.toml
8+
!LICENSE
9+
!MANIFEST.in
10+
11+
!grafana_wtf
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Stage Docker images through GitHub Actions (GHA) to GitHub Container Registry (GHCR).
2+
#
3+
# https://github.com/docker/build-push-action/blob/master/docs/advanced/tags-labels.md
4+
# https://github.com/crazy-max/ghaction-docker-meta
5+
# https://github.com/docker/build-push-action
6+
7+
name: Build and release container images
8+
9+
on:
10+
schedule:
11+
- cron: '0 10 * * *' # everyday at 10am
12+
push:
13+
tags:
14+
- '*.*.*'
15+
workflow_dispatch:
16+
pull_request:
17+
branches: [ main ]
18+
19+
env:
20+
GHCR_IMAGE_NAME: ghcr.io/panodata/grafana-wtf
21+
22+
jobs:
23+
docker:
24+
runs-on: ubuntu-latest
25+
steps:
26+
-
27+
name: Checkout
28+
uses: actions/checkout@v2
29+
-
30+
name: Docker meta
31+
id: meta
32+
uses: docker/metadata-action@v3
33+
with:
34+
# List of Docker images to use as base name for tags
35+
images: |
36+
${{ env.GHCR_IMAGE_NAME }}
37+
# Generate Docker tags based on the following events/attributes
38+
tags: |
39+
type=schedule,pattern=nightly
40+
type=ref,event=pr
41+
type=semver,pattern={{version}}
42+
type=semver,pattern={{major}}.{{minor}}
43+
-
44+
name: Inspect meta
45+
run: |
46+
echo "Tags: ${{ steps.meta.outputs.tags }}"
47+
echo "Labels: ${{ steps.meta.outputs.labels }}"
48+
-
49+
name: Set up QEMU
50+
uses: docker/setup-qemu-action@v1
51+
-
52+
name: Set up Docker Buildx
53+
id: buildx
54+
uses: docker/setup-buildx-action@v1
55+
-
56+
name: Cache Docker layers
57+
uses: actions/cache@v2
58+
with:
59+
path: /tmp/.buildx-cache
60+
key: ${{ runner.os }}-buildx-${{ github.sha }}
61+
restore-keys: |
62+
${{ runner.os }}-buildx-
63+
-
64+
name: Inspect builder
65+
run: |
66+
echo "Name: ${{ steps.buildx.outputs.name }}"
67+
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
68+
echo "Status: ${{ steps.buildx.outputs.status }}"
69+
echo "Flags: ${{ steps.buildx.outputs.flags }}"
70+
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
71+
-
72+
name: Login to GHCR
73+
# Prevent uploading images for pull requests.
74+
# if: github.event_name != 'pull_request'
75+
uses: docker/login-action@v1
76+
with:
77+
registry: ghcr.io
78+
username: ${{ github.repository_owner }}
79+
password: ${{ github.token }}
80+
-
81+
name: Build and push
82+
uses: docker/build-push-action@v2
83+
with:
84+
context: .
85+
file: Dockerfile
86+
platforms: linux/amd64,linux/arm64,linux/arm/v7
87+
tags: ${{ steps.meta.outputs.tags }}
88+
labels: ${{ steps.meta.outputs.labels }}
89+
# Prevent uploading images for pull requests.
90+
# push: ${{ github.event_name != 'pull_request' }}
91+
push: true
92+
cache-from: type=local,src=/tmp/.buildx-cache
93+
cache-to: type=local,dest=/tmp/.buildx-cache-new
94+
95+
-
96+
name: Move cache
97+
run: |
98+
rm -rf /tmp/.buildx-cache
99+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ in progress
1414
- Add example how to print the Grafana version using the ``info`` subcommand
1515
- Add more information about dashboard entities to ``info`` subcommand
1616
- Blackify code base
17+
- Add ``Dockerfile`` and GHA recipe to publish container images to GHCR
1718

1819
2021-12-10 0.11.1
1920
=================

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM python:3.9-slim-bullseye
2+
3+
ENV DEBIAN_FRONTEND noninteractive
4+
ENV TERM linux
5+
6+
# Install prerequisites
7+
RUN apt-get update
8+
RUN apt-get --yes install jq
9+
10+
# Provide sources
11+
COPY . /app
12+
13+
# Install package
14+
WORKDIR /app
15+
RUN python setup.py install

README.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ Display 50 most recent changes across all dashboards.
5353

5454
grafana-wtf log --number=50
5555

56+
Run with Docker::
57+
58+
# Access Grafana instance on localhost, without authentication.
59+
docker run --rm -it --env GRAFANA_URL="http://host.docker.internal:3000" ghcr.io/panodata/grafana-wtf grafana-wtf info
60+
61+
# Access Grafana instance with authentication.
62+
docker run --rm -it --env GRAFANA_URL="https://daq.grafana.org/grafana" --env GRAFANA_TOKEN="eyJrIjoiWHg...dGJpZCI6MX0=" ghcr.io/panodata/grafana-wtf grafana-wtf info
63+
5664

5765
***********
5866
Screenshots

doc/backlog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ grafana-wtf backlog
66
******
77
Prio 1
88
******
9-
- [o] Dockerize
109
- [o] Statistics reports for data sources and panels: https://github.com/panodata/grafana-wtf/issues/18
1110
- [o] Finding invalid data sources: https://github.com/panodata/grafana-wtf/issues/19
1211
- [o] Add test fixture for adding dashboards at runtime from branch ``amo/test-dashboard-runtime``
@@ -57,3 +56,4 @@ Done
5756
- Display Grafana version: https://grafana.com/docs/grafana/latest/http_api/other/#health-api
5857
- Display number of dashboards, folders, users, and playlists
5958
- [x] Blackify
59+
- [x] Dockerize

0 commit comments

Comments
 (0)