This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6db67fb
Showing
6 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: "Build" | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ vars.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Login to ghcr.io | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Generate Docker metadata | ||
id: docker-meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
docker.io/${{ github.repository }} | ||
ghcr.io/${{ github.repository }} | ||
flavor: latest=false | ||
tags: | | ||
type=ref,event=branch | ||
- name: Generate GitHub metadata | ||
id: github-meta | ||
uses: dockerbakery/github-metadata-action@v2 | ||
|
||
- name: Build and push | ||
uses: docker/bake-action@v4 | ||
with: | ||
push: ${{ github.event_name != 'pull_request' }} | ||
files: | | ||
./docker-bake.hcl | ||
${{ steps.docker-meta.outputs.bake-file }} | ||
${{ steps.github-meta.outputs.bake-file }} | ||
set: | | ||
*.cache-from=type=gha | ||
*.cache-to=type=gha,mode=max | ||
- name: Docker Metadata Summary | ||
uses: dockerbakery/docker-metadata-summary@v1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ARG PROMTAIL_VERSION=latest | ||
FROM grafana/promtail:${PROMTAIL_VERSION} | ||
ADD rootfs / | ||
ENTRYPOINT [ "/docker-entrypoint.sh" ] | ||
VOLUME [ "/promtail" ] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
make: | ||
docker buildx bake local --load |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# About | ||
|
||
A customized Grafana Promtail for Docker Swarm. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
variable "PROMTAIL_VERSION" { default = "latest" } | ||
|
||
target "docker-metadata-action" {} | ||
target "github-metadata-action" {} | ||
|
||
target "default" { | ||
inherits = [ "promtail" ] | ||
platforms = [ | ||
"linux/amd64", | ||
"linux/arm64" | ||
] | ||
} | ||
|
||
target "local" { | ||
inherits = [ "promtail" ] | ||
tags = [ "swarmlibs/promtail:local" ] | ||
} | ||
|
||
target "promtail" { | ||
context = "." | ||
dockerfile = "Dockerfile" | ||
inherits = [ | ||
"docker-metadata-action", | ||
"github-metadata-action", | ||
] | ||
args = { | ||
PROMTAIL_VERSION = "${PROMTAIL_VERSION}" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#!/bin/bash | ||
# Copyright (c) Swarm Library Maintainers. | ||
# SPDX-License-Identifier: MIT | ||
|
||
set -e | ||
|
||
PROMTAIL_CONFIG_FILE="/etc/promtail/promtail-config.yaml" | ||
|
||
# -- The log level of the Promtail server | ||
PROMTAIL_LOGLEVEL=${PROMTAIL_LOGLEVEL:-"info"} | ||
|
||
# -- The log format of the Promtail server | ||
# Valid formats: `logfmt, json` | ||
PROMTAIL_LOGFORMAT=${PROMTAIL_LOGFORMAT:-"logfmt"} | ||
|
||
# The config of clients of the Promtail server | ||
PROMTAIL_CLIENT_URL=${PROMTAIL_CLIENT_URL:-"http://loki:3100/loki/api/v1/push"} | ||
|
||
# -- Configures where Promtail will save it's positions file, to resume reading after restarts. | ||
PROMTAIL_POSITION_FILENAME=${PROMTAIL_POSITION_FILENAME:-"/promtail/positions.yaml"} | ||
|
||
# -- The config to enable tracing | ||
PROMTAIL_ENABLE_TRACING=${PROMTAIL_ENABLE_TRACING:-"false"} | ||
|
||
# -- Config file contents for Promtail. | ||
cat <<EOF >${PROMTAIL_CONFIG_FILE} | ||
server: | ||
log_level: ${PROMTAIL_LOGLEVEL} | ||
log_format: ${PROMTAIL_LOGFORMAT} | ||
http_listen_port: 9080 | ||
clients: | ||
- url: ${PROMTAIL_CLIENT_URL} | ||
positions: | ||
filename: ${PROMTAIL_POSITION_FILENAME} | ||
tracing: | ||
enabled: ${PROMTAIL_ENABLE_TRACING} | ||
EOF | ||
|
||
cat <<EOF >>${PROMTAIL_CONFIG_FILE} | ||
scrape_configs: | ||
- job_name: docker | ||
docker_sd_configs: | ||
- host: unix:///var/run/docker.sock | ||
refresh_interval: 10s | ||
relabel_configs: | ||
- source_labels: ['__meta_docker_container_name'] | ||
regex: '/(.*)' | ||
target_label: 'container' | ||
# ================================================================================ | ||
# Label mapping | ||
# ================================================================================ | ||
- action: labelmap | ||
regex: __meta_docker_container_label_com_(docker_.*) | ||
# Rename labels docker_swarm_(.+) to dockerswarm_\$1 | ||
# This is useful for compatibility with "dockerswarm-tasks.yml" relabeling | ||
- action: labelmap | ||
regex: __meta_docker_container_label_com_docker_swarm_(.+) | ||
replacement: dockerswarm_\$1 | ||
- action: labeldrop | ||
regex: (^docker_swarm_.+) | ||
# ================================================================================ | ||
# Docker Swarm compatible relabeling | ||
# - dockerswarm_task_name | ||
# ================================================================================ | ||
# Set "task" label to "<service_name>.<task_slot> | ||
- source_labels: | ||
- dockerswarm_task_name | ||
target_label: task | ||
regex: (.+)\.(.+)\.(.+) | ||
replacement: \$1.\$2 | ||
# ================================================================================ | ||
# Kubernetes compatible relabeling | ||
# - namespace | ||
# - deployment | ||
# - pod | ||
# ================================================================================ | ||
# # Set Kubernetes's Namespace with "com.docker.stack.namespace" label | ||
- source_labels: | ||
- __meta_docker_container_label_com_docker_stack_namespace | ||
target_label: namespace | ||
# Set Kubernetes's Deployment with "com.docker.stack.namespace" label | ||
- source_labels: | ||
- __meta_docker_container_label_com_docker_swarm_service_name | ||
target_label: deployment | ||
# Set Kubernetes's Pod Name with Docker Swarm's Service Name | ||
- source_labels: | ||
- dockerswarm_task_name | ||
target_label: pod | ||
regex: (.*) | ||
EOF | ||
|
||
# If the user is trying to run Prometheus directly with some arguments, then | ||
# pass them to Prometheus. | ||
if [ "${1:0:1}" = '-' ]; then | ||
set -- promtail "$@" | ||
fi | ||
|
||
# If the user is trying to run Prometheus directly with out any arguments, then | ||
# pass the configuration file as the first argument. | ||
if [ "$1" = "" ]; then | ||
set -- promtail -config.file=${PROMTAIL_CONFIG_FILE} | ||
fi | ||
|
||
echo "==> Starting Promtail..." | ||
set -x | ||
exec "$@" |