Add MCU report endpoint and deployment tooling
This commit is contained in:
78
Makefile
Normal file
78
Makefile
Normal file
@@ -0,0 +1,78 @@
|
||||
SHELL := /usr/bin/env bash
|
||||
|
||||
APP_NAME ?= cpone-middleware
|
||||
GOOS ?= linux
|
||||
GOARCH ?= amd64
|
||||
CGO_ENABLED ?= 0
|
||||
BUILD_BINARY ?= dist/$(APP_NAME)-$(GOOS)-$(GOARCH)
|
||||
|
||||
REMOTE_DIR ?= auto
|
||||
REMOTE_BINARY ?=
|
||||
SERVICE ?= $(APP_NAME).service
|
||||
SERVICE_SCOPE ?= auto
|
||||
RESTART_MODE ?= systemd-kill
|
||||
SSH_OPTIONS ?= -o ConnectTimeout=10 -o ServerAliveInterval=5 -o ServerAliveCountMax=2
|
||||
SSH_TIMEOUT ?= 45s
|
||||
TRANSFER_TIMEOUT ?= 120s
|
||||
|
||||
# Supports both `make deploy one@host` and the explicit form
|
||||
# `make deploy DEPLOY_TARGET=one@host`.
|
||||
KNOWN_GOALS := help test vet build check-deploy-target deploy
|
||||
POSITIONAL_TARGET := $(firstword $(filter-out $(KNOWN_GOALS),$(MAKECMDGOALS)))
|
||||
DEPLOY_TARGET ?= $(POSITIONAL_TARGET)
|
||||
|
||||
.DEFAULT_GOAL := help
|
||||
.PHONY: help test vet build check-deploy-target deploy
|
||||
|
||||
help:
|
||||
@printf '%s\n' \
|
||||
'Usage:' \
|
||||
' make deploy one@devcpone.aplikasi.web.id' \
|
||||
' make deploy DEPLOY_TARGET=one@devcpone.aplikasi.web.id' \
|
||||
'' \
|
||||
'Optional overrides:' \
|
||||
' REMOTE_DIR=auto (default: $${HOME}/apps di server)' \
|
||||
' SERVICE=cpone-middleware.service' \
|
||||
' SERVICE_SCOPE=auto|user|system' \
|
||||
' RESTART_MODE=systemd-kill|systemctl' \
|
||||
' SSH_OPTIONS="-p 22 -o ConnectTimeout=10"' \
|
||||
' SSH_TIMEOUT=45s TRANSFER_TIMEOUT=120s'
|
||||
|
||||
test:
|
||||
go test ./...
|
||||
|
||||
vet:
|
||||
go vet ./...
|
||||
|
||||
build: test vet
|
||||
@mkdir -p "$$(dirname "$(BUILD_BINARY)")"
|
||||
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) \
|
||||
go build -trimpath -ldflags='-s -w' -o "$(BUILD_BINARY)" ./cmd/server
|
||||
@printf 'Built %s\n' "$(BUILD_BINARY)"
|
||||
|
||||
check-deploy-target:
|
||||
@if [[ -z "$(DEPLOY_TARGET)" ]]; then \
|
||||
echo 'Error: target server belum diisi.' >&2; \
|
||||
echo 'Contoh: make deploy one@devcpone.aplikasi.web.id' >&2; \
|
||||
exit 2; \
|
||||
fi
|
||||
|
||||
deploy: check-deploy-target build
|
||||
@APP_NAME="$(APP_NAME)" \
|
||||
BUILD_BINARY="$(BUILD_BINARY)" \
|
||||
REMOTE_DIR="$(REMOTE_DIR)" \
|
||||
REMOTE_BINARY="$(REMOTE_BINARY)" \
|
||||
SERVICE="$(SERVICE)" \
|
||||
SERVICE_SCOPE="$(SERVICE_SCOPE)" \
|
||||
RESTART_MODE="$(RESTART_MODE)" \
|
||||
SSH_OPTIONS="$(SSH_OPTIONS)" \
|
||||
SSH_TIMEOUT="$(SSH_TIMEOUT)" \
|
||||
TRANSFER_TIMEOUT="$(TRANSFER_TIMEOUT)" \
|
||||
./scripts/deploy.sh "$(DEPLOY_TARGET)"
|
||||
|
||||
# Extra command-line words are treated as the positional deploy target.
|
||||
ifneq ($(strip $(POSITIONAL_TARGET)),)
|
||||
.PHONY: $(POSITIONAL_TARGET)
|
||||
$(POSITIONAL_TARGET):
|
||||
@:
|
||||
endif
|
||||
Reference in New Issue
Block a user