include rpm package building

This commit is contained in:
samuel 2023-01-24 18:40:54 +01:00
parent d65a67fb7f
commit 058f093bd4
12 changed files with 108 additions and 20 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
.gitignore export-ignore
*.spec export-ignore

2
.gitignore vendored
View File

@ -24,3 +24,5 @@ _testmain.go
*.test
*.prof
# Binaries
/bin

View File

@ -1,4 +1,36 @@
bin/server: cmd/server/main.go pkg/*/*.go go.mod go.sum
go build -o bin/server cmd/server/main.go
NAME = netoik-api
VERSION = $(shell [ -d ".git" ] && git describe | sed "s/-/./g")
BRANCH = $(shell [ -d ".git" ] && git branch --show-current)
SYSCONFDIR = $(shell rpm --eval "%{_sysconfdir}")
UNITDIR = $(shell rpm --eval "%{_unitdir}")
BINDIR = $(shell rpm --eval "%{_bindir}")
VARDIR = $(shell rpm --eval "%{_var}")
.PHONY: build
build: bin/server
bin/server: cmd/server/main.go pkg/*/*.go go.mod go.sum
mkdir --parents bin
CGO_ENABLED=0 go build -o "$@" ./cmd/server/main.go
.PHONY: version
version:
@echo $(VERSION)
.PHONY: tarball
tarball: $(HOME)/rpmbuild/SOURCES/$(NAME)-$(VERSION).tar.gz
$(HOME)/rpmbuild/SOURCES/$(NAME)-%.tar.gz: .
git archive --format=tar.gz --output=$@ --prefix=$(NAME)-$(VERSION)/ --worktree-attributes --verbose $(BRANCH)
.PHONY: install
install:
mkdir --parents $(DESTDIR)$(VARDIR)/$(NAME)/captcha
mkdir --parents $(DESTDIR)$(SYSCONFDIR)/$(NAME)
install server.conf.sample $(DESTDIR)$(SYSCONFDIR)/$(NAME)/server.conf.sample
install server.conf.sample $(DESTDIR)$(SYSCONFDIR)/$(NAME)/server.conf
mkdir --parents $(DESTDIR)$(UNITDIR)
install systemd/netoik-api-server.service $(DESTDIR)$(UNITDIR)/netoik-api-server.service
mkdir --parents $(DESTDIR)$(BINDIR)
install bin/server $(DESTDIR)$(BINDIR)/$(NAME)-server

Binary file not shown.

View File

@ -4,9 +4,9 @@ import (
"flag"
"fmt"
"net/http"
"netoik.io/netoik-website/pkg/captcha"
"netoik.io/netoik-website/pkg/conf"
"netoik.io/netoik-website/pkg/contact"
"netoik.io/netoik-api/pkg/captcha"
"netoik.io/netoik-api/pkg/conf"
"netoik.io/netoik-api/pkg/contact"
"os"
)

13
go.mod
View File

@ -1,10 +1,11 @@
module netoik.io/netoik-website
module netoik.io/netoik-api
go 1.18
go 1.19
require (
github.com/dchest/captcha v0.0.0-20200903113550-03f5f0333e1f // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
github.com/dchest/captcha v1.0.0
github.com/pelletier/go-toml v1.9.5
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
)
require gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect

4
go.sum
View File

@ -1,5 +1,5 @@
github.com/dchest/captcha v0.0.0-20200903113550-03f5f0333e1f h1:q/DpyjJjZs94bziQ7YkBmIlpqbVP7yw179rnzoNVX1M=
github.com/dchest/captcha v0.0.0-20200903113550-03f5f0333e1f/go.mod h1:QGrK8vMWWHQYQ3QU9bw9Y9OPNfxccGzfb41qjvVeXtY=
github.com/dchest/captcha v1.0.0 h1:vw+bm/qMFvTgcjQlYVTuQBJkarm5R0YSsDKhm1HZI2o=
github.com/dchest/captcha v1.0.0/go.mod h1:7zoElIawLp7GUMLcj54K9kbw+jEyvz2K0FDdRRYhvWo=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=

50
netoik-api.spec Normal file
View File

@ -0,0 +1,50 @@
%undefine _missing_build_ids_terminate_build
%define debug_package %{nil}
Name: netoik-api
Version: %(make version)
Release: 1%{?dist}
Summary: Netoik rest API server
License: GPLv3
URL: https://www.netoik.io/api
Source0: %{name}-%{version}.tar.gz
Buildarch: x86_64
BuildRequires: make
%description
Netoik rest API server
%prep
%autosetup -v
%build
%make_build
%install
%make_install
%pre
useradd --no-create-home --system --user-group %{name}
%post
systemctl stop %{name}-server.service
systemctl daemon-reload
systemctl start %{name}-server.service
%preun
systemctl stop %{name}-server.service
%postun
systemctl daemon-reload
userdel %{name}
%files
%attr(755, root, root) %dir %{_var}/%{name}
%attr(755, %{name}, %{name}) %dir %{_var}/%{name}/captcha
%attr(755, root, root) %dir %{_sysconfdir}/%{name}
%attr(644, root, root) %{_sysconfdir}/%{name}/server.conf.sample
%attr(644, root, root) %config(noreplace) %{_sysconfdir}/%{name}/server.conf
%attr(644, root, root) %{_unitdir}/%{name}-server.service
%attr(755, root, root) %{_bindir}/%{name}-server

View File

@ -5,8 +5,8 @@ import (
"fmt"
"github.com/dchest/captcha"
"net/http"
"netoik.io/netoik-website/pkg/api"
"netoik.io/netoik-website/pkg/conf"
"netoik.io/netoik-api/pkg/api"
"netoik.io/netoik-api/pkg/conf"
"os"
"path/filepath"
"time"

View File

@ -7,8 +7,8 @@ import (
"github.com/dchest/captcha"
"gopkg.in/gomail.v2"
"net/http"
"netoik.io/netoik-website/pkg/api"
"netoik.io/netoik-website/pkg/conf"
"netoik.io/netoik-api/pkg/api"
"netoik.io/netoik-api/pkg/conf"
"os"
"path/filepath"
)

View File

@ -7,5 +7,5 @@ smtp_username = "<SMTP-USERNAME>"
smtp_password = "<SMTP-PASSWORD>"
smtp_receiver = "<SMTP-RECEIVER>"
captcha_directory = "/tmp/netoik-api/captcha"
captcha_directory = "/var/netoik-api/captcha"
captcha_expiration = "1h"

View File

@ -3,8 +3,9 @@ Description=Netoïk rest api
After=network.target
[Service]
User=www-data
ExecStart=/usr/netoik-api/bin/server -c /etc/netoik-api/server.conf
User=netoik-api
Group=netoik-api
ExecStart=/usr/bin/netoik-api-server -c /etc/netoik-api/server.conf
Restart=always
[Install]