chore: add project scaffolding and build tooling
Go module, makefile (build, test, docker, e2e targets), version embedding, initialize script, vars template, ignores and the project plan.
This commit is contained in:
1 parent
1b33d094cd
commit
a02eef13a7
9 files changed
+1081
No files matched your search
@@ -0,0 +1,98 @@
|
||||
#!make
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
# Copyright (C) 2026 Bryan Joshua Pedini
|
||||
|
||||
include .vars
|
||||
|
||||
# Image tag / embedded version (override from the environment: APP_VERSION=1.2.3 make docker)
|
||||
APP_VERSION ?= latest
|
||||
export APP_VERSION
|
||||
# Commit embedded in the binary, computed on the host ("undefined" when there are no commits)
|
||||
COMMIT_ID := $(shell git rev-parse --verify --quiet --short HEAD 2>/dev/null || echo undefined)
|
||||
export COMMIT_ID
|
||||
# Label identifying this project's images, so cleanup never touches unrelated images
|
||||
IMAGE_LABEL = dpsapi.project=$${REPO_ORG}/$${REPO_NAME}
|
||||
# Local build output
|
||||
BINARY = dpsapi
|
||||
|
||||
.PHONY: default clean build docker dockerpush test test-race test-e2e docker-e2e version run dockerrun
|
||||
|
||||
default: version
|
||||
|
||||
clean:
|
||||
rm -f ./$(BINARY) ./coverage.out
|
||||
if [ "$$(docker images "$${CONTAINER_ORG}/$${CONTAINER_IMAGE}" --format "{{.Repository}}:{{.Tag}}")" != "" ]; then \
|
||||
docker image rm $$(docker images "$${CONTAINER_ORG}/$${CONTAINER_IMAGE}" --format "{{.Repository}}:{{.Tag}}"); \
|
||||
fi
|
||||
docker image prune --force --filter "label=$(IMAGE_LABEL)"
|
||||
|
||||
build:
|
||||
CGO_ENABLED=0 go build \
|
||||
-trimpath \
|
||||
-ldflags="-w -s -X 'main.APP_VERSION=$${APP_VERSION}' -X 'main.COMMIT_ID=$${COMMIT_ID}'" \
|
||||
-o ./$(BINARY) .
|
||||
|
||||
docker:
|
||||
docker build \
|
||||
--build-arg GO_BUILDER=$${GO_BUILDER} \
|
||||
--build-arg GO_VERSION=$${GO_VERSION} \
|
||||
--build-arg GO_OS=$${GO_OS} \
|
||||
--build-arg GO_ARCH=$${GO_ARCH} \
|
||||
--build-arg GIT_HOST=$${GIT_HOST} \
|
||||
--build-arg REPO_ORG=$${REPO_ORG} \
|
||||
--build-arg REPO_NAME=$${REPO_NAME} \
|
||||
--build-arg APP_VERSION=$${APP_VERSION} \
|
||||
--build-arg COMMIT_ID=$${COMMIT_ID} \
|
||||
--label "$(IMAGE_LABEL)" \
|
||||
-t $${CONTAINER_ORG}/$${CONTAINER_IMAGE}:$${APP_VERSION} .
|
||||
# Remove only this project's images left dangling by the re-tag (prune without --all only removes dangling images)
|
||||
docker image prune --force --filter "label=$(IMAGE_LABEL)"
|
||||
|
||||
dockerpush:
|
||||
docker push \
|
||||
$${CONTAINER_ORG}/$${CONTAINER_IMAGE}:$${APP_VERSION}
|
||||
|
||||
test:
|
||||
go test ./...
|
||||
|
||||
test-race:
|
||||
CGO_ENABLED=1 go test -race ./...
|
||||
|
||||
# The binary is built by the build prerequisite, so the suite's own build step is skipped
|
||||
test-e2e: build
|
||||
cd e2e && npm ci && DPSAPI_E2E_SKIP_BUILD=1 npx playwright test --project=host
|
||||
|
||||
docker-e2e: docker
|
||||
cd e2e && npm ci && \
|
||||
DPSAPI_IMAGE=$${CONTAINER_ORG}/$${CONTAINER_IMAGE}:$${APP_VERSION} npx playwright test --project=image
|
||||
|
||||
version:
|
||||
bash -c "./version.sh"
|
||||
|
||||
run:
|
||||
mkdir -p ./data
|
||||
docker run \
|
||||
--rm \
|
||||
--tty \
|
||||
--interactive \
|
||||
--publish $${CONTAINER_IP}:$${CONTAINER_PORT}:80 \
|
||||
--workdir /go/src/$${GIT_HOST}/$${REPO_ORG}/$${REPO_NAME} \
|
||||
--volume $(shell pwd):/go/src/$${GIT_HOST}/$${REPO_ORG}/$${REPO_NAME} \
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock \
|
||||
--env DB_PATH=/go/src/$${GIT_HOST}/$${REPO_ORG}/$${REPO_NAME}/data/dpsapi.db \
|
||||
--env LOG_LEVEL=$${LOG_LEVEL:-INFO} \
|
||||
$${GO_BUILDER}:$${GO_VERSION} \
|
||||
go run .
|
||||
|
||||
dockerrun:
|
||||
mkdir -p ./data
|
||||
docker run \
|
||||
--rm \
|
||||
--tty \
|
||||
--interactive \
|
||||
--publish $${CONTAINER_IP}:$${CONTAINER_PORT}:80 \
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock \
|
||||
--volume $(shell pwd)/data:/data \
|
||||
--env DB_PATH=/data/dpsapi.db \
|
||||
--env LOG_LEVEL=$${LOG_LEVEL:-INFO} \
|
||||
$${CONTAINER_ORG}/$${CONTAINER_IMAGE}:$${APP_VERSION}
|
||||
Reference in new issue
Block a user