Add dockerfile (#267)

* Add dockerfile

* Update dockerfile and add docker image release workflow

* Add readme for docker usage

* Swap Docker Hub for Github Container Registry
This commit is contained in:
Dan Sosedoff 2023-01-19 22:33:47 -06:00 committed by GitHub
parent 78e48d6ed3
commit e5ec9ac55d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 0 deletions

47
.github/workflows/docker.yml vendored Normal file
View File

@ -0,0 +1,47 @@
name: Docker
on:
push:
tags:
- "v*"
permissions:
contents: read
packages: write
env:
DOCKER_REPO: ghcr.io/discourse/prometheus_exporter
jobs:
build-and-publish:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Set vars
id: vars
run: |
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- name: Login to Github Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push images
uses: docker/build-push-action@v3
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
build-args: |
GEM_VERSION=${{ steps.vars.outputs.version }}
tags: |
${{ env.DOCKER_REPO }}:${{ steps.vars.outputs.version }}
${{ env.DOCKER_REPO }}:latest

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
ARG RUBY_VERSION=3.1
ARG GEM_VERSION=
FROM ruby:${RUBY_VERSION}-slim
RUN gem install --no-doc --version=${GEM_VERSION} prometheus_exporter
EXPOSE 9394
ENTRYPOINT ["prometheus_exporter", "-b", "ANY"]

View File

@ -32,6 +32,7 @@ To learn more see [Instrumenting Rails with Prometheus](https://samsaffron.com/a
* [Transport concerns](#transport-concerns)
* [JSON generation and parsing](#json-generation-and-parsing)
* [Logging](#logging)
* [Docker Usage](#docker-usage)
* [Contributing](#contributing)
* [License](#license)
* [Code of Conduct](#code-of-conduct)
@ -963,6 +964,28 @@ You can also pass a log level (default is [`Logger::WARN`](https://ruby-doc.org/
PrometheusExporter::Client.new(log_level: Logger::DEBUG)
```
## Docker Usage
You can run `prometheus_exporter` project using an official Docker image:
```bash
docker pull discourse/prometheus_exporter:latest
# or use specific version
docker pull discourse/prometheus_exporter:x.x.x
```
The start the container:
```bash
docker run -p 9394:9394 discourse/prometheus_exporter
```
Additional flags could be included:
```
docker run -p 9394:9394 discourse/prometheus_exporter --verbose --prefix=myapp
```
## Docker/Kubernetes Healthcheck
A `/ping` endpoint which only returns `PONG` is available so you can run container healthchecks :