Add Makefile, add make scripts

This commit is contained in:
Radosław Szamszur
2021-07-27 12:49:07 +02:00
parent c36ec8e0e0
commit 3e513e565e
4 changed files with 121 additions and 0 deletions

35
Makefile Normal file
View File

@@ -0,0 +1,35 @@
.DEFAULT_GOAL:=help
.EXPORT_ALL_VARIABLES:
ifndef VERBOSE
.SILENT:
endif
# set default shell
SHELL=/usr/bin/env bash -o pipefail -o errexit
# Use the 0.0 tag for testing, it shouldn't clobber any release builds
TAG ?= $(shell cat TAG)
REPO_INFO ?= $(shell git config --get remote.origin.url)
COMMIT_SHA ?= git-$(shell git rev-parse --short HEAD)
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: image
image: ## Build ingestion-server image
@build/image.sh
.PHONY: clean-image
clean-image: ## Clean ingestion-server image
@build/clean-image.sh
.PHONY: venv
venv: ## Install project locally to virtualenv
@build/venv.sh
.PHONY: show-version
show-version:
echo -n $(TAG)

23
build/clean-image.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
if [ -n "$DEBUG" ]; then
set -x
fi
set -o errexit
set -o nounset
set -o pipefail
DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)
if command -v docker &> /dev/null; then
echo "[image] Found docker-engine, begin removing image."
docker rmi -f fastapi-mvc-template:$TAG . || true
elif command -v podman &> /dev/null; then
echo "[image] Found podman container engine, begin removing image."
podman rmi -f fastapi-mvc-template:$TAG . || true
else
echo "[image] Neither docker nor podman container engine found."
exit 1
fi

23
build/image.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
if [ -n "$DEBUG" ]; then
set -x
fi
set -o errexit
set -o nounset
set -o pipefail
DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)
if command -v docker &> /dev/null; then
echo "[image] Found docker-engine, begin building image."
docker build -t fastapi-mvc-template:$TAG .
elif command -v podman &> /dev/null; then
echo "[image] Found podman container engine, begin building image."
podman build -t fastapi-mvc-template:$TAG .
else
echo "[image] Neither docker nor podman container engine found."
exit 1
fi

40
build/venv.sh Executable file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/env bash
if [ -n "$DEBUG" ]; then
set -x
fi
set -o errexit
set -o nounset
set -o pipefail
DIR=$(cd $(dirname "${BASH_SOURCE}") && pwd -P)
if ! command -v python &> /dev/null; then
echo "python is not installed"
exit 1
fi
if ! command -v virtualenv &> /dev/null; then
echo "virtualenv is not installed"
exit 1
fi
PYTHON_VERSION=$(python -V 2>&1 | grep -Eo '([0-9]+\.[0-9]+\.[0-9]+)$')
if [[ ${PYTHON_VERSION} < "3.7.0" ]]; then
echo "Please upgrade python to 3.7.0 or higher"
exit 1
fi
echo "[venv] creating virtualenv"
virtualenv --python=python venv
echo "[venv] installing project"
venv/bin/pip install .
cat <<EOF
Project successfully installed in virtualenv
To activate virtualenv run from project root: $ source venv/bin/activate
Now you should access CLI binary: $ fastapi --help
To deactivate virtualenv simply type: $ deactivate
EOF