Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
feat: First version (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
lholota committed Jun 18, 2020
1 parent e88c70e commit 7bb0c4f
Show file tree
Hide file tree
Showing 24 changed files with 361 additions and 78 deletions.
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
* text=auto
*.sh eol=lf
**/run eol=lf
*/services.d/* eol=lf
**/finish eol=lf
*/services.d/* eol=lf
*/alertmanager.yml eof=lf
4 changes: 2 additions & 2 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://developer.github.com/v3/repos/#edit
repository:
name: docker-$$IMAGE_NAME$$
name: docker-prometheus-alertmanager
description: ""
homepage: https://homecentr.github.io/
private: false
Expand All @@ -21,7 +21,7 @@ branches:
protection:
required_status_checks:
strict: true
contexts: [ ".github/workflows/ci.yml" ]
contexts: [ "build" ]
required_pull_request_reviews: null
enforce_admins: false
restrictions:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

env:
IMAGE_NAME: "homecentr/$$IMAGE_NAME$$"
IMAGE_NAME: "homecentr/prometheus-alertmanager"

jobs:
build:
Expand All @@ -30,7 +30,7 @@ jobs:
run: docker build . -t ${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.docker_tag }}

- name: Test Docker image
run: cd tests && sudo gradle test --info -Dimage_tag=${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.docker_tag }}
run: cd tests && sudo gradle test --info -Ddocker_image_tag=${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.docker_tag }}

- name: Scan with Phonito Security
uses: phonito/phonito-scanner-action@master
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- master

env:
IMAGE_NAME: "homecentr/$$IMAGE_NAME$$"
IMAGE_NAME: "homecentr/prometheus-alertmanager"

jobs:
build:
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Test Docker image
if: env.RELEASE_VERSION != ''
run: cd tests && sudo gradle test -Dimage_tag=${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}
run: cd tests && sudo gradle test -Ddocker_image_tag=${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}

- name: Scan with Phonito Security
if: env.RELEASE_VERSION != ''
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/regular_scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
- cron: '0 6 * * *'

env:
IMAGE_NAME: "homecentr/$$IMAGE_NAME$$"
IMAGE_NAME: "homecentr/prometheus-alertmanager"

jobs:
build:
Expand Down
20 changes: 19 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
FROM alpine
FROM prom/alertmanager:v0.21.0 as original

FROM homecentr/base:2.4.0-alpine

ENV ALERTMANAGER_ARGS=""

COPY --from=original /bin/amtool /bin/amtool
COPY --from=original /bin/alertmanager /bin/alertmanager

COPY ./fs/ /

RUN mkdir /config && \
mkdir /alertmanager && \
chmod 777 /alertmanager

EXPOSE 9093

VOLUME /config
VOLUME /alertmanager
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
[![Project status](https://badgen.net/badge/project%20status/stable%20%26%20actively%20maintaned?color=green)](https://github.com/homecentr/docker-$$IMAGE_NAME$$/graphs/commit-activity) [![](https://badgen.net/github/label-issues/homecentr/docker-$$IMAGE_NAME$$/bug?label=open%20bugs&color=green)](https://github.com/homecentr/docker-$$IMAGE_NAME$$/labels/bug) [![](https://badgen.net/github/release/homecentr/docker-$$IMAGE_NAME$$)](https://hub.docker.com/repository/docker/homecentr/$$IMAGE_NAME$$)
[![](https://badgen.net/docker/pulls/homecentr/$$IMAGE_NAME$$)](https://hub.docker.com/repository/docker/homecentr/$$IMAGE_NAME$$)
[![](https://badgen.net/docker/size/homecentr/$$IMAGE_NAME$$)](https://hub.docker.com/repository/docker/homecentr/$$IMAGE_NAME$$)
[![Project status](https://badgen.net/badge/project%20status/stable%20%26%20actively%20maintaned?color=green)](https://github.com/homecentr/docker-prometheus-alertmanager/graphs/commit-activity) [![](https://badgen.net/github/label-issues/homecentr/docker-prometheus-alertmanager/bug?label=open%20bugs&color=green)](https://github.com/homecentr/docker-prometheus-alertmanager/labels/bug) [![](https://badgen.net/github/release/homecentr/docker-prometheus-alertmanager)](https://hub.docker.com/repository/docker/homecentr/prometheus-alertmanager)
[![](https://badgen.net/docker/pulls/homecentr/prometheus-alertmanager)](https://hub.docker.com/repository/docker/homecentr/prometheus-alertmanager)
[![](https://badgen.net/docker/size/homecentr/prometheus-alertmanager)](https://hub.docker.com/repository/docker/homecentr/prometheus-alertmanager)

![CI/CD on master](https://github.com/homecentr/docker-$$IMAGE_NAME$$/workflows/CI/CD%20on%20master/badge.svg)
![Regular Docker image vulnerability scan](https://github.com/homecentr/docker-$$IMAGE_NAME$$/workflows/Regular%20Docker%20image%20vulnerability%20scan/badge.svg)
![CI/CD on master](https://github.com/homecentr/docker-prometheus-alertmanager/workflows/CI/CD%20on%20master/badge.svg)
![Regular Docker image vulnerability scan](https://github.com/homecentr/docker-prometheus-alertmanager/workflows/Regular%20Docker%20image%20vulnerability%20scan/badge.svg)


# HomeCentr - $$IMAGE_NAME$$
# HomeCentr - prometheus-alertmanager

This Docker image is a repack of the original [Prometheus Alertmanager](https://github.com/prometheus/alertmanager) with the usual Homecentr bells and whistles.


## Usage

```yml
version: "3.7"
services:
$$IMAGE_NAME$$:
prometheus-alertmanager:
build: .
image: homecentr/$$IMAGE_NAME$$
image: homecentr/prometheus-alertmanager:local
environment:
ALERTMANAGER_ARGS: "--log.level=debug"
volumes:
- ./example:/config
ports:
- 9093:9093
restart: unless-stopped
```

## Environment variables

| Name | Default value | Description |
|------|---------------|-------------|
| PUID | 7077 | UID of the user $$IMAGE_NAME$$ should be running as. |
| PGID | 7077 | GID of the user $$IMAGE_NAME$$ should be running as. |
| PUID | 7077 | UID of the user prometheus-alertmanager should be running as. |
| PGID | 7077 | GID of the user prometheus-alertmanager should be running as. |
| ALERTMANAGER_ARGS | | Additional command line arguments passed to the Alertmanager executable. Do not specify the `--config.file` and `--storage.path` these are already set by the image. |

## Exposed ports

| Port | Protocol | Description |
|------|------|-------------|
| 80 | TCP | Some useful details |
| 9093 | TCP | Alert manager API |

## Volumes

| Container path | Description |
|------------|---------------|
| /config | Some useful details |
| /config | [Alertmanager Configuration](https://github.com/prometheus/alertmanager#example). The configuration should be in `/config/alertmanager.yml`. |
| /alertmanager | Alertmanager state in case it is restarted. Make sure the PUID/PGID grants the process the rights to write into this directory. |

## Security
The container is regularly scanned for vulnerabilities and updated. Further info can be found in the [Security tab](https://github.com/homecentr/docker-$$IMAGE_NAME$$/security).
The container is regularly scanned for vulnerabilities and updated. Further info can be found in the [Security tab](https://github.com/homecentr/docker-prometheus-alertmanager/security).

### Container user
The container supports privilege drop. Even though the container starts as root, it will use the permissions only to perform the initial set up. The $$IMAGE_NAME$$ process runs as UID/GID provided in the PUID and PGID environment variables.
The container supports privilege drop. Even though the container starts as root, it will use the permissions only to perform the initial set up. The prometheus-alertmanager process runs as UID/GID provided in the PUID and PGID environment variables.

:warning: Do not change the container user directly using the `user` Docker compose property or using the `--user` argument. This would break the privilege drop logic.
10 changes: 8 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
version: "3.7"
services:
$$IMAGE_NAME$$:
prometheus-alertmanager:
build: .
image: homecentr/$$IMAGE_NAME$$
image: homecentr/prometheus-alertmanager:local
environment:
ALERTMANAGER_ARGS: "--log.level=debug"
volumes:
- ./example:/config
ports:
- 9093:9093
restart: unless-stopped
82 changes: 82 additions & 0 deletions example/alertmanager.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
global:
# The smarthost and SMTP sender used for mail notifications.
smtp_smarthost: 'localhost:25'
smtp_from: '[email protected]'

# The root route on which each incoming alert enters.
route:
# The root route must not have any matchers as it is the entry point for
# all alerts. It needs to have a receiver configured so alerts that do not
# match any of the sub-routes are sent to someone.
receiver: 'team-X-mails'

# The labels by which incoming alerts are grouped together. For example,
# multiple alerts coming in for cluster=A and alertname=LatencyHigh would
# be batched into a single group.
#
# To aggregate by all possible labels use '...' as the sole label name.
# This effectively disables aggregation entirely, passing through all
# alerts as-is. This is unlikely to be what you want, unless you have
# a very low alert volume or your upstream notification system performs
# its own grouping. Example: group_by: [...]
group_by: ['alertname']

# When a new group of alerts is created by an incoming alert, wait at
# least 'group_wait' to send the initial notification.
# This way ensures that you get multiple alerts for the same group that start
# firing shortly after another are batched together on the first
# notification.
group_wait: 30s

# When the first notification was sent, wait 'group_interval' to send a batch
# of new alerts that started firing for that group.
group_interval: 5m

# If an alert has successfully been sent, wait 'repeat_interval' to
# resend them.
repeat_interval: 3h

# All the above attributes are inherited by all child routes and can
# overwritten on each.

# The child route trees.
routes:
# This routes performs a regular expression match on alert labels to
# catch alerts that are related to a list of services.
- match_re:
service: ^(foo1|foo2|baz)$
receiver: team-X-mails

# The service has a sub-route for critical alerts, any alerts
# that do not match, i.e. severity != critical, fall-back to the
# parent node and are sent to 'team-X-mails'
routes:
- match:
severity: critical
receiver: team-X-pager


# Inhibition rules allow to mute a set of alerts given that another alert is
# firing.
# We use this to mute any warning-level notifications if the same alert is
# already critical.
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
# Apply inhibition if the alertname is the same.
# CAUTION:
# If all label names listed in `equal` are missing
# from both the source and target alerts,
# the inhibition rule will apply!
equal: ['alertname']

receivers:
- name: 'team-X-mails'
email_configs:
- to: '[email protected], [email protected]'

- name: 'team-X-pager'
email_configs:
- to: '[email protected]'
3 changes: 3 additions & 0 deletions fs/etc/services.d/alertmanager/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/execlineb -S1

s6-svscanctl -t /var/run/s6/services
5 changes: 5 additions & 0 deletions fs/etc/services.d/alertmanager/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/with-contenv ash

cd /alertmanager

exec runas /bin/alertmanager --config.file=/config/alertmanager.yml --storage.path=/alertmanager $ALERTMANAGER_ARGS
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "homecentr-$$IMAGE_NAME$$",
"name": "homecentr-prometheus-alertmanager",
"version": "1.0.0",
"description": "",
"repository": {
"type": "git",
"url": "git+https://github.com/homecentr/docker-$$IMAGE_NAME$$.git"
"url": "git+https://github.com/homecentr/docker-prometheus-alertmanager.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/homecentr/docker-$$IMAGE_NAME$$/issues"
"url": "https://github.com/homecentr/docker-prometheus-alertmanager/issues"
},
"homepage": "https://github.com/homecentr/docker-$$IMAGE_NAME$$#readme"
"homepage": "https://github.com/homecentr/docker-prometheus-alertmanager#readme"
}
6 changes: 0 additions & 6 deletions tests/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
<attribute name="gradle_used_by_scope" value="test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/resources">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7bb0c4f

Please sign in to comment.