Skip to content

Commit

Permalink
Merge 1fc46ac into 106b4db
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Zimmermann committed Apr 4, 2021
2 parents 106b4db + 1fc46ac commit 2ed0765
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 12 deletions.
27 changes: 17 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.13 as builder
FROM golang:1.16 as builder

ARG CC=""
ARG CC_PKG=""
Expand All @@ -13,15 +13,22 @@ RUN if [ -n "$CC_PKG" ]; then \
&& export GOOS=linux \
&& export GOARCH=$CC_GOARCH \
&& export CGO_ENABLED=1 \
&& go build -o /var/tmp/app -v github.com/rycus86/release-watcher

FROM <target>

LABEL maintainer "Viktor Adam <rycus86@gmail.com>"

RUN apt-get update \
&& apt-get install -y ca-certificates \
&& rm -rf /var/lib/apt/lists/*
&& cd /go/src/github.com/rycus86/release-watcher \
&& go mod vendor \
&& go build -mod vendor -o /var/tmp/app .

FROM builder

LABEL application="Release Watcher" \
description="Release Watcher - Backend service to send slack notifactions after a new release of a lib" \
version="0.0.2" \
maintainer="Viktor Adam <rycus86@gmail.com>" \
lastUpdatedBy="Pascal Zimmermann" \
lastUpdatedOn="2021-03-21"

RUN apt-get update && \
apt-get install -y ca-certificates && \
rm -rf /var/lib/apt/lists/*

COPY --from=builder /var/tmp/app /release-watcher

Expand Down
94 changes: 94 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
GOCMD=go
GOTEST=$(GOCMD) test
BINARY_NAME=release-watcher
VERSION=0.0.2
SERVICE_PORT=3000
DOCKER_REGISTRY= #if set it should finished by /
EXPORT_RESULT=false # for CI please set EXPORT_RESULT to true

GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)

.PHONY: all test build vendor

all: help

run: ## Run the go code
ifeq (,$(wildcard ./release-watcher.yml))
cp testdata/sample_config.yml ./release-watcher.yml
endif
$(GOCMD) run -mod vendor ./main.go

build: ## Build your project and put the output binary in out/bin/
mkdir -p out/bin
$(GOCMD) build -mod vendor -o out/bin/$(BINARY_NAME) .

clean: ## Remove build related file
rm -fr ./bin
rm -fr ./out
rm -f ./junit-report.xml checkstyle-report.xml ./coverage.xml ./profile.cov yamllint-checkstyle.xml
rm ./release-watcher.yml

coverage: ## Run the tests of the project and export the coverage
$(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./...
$(GOCMD) tool cover -func profile.cov
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/AlekSi/gocov-xml
GO111MODULE=off go get -u github.com/axw/gocov/gocov
gocov convert profile.cov | gocov-xml > coverage.xml
endif

docker-build: ## Use the dockerfile to build the container
docker build --rm --tag $(BINARY_NAME) .

docker-release: ## Release the container with tag latest and version
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)$(BINARY_NAME):latest
docker tag $(BINARY_NAME) $(DOCKER_REGISTRY)$(BINARY_NAME):$(VERSION)
# Push the docker images
docker push $(DOCKER_REGISTRY)$(BINARY_NAME):latest
docker push $(DOCKER_REGISTRY)$(BINARY_NAME):$(VERSION)

help: ## Show this help.
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " ${YELLOW}%-16s${GREEN}%s${RESET}\n", $$1, $$2}' $(MAKEFILE_LIST)

lint: lint-go lint-dockerfile lint-yaml ## Run all available linters

lint-dockerfile: ## Lint your Dockerfile
# If dockerfile is present we lint it.
ifeq ($(shell test -e ./Dockerfile && echo -n yes),yes)
$(eval CONFIG_OPTION = $(shell [ -e $(shell pwd)/.hadolint.yaml ] && echo "-v $(shell pwd)/.hadolint.yaml:/root/.config/hadolint.yaml" || echo "" ))
$(eval OUTPUT_OPTIONS = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "--format checkstyle" || echo "" ))
$(eval OUTPUT_FILE = $(shell [ "${EXPORT_RESULT}" == "true" ] && echo "| tee /dev/tty > checkstyle-report.xml" || echo "" ))
docker run --rm -i $(CONFIG_OPTION) hadolint/hadolint hadolint $(OUTPUT_OPTIONS) - < ./Dockerfile $(OUTPUT_FILE)
endif

lint-go:
$(GOCMD) fmt ./...

lint-yaml: ## Use yamllint on the yaml file of your projects
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/thomaspoignant/yamllint-checkstyle
$(eval OUTPUT_OPTIONS = | tee /dev/tty | yamllint-checkstyle > yamllint-checkstyle.xml)
endif
docker run --rm -it -v $(shell pwd):/data cytopia/yamllint -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)

test: ## Run the tests of the project
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/jstemmer/go-junit-report
$(eval OUTPUT_OPTIONS = | tee /dev/tty | go-junit-report -set-exit-code > junit-report.xml)
endif
$(GOTEST) -v -race ./... $(OUTPUT_OPTIONS)

vendor: ## Copy of all packages needed to support builds and tests in the vendor directory
$(GOCMD) mod vendor

watch: ## Run the code with cosmtrek/air to have automatic reload on changes
$(eval PACKAGE_NAME=$(shell head -n 1 go.mod | cut -d ' ' -f2))
docker run -it --rm -w /go/src/$(PACKAGE_NAME) -v $(shell pwd):/go/src/$(PACKAGE_NAME) -p $(SERVICE_PORT):$(SERVICE_PORT) cosmtrek/air
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $ docker run -d --name release-watcher \
rycus86/release-watcher
```

Alternatively, build with Go (tested on version 1.10, 1.14), then execute:
Alternatively, build with Go (tested on version 1.10, 1.14, 1.16), then execute:

```shell
$ export DATABASE_PATH=$PWD/releases.db
Expand Down
5 changes: 5 additions & 0 deletions deployment/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart to deploy the Release Watcher application inside a K8s cluster
name: release-watcher
version: 0.0.2
15 changes: 15 additions & 0 deletions deployment/helm/templates/01-pv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: "gluster-{{ .Values.basic.name }}-pv"
namespace: "{{ .Values.basic.namespace }}"
spec:
capacity:
storage: "{{ .Values.basic.storage_size }}Gi"
accessModes:
- ReadWriteMany
glusterfs:
endpoints: gluster-cluster-sv
path: "/{{ .Values.basic.name }}"
readOnly: false
persistentVolumeReclaimPolicy: Retain
11 changes: 11 additions & 0 deletions deployment/helm/templates/02-pvc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: "gluster-{{ .Values.basic.name }}-claim"
namespace: "{{ .Values.basic.namespace }}"
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: "{{ .Values.basic.storage_size }}Gi"
8 changes: 8 additions & 0 deletions deployment/helm/templates/03-sc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: "{{ .Values.basic.name }}-sc"
namespace: "{{ .Values.basic.namespace }}"
stringData:
SLACK_WEBHOOK_URL: "{{ .Values.secret.SLACK_WEBHOOK_URL }}"
41 changes: 41 additions & 0 deletions deployment/helm/templates/04-de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: "{{ .Values.basic.name }}-de"
labels:
app.kubernetes.io/name: "{{ .Values.basic.name }}"
namespace: "{{ .Values.basic.namespace }}"
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: "{{ .Values.basic.name }}"
template:
metadata:
labels:
app.kubernetes.io/name: "{{ .Values.basic.name }}"
spec:
containers:
- name: "{{ .Values.basic.name }}"
image: "{{ .Values.docker.image }}:{{ .Values.docker.tag }}"
env:
- name: SLACK_WEBHOOK_URL
valueFrom:
secretKeyRef:
name: "{{ .Values.basic.name }}-sc"
key: SLACK_WEBHOOK_URL
- name: CONFIGURATION_FILE
value: "{{ .Values.config.CONFIGURATION_FILE }}"
- name: DATABASE_PATH
value: "{{ .Values.config.DATABASE_PATH }}"
volumeMounts:
- mountPath: /data
name: storage
readOnly: false
imagePullPolicy: Always
volumes:
- name: data
persistentVolumeClaim:
claimName: "gluster-{{ .Values.basic.name }}-claim"
securityContext:
fsGroup: 500
15 changes: 15 additions & 0 deletions deployment/helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
basic:
name: release-watcher
namespace:
storage_size: 5

docker:
image: release-watcher
tag: 0.0.2

secret:
SLACK_WEBHOOK_URL:

config:
CONFIGURATION_FILE: /data/releases.yml
DATABASE_PATH: /data/releases.db
14 changes: 14 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3'
services:
release-watcher:
build:
context: ../
dockerfile: Dockerfile
environment:
- CONFIGURATION_FILE=/data/releases.yml
- DATABASE_PATH=/data/releases.db
- SLACK_WEBHOOK_URL=https://some.slack.webhook.url
restart: always
volumes:
- /data:/data
- $PWD/release-watcher.yml:/data/releases.yml
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/rycus86/release-watcher

go 1.13
go 1.16

require (
github.com/google/go-github v17.0.0+incompatible
Expand Down

0 comments on commit 2ed0765

Please sign in to comment.