Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
mmassenzio committed Jul 21, 2024
2 parents ece554a + 1ea00c8 commit f0c8bb5
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 122 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
#
# Author: Marco Massenzio (marco@alertavert.com)

include templates/common.mk

TESTDIR := parse-args
VERSION = $(shell ./scripts/get-version.sh manifest.json)
TARBALL := common-utils-$(VERSION).tar.gz
python := $(shell which python3)

package:
@mkdir -p dist
./package.sh dist/$(TARBALL)

test:
ifeq ($(strip $(python)),)
@echo "$(RED)ERROR:$(RESET) Missing python3 binary"
@exit 1
endif
@echo "--- Running tests in the ${TESTDIR} directory"
python -m unittest discover -s ${TESTDIR}
$(python) -m unittest discover -s ${TESTDIR}

version:
@echo $(VERSION)
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ then
fi
curl -s -L ${TARBALL} | tar x -C ${COMMON_UTILS}

source ${COMMON_UTILS}/utils
source ${COMMON_UTILS}/utils.sh
success "Utilities installed to ${COMMON_UTILS}"

cat <<EOF >${HOME}/.commonrc
Expand Down
14 changes: 14 additions & 0 deletions settings.yaml
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
119 changes: 0 additions & 119 deletions templates/Makefile-template

This file was deleted.

65 changes: 65 additions & 0 deletions templates/Makefile.go.mk
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
64 changes: 64 additions & 0 deletions templates/common.mk
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)

14 changes: 14 additions & 0 deletions templates/settings.yaml.template
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

0 comments on commit f0c8bb5

Please sign in to comment.