From 8dc785d8435eb5693ec39a88555b22a067249740 Mon Sep 17 00:00:00 2001 From: Steve Howes Date: Wed, 18 Oct 2023 15:14:54 +0100 Subject: [PATCH] Conversion to Makefile and systemd unit --- .dockerignore | 1 - .gitignore | 2 -- Dockerfile | 14 -------------- Makefile | 31 +++++++++++++++++++++++++++++++ README.md | 15 ++++++++++++--- osgrid-server.service | 17 +++++++++++++++++ 6 files changed, 60 insertions(+), 20 deletions(-) delete mode 100644 .dockerignore delete mode 100644 .gitignore delete mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 osgrid-server.service diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 3c3629e..0000000 --- a/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 944c283..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -.idea/ diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 40976cd..0000000 --- a/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM paulcager/go-base:latest as build - -COPY * ./ -RUN CGO_ENABLED=0 go install -v ./... && \ - sha256sum /go/bin/osgrid-server - -FROM scratch -WORKDIR /app -COPY --from=build /go/bin/osgrid-server . -EXPOSE 9090 - -CMD [ "/app/osgrid-server" ] - - diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c523f34 --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +.DEFAULT_GOAL := build + +clean: + rm -f osgrid-server + +fmt: + go fmt ./... +.PHONY:fmt + +lint: fmt + golint ./... +.PHONY:lint + +vet: fmt + go vet ./... +.PHONY:vet + +build: vet + go build +.PHONY:build + +run: build + ./osgrid-server +.PHONY:run + +install: build + mkdir -p /opt/sartools/ + useradd sartools || true + chown sartools:sartools /opt/sartools/ + cp osgrid-server /opt/sartools/ + cp osgrid-server.service /etc/systemd/system/ diff --git a/README.md b/README.md index c5de33f..fc07585 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,22 @@ # osgrid-server - _Ordnance Survey Grid Ref Converter_ This project implements a simple REST server to allow conversion between Ordnance Survey -grid references and latitude / longitude. +grid references and latitude / longitude. This fork runs without docker and includes +a makefile implementing install, run, build, vet, lint, fmt and clean. As this is part +of an intended set of SAR tools, installation is to /opt/sartools/ and will create the +user 'sartools' if it does not exist. + +## Pre-requisites +- go +- make +- golint (optional) ## Usage -The easiest way is to start the server using Docker: +To use this stand-alone (non Docker variant) on http://localhost:9090 just run: - docker run -d --rm --name osgrid-server -p 9090:9090 paulcager/osgrid-server + make install + service osgrid-server A grid reference may then be converted to a lat / lon: diff --git a/osgrid-server.service b/osgrid-server.service new file mode 100644 index 0000000..c574e46 --- /dev/null +++ b/osgrid-server.service @@ -0,0 +1,17 @@ +[Unit] +Description=OS Grid Server +ConditionPathExists=/opt/sartools/osgrid-server +After=network.target +[Service] +Type=simple +User=sartools +Group=sartools +WorkingDirectory=/opt/sartools/ +ExecStart=/opt/sartools/osgrid-server --port localhost:9090 +Restart=on-failure +RestartSec=10 +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=osgrid-server +[Install] +WantedBy=multi-user.target