Skip to content

Commit

Permalink
package discovery-engine as a systemd service
Browse files Browse the repository at this point in the history
Signed-off-by: Ankur Kothiwal <ankur.kothiwal@accuknox.com>
  • Loading branch information
Ankurk99 committed Aug 16, 2022
1 parent 6cd61f8 commit 803eddb
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.vscode/
src/knoxAutoPolicy
src/discovery-engine
script/log
src/log
log
Expand Down
64 changes: 54 additions & 10 deletions src/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,71 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
project_name: discovery-engine

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- env:
- CGO_ENABLED=1
- binary: "opt/discovery-engine/src/discovery-engine"
id: discovery-engine
goos:
- linux
#- windows
#- darwin
goarch:
- amd64

archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
- id: "discovery-engine"
builds:
- "discovery-engine"
name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}"
files:
- src: ./conf/local-file.yaml
dst: /opt/discovery-engine
strip_parent: true
- src: ./packaging/discovery-engine.service
dst: /usr/lib/systemd/system
strip_parent: true

nfpms:
- id: "discovery-engine"
builds:
- "discovery-engine"
formats:
- deb
- rpm
replaces:
- discovery-engine
maintainer: "Ankur Kothiwal <ankur.kothiwal@accuknox.com>"
description: |
Auto policy discovery engine
file_name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}"
bindir: /
contents:
- dst: /opt/discovery-engine
type: dir
- src: ./conf/local-file.yaml
dst: /opt/discovery-engine/conf/local-file.yaml
type: config
- src: ./packaging/discovery-engine.service
dst: /usr/lib/systemd/system/discovery-engine.service
type: config
- src: /opt/discovery-engine/src/discovery-engine
dst: /usr/local/bin/discovery-engine
type: symlink
scripts:
postinstall: packaging/post-install.sh
overrides:
deb:
dependencies:
- make
rpm:
dependencies:
- make

checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
18 changes: 14 additions & 4 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ GIT_INFO := $(shell govvv -flags -pkg $(PKG))

.PHONY: build
build:
@# for build_image -> CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w' -o knoxAutoPolicy main.go
@# for delve -> cd $(CURDIR); go mod tidy; go build -tags debugger -gcflags="all=-N -l" -o knoxAutoPolicy main.go
@# for build_image -> CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s -w' -o discovery-engine main.go
@# for delve -> cd $(CURDIR); go mod tidy; go build -tags debugger -gcflags="all=-N -l" -o discovery-engine main.go
go mod tidy
go build -ldflags "$(GIT_INFO)" -o knoxAutoPolicy main.go
go build -ldflags "$(GIT_INFO)" -o discovery-engine main.go

.PHONY: test
test:
Expand All @@ -33,8 +33,18 @@ gosec:

.PHONY: clean
clean:
cd $(CURDIR); rm -f knoxAutoPolicy go.sum
cd $(CURDIR); rm -f discovery-engine go.sum

.PHONY: image
image:
cd $(CURDIR)/build; $(MAKE)

.PHONY: local-release
local-release: build
ifeq (, $(shell which goreleaser))
@{ \
set -e ;\
go install github.com/goreleaser/goreleaser@latest ;\
}
endif
cd $(CURDIR); VERSION=$(shell git describe --tags --always --dirty) goreleaser release --rm-dist --skip-publish --skip-sign --skip-validate --snapshot
12 changes: 12 additions & 0 deletions src/packaging/discovery-engine.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=discovery-engine

[Service]
User=root
KillMode=process
EnvironmentFile=/opt/discovery-engine/local-file.yaml
WorkingDirectory=/opt/discovery-engine/
ExecStart=/opt/discovery-engine/src/discovery-engine

[Install]
WantedBy=multi-user.target
4 changes: 4 additions & 0 deletions src/packaging/post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set -e

/bin/systemctl daemon-reload
/bin/systemctl start discovery-engine.service
2 changes: 1 addition & 1 deletion tests/test-scenarios-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ res_start_service=0
function start_and_wait_for_KnoxAutoPolicy_initialization() {
export CONF_FILE_NAME=local

$AUTOPOL_HOME/src/knoxAutoPolicy -config-path=$AUTOPOL_HOME/tests/conf &
$AUTOPOL_HOME/src/discovery-engine -config-path=$AUTOPOL_HOME/tests/conf &
echo $?
if [ $? != 0 ]; then
res_start_service=1
Expand Down

0 comments on commit 803eddb

Please sign in to comment.