-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
11 changed files
with
222 additions
and
12 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
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,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 |
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
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 @@ | ||
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 |
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,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 |
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,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" |
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,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 }}" |
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,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 |
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,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 |
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,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 |
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