Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
massenz committed May 5, 2024
2 parents 6c6deb7 + 380d162 commit e3b4e9a
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 64 deletions.
36 changes: 36 additions & 0 deletions ifind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env zsh
#
# Extends `find` to use .gitignore to exclude
# paths from results.
#
# Created M. Massenzio, 2024-05-04
declare -r search_dir=${1:-.}

# Start constructing the find command
cmd="find ${search_dir} -type f"

# Exclude common "noisy" directories
patterns=('.git' '.run' '.idea' '.cache')
for p in "${patterns[@]}"; do
cmd+=" -not -path ${search_dir}/$p/'*'"
done

# If it exists in the current directory,
# or in the $search_dir path,
# read each line from .gitignore
gitignore=$(test -f ./.gitignore && echo './.gitignore' || \
echo "${search_dir}/.gitignore")
if [[ -n ${gitignore} ]]; then
while read -r pattern; do
# Ignore empty lines and comments
# Append the exclusion pattern to the find command
# only if it is a directory exclusion pattern.
if [[ -n "$pattern" && ! ( "$pattern" =~ '^#' || "$pattern" =~ '^!' ) \
&& "$pattern" =~ '/$' ]]; then
cmd+=" -not -path '$search_dir/$pattern*'"
fi
done < ${gitignore}
fi

# Execute the find command
eval "$cmd"
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version" : "0.9.0",
"version" : "0.10.0",
"metadata": {
"author": "marco@alertavert.com",
"comment": "Common utilities for Shell Scripts"
Expand Down
11 changes: 0 additions & 11 deletions parse-args/parse_args.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@

# Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Author: Marco Massenzio (marco@alertavert.com)
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Author: Marco Massenzio (marco@alertavert.com)
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Author: Marco Massenzio (marco@alertavert.com)

import argparse
import re
Expand Down
108 changes: 56 additions & 52 deletions templates/Makefile-template
Original file line number Diff line number Diff line change
@@ -1,30 +1,58 @@
# Copyright (c) 2022 AlertAvert.com. All rights reserved.
# Copyright (c) 2022-2024 AlertAvert.com. All rights reserved.
# Created by M. Massenzio, 2022-03-14

bin := build/bin
cov := build/coverage
# TODO: replace with name of binary, if appropriate
out := $(bin)/server
# TODO: install the https://github.com/massenz/common-utils library
# or implement your own script to generate the version tag.
tag := $(shell go-make-version-tag)
# 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


# TODO: Update as required
prog := my-go-app
version := v0.1.0

release := $(version)-g$(shell git rev-parse --short HEAD)
bin := out/bin/$(prog)-$(version)_$(GOOS)-$(GOARCH)

# TODO: replace with name of image as appropriate
image := <<IMAGE NAME GOES HERE>>
image := $(prog)
module := $(shell go list -m)

compose := docker/docker-compose.yaml
dockerfile := docker/Dockerfile

# Source files & Test files definitions
#
# Edit only the packages list, when adding new functionality,
# the rest is deduced automatically.
#
pkgs := <<LIST OF PACKAGES GOES HERE AS ./api ./grpc ./http ETC. >>
# Assumes all code packages reside as directories inside pkg/
SUBDIRS := $(wildcard pkg/*)
PACKAGEDIRS := $(filter %/, $(SUBDIRS))
packages := $(patsubst pkg/%, ./%, $(PACKAGEDIRS))

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))
srcs := $(filter-out $(test_srcs), $(all_go))

##@ General

Expand All @@ -48,24 +76,28 @@ 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))
@rm -rf certs

.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 ./clients
@go fmt $(pkgs) ./cmd

##@ Development
$(out): cmd/main.go $(srcs)
# TODO: replace package name as appropriate; if Release is in main, leave only Release.
go build -ldflags "-X $(module)/<<PACKAGE>>.Release=$(tag)" -o $(out) cmd/main.go
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, starting services first, if required
ginkgo $(pkgs)
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)
Expand All @@ -80,36 +112,8 @@ coverage: $(cov)/cov.out ## Runs the Test Coverage target and opens a browser wi
#
.PHONY: container
container: $(out) ## Builds the container image
docker build -f $(dockerfile) -t $(image):$(tag) .

# TODO: will be replaced once we adopt TestContainers (#26)
.PHONY: services
services: ## Starts the Redis and LocalStack containers
@docker-compose -f $(compose) up -d
docker build -f $(dockerfile) -t $(image):$(release) .

##@ TLS Support
#
# NOTE: This section is WIP and subject to change.
#
# Install CFSSL following the instructions here:
# https://github.com/cloudflare/cfssl#installation

config_dir := ssl-config
ca-csr := $(config_dir)/ca-csr.json
ca-config := $(config_dir)/ca-config.json
server-csr := $(config_dir)/localhost-csr.json

.PHONY: gencert
gencert: $(ca-csr) $(config) $(server-csr) ## Generates all certificates in the certs directory (requires cfssl and cfssl, see https://github.com/cloudflare/cfssl#installation)
cfssl gencert \
-initca $(ca-csr) | cfssljson -bare ca

cfssl gencert \
-ca=ca.pem \
-ca-key=ca-key.pem \
-config=$(ca-config) \
-profile=server \
$(server-csr) | cfssljson -bare server
@mkdir -p certs
@mv *.pem *.csr certs/
@echo "Certificates generated in $(shell pwd)/certs"
.PHONY: start
start: ## Starts all the containers
@RELEASE=$(release) docker-compose -f $(compose) up -d

0 comments on commit e3b4e9a

Please sign in to comment.