-
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
Showing
7 changed files
with
166 additions
and
122 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
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 @@ | ||
# Copyright (c) 2023-2024 AlertAvert.com | ||
# All rights reserved. | ||
# Created by Marco Massenzio, 2023-07-13 | ||
|
||
# This will be the name of the binary | ||
name: application-name | ||
|
||
# Manually update this value to change the semantic version | ||
# of your binary/container image. | ||
version: 0.10.0 | ||
description: "Common utilities for Shell Scripts" | ||
author: Marco Massenzio (marco@alertavert.com) | ||
license: Apache-2.0 | ||
url: https://github.com/massenz/common-utils |
This file was deleted.
Oops, something went wrong.
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,65 @@ | ||
# Copyright (c) 2024 AlertAvert.com. All rights reserved. | ||
# Created by M. Massenzio, 2022-03 | ||
# | ||
# Makefile template for Go Applications | ||
|
||
# Adjust location accordingly | ||
include $(COMMON_UTILS)/common.mk | ||
|
||
# Source files & Test files definitions | ||
# Place all packages in a ./pkg subdir of the main project; the main binary | ||
# should be placed in ./cmd/main.go (change the `build` target accordingly if you | ||
# use something different). | ||
pkgs := $(shell find pkg -mindepth 1 -type d) | ||
all_go := $(shell for d in $(pkgs); do find $$d -name "*.go"; done) | ||
test_srcs := $(shell for d in $(pkgs); do find $$d -name "*_test.go"; done) | ||
srcs := $(filter-out $(test_srcs),$(all_go)) | ||
bin := $(prog)-$(RELEASE)_$(GOOS)-$(GOARCH) | ||
|
||
##@ General | ||
.PHONY: clean | ||
clean: ## Cleans up the binary, container image and other data | ||
@rm -rf build | ||
@docker-compose -f $(compose) down | ||
@docker rmi $(shell docker images -q --filter=reference=$(image)) | ||
|
||
.PHONY: version | ||
version: ## Displays the current version tag (release) | ||
@echo $(release) | ||
|
||
.PHONY: fmt | ||
fmt: ## Formats the Go source code using 'go fmt' | ||
@go fmt $(pkgs) ./cmd | ||
|
||
##@ Development | ||
$(out): cmd/main.go $(srcs) | ||
go build -ldflags "-X $(module)/Release=$(release)" -o $(out) cmd/main.go | ||
@chmod +x $(out) | ||
|
||
build: $(out) ## Builds the server | ||
|
||
test: $(srcs) $(test_srcs) ## Runs all tests in parallel | ||
ginkgo -p $(pkgs) | ||
|
||
run: $(out) ## Runs the most recent build of the application | ||
@echo $(GREEN) Running $(out)... | ||
$(out) | ||
|
||
$(cov)/cov.out: $(srcs) $(test_srcs) | ||
@go test -coverprofile=$(cov)/cov.out $(pkgs) | ||
@go tool cover -html=$(cov)/cov.out | ||
|
||
.PHONY: coverage | ||
coverage: $(cov)/cov.out ## Runs the Test Coverage target and opens a browser window with the coverage report | ||
|
||
##@ Container Management | ||
# Convenience targets to run locally containers and | ||
# setup the test environments. | ||
# | ||
.PHONY: container | ||
container: $(out) ## Builds the container image | ||
docker build -f $(dockerfile) -t $(image):$(release) . | ||
|
||
.PHONY: start | ||
start: ## Starts all the containers | ||
@RELEASE=$(release) docker-compose -f $(compose) up -d |
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 @@ | ||
# Copyright (c) 2024 AlertAvert.com. All rights reserved. | ||
# Created by M. Massenzio, 2022-03-14 | ||
|
||
# ANSI color codes | ||
GREEN=$(shell tput -Txterm setaf 2) | ||
YELLOW=$(shell tput -Txterm setaf 3) | ||
RED=$(shell tput -Txterm setaf 1) | ||
BLUE=$(shell tput -Txterm setaf 6) | ||
RESET=$(shell tput -Txterm sgr0) | ||
|
||
# Go platform management | ||
GOOS ?= $(shell uname -s | tr "[:upper:]" "[:lower:]") | ||
GOMOD := $(shell go list -m) | ||
|
||
UNAME_M := $(shell uname -m) | ||
ifeq ($(UNAME_M),x86_64) | ||
GOARCH = amd64 | ||
else ifeq ($(UNAME_M),aarch64) | ||
GOARCH = arm64 | ||
else ifeq ($(UNAME_M),armv6l) | ||
GOARCH = arm | ||
else ifeq ($(UNAME_M),armv7l) | ||
GOARCH = arm | ||
else ifeq ($(UNAME_M),armv8l) | ||
GOARCH = arm64 | ||
else | ||
$(error Unsupported architecture $(UNAME_M)) | ||
endif | ||
|
||
|
||
# Versioning | ||
# The `version` is a static value, set in settings.yaml, and ONLY used to tag the release. | ||
VERSION ?= $(shell cat settings.yaml | yq -r .version) | ||
GIT_COMMIT := $(shell git rev-parse --short HEAD) | ||
RELEASE := v$(VERSION)-g$(GIT_COMMIT) | ||
|
||
prog := $(shell cat settings.yaml | yq -r .name) | ||
|
||
# Certificates | ||
certs_dir := ssl-config | ||
ca-csr := $(certs_dir)/ca-csr.json | ||
ca-config := $(certs_dir)/ca-config.json | ||
server-csr := $(certs_dir)/localhost-csr.json | ||
|
||
# Dockerfile | ||
compose := docker/docker-compose.yaml | ||
dockerfile := docker/Dockerfile | ||
|
||
##@ Help | ||
# The help target prints out all targets with their descriptions organized | ||
# beneath their categories. The categories are represented by '##@' and the | ||
# target descriptions by '##'. The awk commands is responsible for reading the | ||
# entire set of makefiles included in this invocation, looking for lines of the | ||
# file as xyz: ## something, and then pretty-format the target and help. Then, | ||
# if there's a line with ##@ something, that gets pretty-printed as a category. | ||
# More info on the usage of ANSI control characters for terminal formatting: | ||
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters | ||
# More info on the awk command: | ||
# http://linuxcommand.org/lc3_adv_awk.php | ||
|
||
.PHONY: help | ||
help: ## Display this help. | ||
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | ||
|
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 @@ | ||
# Copyright (c) 2023-2024 AlertAvert.com | ||
# All rights reserved. | ||
# Created by Marco Massenzio, 2023-07-13 | ||
|
||
# This will be the name of the binary | ||
name: application-name | ||
|
||
# Manually update this value to change the semantic version | ||
# of your binary/container image. | ||
version: 0.10.0 | ||
description: Short description of your project here | ||
author: Marco Massenzio (marco@alertavert.com) | ||
license: Apache-2.0 | ||
url: https://github.com/massenz/common-utils |