Skip to content

Commit 025ad17

Browse files
authored
Merge pull request #12 from swisscom/master
merge back updates
2 parents 6726fc3 + ba2b7c6 commit 025ad17

File tree

33 files changed

+2667
-56
lines changed

33 files changed

+2667
-56
lines changed

.circleci/config.yml

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
build:
1111
docker:
1212
# primary image for building app
13-
- image: circleci/golang:1.15
13+
- image: cimg/go:1.16-node
1414

1515
# service images available at `host: localhost`
1616
- image: circleci/postgres:12-alpine
@@ -24,15 +24,13 @@ jobs:
2424
MYSQL_DATABASE: mysql
2525
MYSQL_ROOT_PASSWORD: my-secret-pw
2626

27-
- image: circleci/mongo:3.6
27+
- image: circleci/mongo:4.4
2828
environment:
2929
MONGO_INITDB_ROOT_USERNAME: mongoadmin
3030
MONGO_INITDB_ROOT_PASSWORD: super-secret
3131

3232
- image: circleci/redis:5.0
3333

34-
working_directory: /go/src/github.com/swisscom/backman
35-
3634
steps:
3735
- checkout
3836

@@ -41,6 +39,12 @@ jobs:
4139

4240
# build binary
4341
- run: make build
42+
- run:
43+
name: install binary
44+
command: |
45+
chmod +x /home/circleci/project/backman
46+
sudo cp /home/circleci/project/backman /usr/local/bin/backman
47+
sudo chmod +x /usr/local/bin/backman
4448
4549
# minIO server
4650
- run:
@@ -56,6 +60,13 @@ jobs:
5660
MINIO_ACCESS_KEY: 6d611e2d-330b-4e52-a27c-59064d6e8a62
5761
MINIO_SECRET_KEY: eW9sbywgeW91IGhhdmUganVzdCBiZWVuIHRyb2xsZWQh
5862

63+
# killall
64+
- run:
65+
name: install killall
66+
command: |
67+
sudo apt-get update
68+
sudo apt-get -y install psmisc
69+
5970
# jq
6071
- run:
6172
name: install jq
@@ -78,23 +89,20 @@ jobs:
7889
- run:
7990
name: install MongoDB client
8091
command: |
81-
sudo apt-get install -y libcurl4
82-
wget https://repo.mongodb.org/apt/debian/dists/stretch/mongodb-org/3.6/main/binary-amd64/mongodb-org-server_3.6.14_amd64.deb -qO mongodb-org-server_3.6.14_amd64.deb
83-
sudo dpkg -i --ignore-depends=libcurl3 mongodb-org-server_3.6.14_amd64.deb
84-
wget https://repo.mongodb.org/apt/debian/dists/stretch/mongodb-org/3.6/main/binary-amd64/mongodb-org-shell_3.6.14_amd64.deb -qO mongodb-org-shell_3.6.14_amd64.deb
85-
sudo dpkg -i --ignore-depends=libcurl3 mongodb-org-shell_3.6.14_amd64.deb
86-
wget https://repo.mongodb.org/apt/debian/dists/stretch/mongodb-org/4.2/main/binary-amd64/mongodb-org-tools_4.2.0_amd64.deb -qO mongodb-org-tools_4.2.0_amd64.deb
87-
sudo dpkg -i --ignore-depends=libcurl3 mongodb-org-tools_4.2.0_amd64.deb
92+
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
93+
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
94+
sudo apt-get update
95+
sudo apt-get install -y mongodb-database-tools=100.5.0 mongodb-org-tools=5.0.2 mongodb-org-shell=5.0.2
8896
- run: make mongodb-test
8997

90-
# mysql integration tests
91-
- run:
92-
name: install MySQL client
93-
command: sudo apt install -y mariadb-client
94-
- run: make mysql-test
95-
9698
# redis integration tests
9799
- run:
98100
name: install Redis client
99101
command: sudo apt install -y redis-tools
100102
- run: make redis-test
103+
104+
# mysql integration tests
105+
- run:
106+
name: install MySQL client
107+
command: sudo apt install -y mariadb-client
108+
- run: make mysql-test

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ RUN echo "debconf debconf/frontend select noninteractive" | debconf-set-selectio
66
apt-get -y $package_args update && \
77
apt-get -y $package_args dist-upgrade && \
88
apt-get -y $package_args install curl ca-certificates gnupg tzdata git
9-
RUN curl --location --output go.tar.gz "https://golang.org/dl/go1.16.3.linux-amd64.tar.gz" && \
10-
echo "951a3c7c6ce4e56ad883f97d9db74d3d6d80d5fec77455c6ada6c1f7ac4776d2 go.tar.gz" | sha256sum -c && \
9+
RUN curl --location --output go.tar.gz "https://golang.org/dl/go1.16.7.linux-amd64.tar.gz" && \
10+
echo "7fe7a73f55ba3e2285da36f8b085e5c0159e9564ef5f63ee0ed6b818ade8ef04 go.tar.gz" | sha256sum -c && \
1111
tar -C /usr/local -xzf go.tar.gz && \
1212
rm go.tar.gz
1313

@@ -28,12 +28,12 @@ RUN echo "debconf debconf/frontend select noninteractive" | debconf-set-selectio
2828
apt-get -y $package_args install curl ca-certificates gnupg tzdata
2929

3030
RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
31-
curl https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add - && \
31+
curl https://www.mongodb.org/static/pgp/server-5.0.asc | apt-key add - && \
3232
echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
33-
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" > /etc/apt/sources.list.d/mongodb-org-4.4.list
33+
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/5.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-5.0.list
3434
RUN curl -sL https://deb.nodesource.com/setup_lts.x | bash -
3535
RUN apt-get -y $package_args update && \
36-
apt-get -y $package_args install mysql-client postgresql-client-12 mongodb-org-tools=4.4.5 mongodb-org-shell=4.4.5 redis-tools nodejs openssh-server bash vim && \
36+
apt-get -y $package_args install mysql-client postgresql-client-12 mongodb-database-tools=100.5.0 mongodb-org-tools=5.0.2 mongodb-org-shell=5.0.2 redis-tools nodejs openssh-server bash vim && \
3737
apt-get clean && \
3838
find /usr/share/doc/*/* ! -name copyright | xargs rm -rf && \
3939
rm -rf \

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DEFAULT_GOAL := run
22
SHELL := /bin/bash
3-
APP ?= $(shell basename $$(pwd))
3+
APP = backman
44
COMMIT_SHA = $(shell git rev-parse --short HEAD)
55
DOCKER_TAG = latest
66

@@ -13,12 +13,12 @@ help:
1313
.PHONY: run
1414
## run: runs main.go with the race detector
1515
run:
16-
source .env; source .env_*; go run -race main.go
16+
source .env; source .env_*; source .env_teams; go run -race main.go
1717

1818
.PHONY: gin
1919
## gin: runs main.go via gin (hot reloading)
2020
gin:
21-
source .env; source .env_*; gin --all --immediate run main.go
21+
source .env; source .env_*; source .env_teams; gin --all --immediate run main.go
2222

2323
.PHONY: build
2424
## build: builds the application

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ These here are the default values backman will use if not configured via JSON:
4949
"disable_web": false,
5050
"disable_metrics": false,
5151
"unprotected_metrics": false,
52+
"notifications": {
53+
"teams": {
54+
"webhook": "https://example.webhook.office.com/webhookb2/deadbeef/IncomingWebhook/beefdead/deadbeef",
55+
"events": ["backup-success", "backup-failed"]
56+
}
57+
},
5258
"s3": {
5359
"service_label": "dynstrg",
5460
"encryption_key":"a_super_strong_key"
@@ -85,6 +91,8 @@ Possible JSON properties:
8591
- `disable_web`: optional, disable web interface and api
8692
- `disable_metrics`: optional, disable Prometheus metrics endpoint
8793
- `unprotected_metrics`: optional, disable HTTP basic auth protection for Prometheus metrics endpoint
94+
- `notifications.teams.webhook`: optional, setting a webhook URL will enable MS Teams notifications about backups
95+
- `notifications.teams.events`: optional, list of events to send a Teams notification for. Can be *backup-started*, *backup-success*, *backup-failed*. Sends a notification for all events if empty.
8896
- `s3.disable_ssl`: optional, S3 client connections will use HTTP instead of HTTPS
8997
- `s3.skip_ssl_verification`: optional, S3 client will still use HTTPS but skips certificate verification
9098
- `s3.service_label`: optional, defines which service label backman will look for to find the S3-compatible object storage

apt.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
---
22
keys:
33
- https://www.postgresql.org/media/keys/ACCC4CF8.asc
4-
- https://www.mongodb.org/static/pgp/server-4.4.asc
4+
- https://www.mongodb.org/static/pgp/server-5.0.asc
55
repos:
66
- deb https://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main
7-
- deb https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse
7+
- deb https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/5.0 multiverse
88
packages:
99
- mysql-client
1010
- postgresql-client-12
11-
- mongodb-org-tools=4.4.0
12-
- mongodb-org-shell=4.4.0
11+
- mongodb-org-shell=5.0.2
12+
- mongodb-org-tools=5.0.2
13+
- mongodb-database-tools=100.5.0
1314
- redis-tools

config/config.go

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io/ioutil"
77
"log"
88
"os"
9+
"strings"
910
"sync"
1011
"time"
1112
)
@@ -20,9 +21,10 @@ type Config struct {
2021
LoggingTimestamp bool `json:"logging_timestamp"`
2122
Username string
2223
Password string
23-
DisableWeb bool `json:"disable_web"`
24-
DisableMetrics bool `json:"disable_metrics"`
25-
UnprotectedMetrics bool `json:"unprotected_metrics"`
24+
DisableWeb bool `json:"disable_web"`
25+
DisableMetrics bool `json:"disable_metrics"`
26+
UnprotectedMetrics bool `json:"unprotected_metrics"`
27+
Notifications NotificationConfig `json:"notifications"`
2628
S3 S3Config
2729
Services map[string]ServiceConfig
2830
Foreground bool
@@ -52,6 +54,15 @@ type ServiceConfig struct {
5254
RestoreOptions []string `json:"restore_options"`
5355
}
5456

57+
type NotificationConfig struct {
58+
Teams TeamsNotificationConfig `json:"teams,omitempty"`
59+
}
60+
61+
type TeamsNotificationConfig struct {
62+
Webhook string `json:"webhook"`
63+
Events []string `json:"events"`
64+
}
65+
5566
type TimeoutDuration struct {
5667
time.Duration
5768
}
@@ -132,6 +143,12 @@ func Get() *Config {
132143
if envConfig.UnprotectedMetrics {
133144
config.UnprotectedMetrics = envConfig.UnprotectedMetrics
134145
}
146+
if len(envConfig.Notifications.Teams.Webhook) > 0 {
147+
config.Notifications.Teams.Webhook = envConfig.Notifications.Teams.Webhook
148+
}
149+
if len(envConfig.Notifications.Teams.Events) > 0 {
150+
config.Notifications.Teams.Events = envConfig.Notifications.Teams.Events
151+
}
135152
if envConfig.S3.DisableSSL {
136153
config.S3.DisableSSL = envConfig.S3.DisableSSL
137154
}
@@ -195,16 +212,32 @@ func Get() *Config {
195212
}
196213

197214
// use username & password from env if defined
198-
if len(os.Getenv("BACKMAN_USERNAME")) > 0 {
199-
config.Username = os.Getenv("BACKMAN_USERNAME")
215+
if os.Getenv(BackmanUsername) != "" {
216+
config.Username = os.Getenv(BackmanUsername)
200217
}
201-
if len(os.Getenv("BACKMAN_PASSWORD")) > 0 {
202-
config.Password = os.Getenv("BACKMAN_PASSWORD")
218+
if os.Getenv(BackmanPassword) != "" {
219+
config.Password = os.Getenv(BackmanPassword)
203220
}
204221

205222
// use s3 encryption key from env if defined
206-
if len(os.Getenv("BACKMAN_ENCRYPTION_KEY")) > 0 {
207-
config.S3.EncryptionKey = os.Getenv("BACKMAN_ENCRYPTION_KEY")
223+
if os.Getenv(BackmanEncryptionKey) != "" {
224+
config.S3.EncryptionKey = os.Getenv(BackmanEncryptionKey)
225+
}
226+
227+
// use teams webhook url from env if defined
228+
if os.Getenv(BackmanTeamsWebhook) != "" {
229+
config.Notifications.Teams.Webhook = os.Getenv(BackmanTeamsWebhook)
230+
}
231+
232+
// use teams events configuration from env if defined
233+
if os.Getenv(BackmanTeamsEvents) != "" {
234+
var events []string
235+
eventsString := os.Getenv(BackmanTeamsEvents)
236+
if eventsString != "" {
237+
events = strings.Split(eventsString, ",")
238+
}
239+
240+
config.Notifications.Teams.Events = events
208241
}
209242
})
210243
return &config

config/const.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package config
2+
3+
const BackmanUsername = "BACKMAN_USERNAME"
4+
const BackmanPassword = "BACKMAN_PASSWORD"
5+
const BackmanEncryptionKey = "BACKMAN_ENCRYPTION_KEY"
6+
const BackmanTeamsWebhook = "BACKMAN_TEAMS_WEBHOOK"
7+
const BackmanTeamsEvents = "BACKMAN_TEAMS_EVENT"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/swisscom/backman
33
go 1.16
44

55
require (
6+
github.com/atc0005/go-teams-notify/v2 v2.6.0
67
github.com/cloudfoundry-community/go-cfenv v1.18.0
78
github.com/dustin/go-humanize v1.0.0
89
github.com/golang/protobuf v1.5.2 // indirect
@@ -19,7 +20,6 @@ require (
1920
github.com/prometheus/common v0.20.0 // indirect
2021
github.com/robfig/cron v1.2.0
2122
github.com/sirupsen/logrus v1.8.1
22-
github.com/stretchr/testify v1.6.1 // indirect
2323
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
2424
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1 // indirect
2525
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 // indirect

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC
1717
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
1818
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
1919
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
20+
github.com/atc0005/go-teams-notify/v2 v2.6.0 h1:YegKDWbjlatR0fP2yHsQYXzTcUGNJXhm1/OiCgbyysc=
21+
github.com/atc0005/go-teams-notify/v2 v2.6.0/go.mod h1:xo6GejLDHn3tWBA181F8LrllIL0xC1uRsRxq7YNXaaY=
2022
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
2123
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
2224
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
@@ -319,8 +321,8 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
319321
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
320322
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
321323
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
322-
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
323-
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
324+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
325+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
324326
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
325327
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
326328
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/swisscom/backman/config"
77
"github.com/swisscom/backman/log"
8+
"github.com/swisscom/backman/notifications"
89
"github.com/swisscom/backman/router"
910
"github.com/swisscom/backman/scheduler"
1011
"github.com/swisscom/backman/service"
@@ -18,6 +19,9 @@ func main() {
1819
// init services
1920
service.Get()
2021

22+
// init notifications manager
23+
notifications.Manager()
24+
2125
// check if an immediate backup/restore should run, in non-background mode. otherwise continue and start scheduler
2226
if runNow() {
2327
return

0 commit comments

Comments
 (0)