diff --git a/src/.goreleaser.yml b/src/.goreleaser.yml index 5002bbb4..dd41411d 100644 --- a/src/.goreleaser.yml +++ b/src/.goreleaser.yml @@ -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: knoxAutoPolicy + 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/knoxAutoPolicy/src/knoxAutoPolicy" + id: knoxAutoPolicy goos: - linux #- windows #- darwin goarch: - amd64 + archives: - - replacements: - darwin: Darwin - linux: Linux - windows: Windows - 386: i386 - amd64: x86_64 + - id: "knoxAutoPolicy" + builds: + - "knoxAutoPolicy" + name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}" + files: + - src: ./conf/local-file.yaml + dst: /opt/knoxAutoPolicy + strip_parent: true + - src: ./packaging/knoxAutoPolicy.service + dst: /usr/lib/systemd/system + strip_parent: true + +nfpms: + - id: "knoxAutoPolicy" + builds: + - "knoxAutoPolicy" + formats: + - deb + - rpm + replaces: + - knoxAutoPolicy + maintainer: "Ankur Kothiwal " + description: | + Auto policy discovery engine + file_name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}" + bindir: / + contents: + - dst: /opt/knoxAutoPolicy + type: dir + - src: ./conf/local-file.yaml + dst: /opt/knoxAutoPolicy/conf/local-file.yaml + type: config + - src: ./packaging/knoxAutoPolicy.service + dst: /usr/lib/systemd/system/knoxAutoPolicy.service + type: config + - src: /opt/knoxAutoPolicy/src/knoxAutoPolicy + dst: /usr/local/bin/knoxAutoPolicy + type: symlink + scripts: + postinstall: packaging/post-install.sh + overrides: + deb: + dependencies: + - make + rpm: + dependencies: + - make + checksum: name_template: 'checksums.txt' snapshot: diff --git a/src/Makefile b/src/Makefile index c6ceb6e1..28696269 100644 --- a/src/Makefile +++ b/src/Makefile @@ -38,3 +38,13 @@ clean: .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 diff --git a/src/packaging/knoxAutoPolicy.service b/src/packaging/knoxAutoPolicy.service new file mode 100644 index 00000000..182b58d6 --- /dev/null +++ b/src/packaging/knoxAutoPolicy.service @@ -0,0 +1,11 @@ +[Unit] +Description=knoxAutoPolicy + +[Service] +KillMode=process +EnvironmentFile=/opt/knoxAutoPolicy/local-file.yaml +WorkingDirectory=/opt/knoxAutoPolicy/ +ExecStart=/opt/knoxAutoPolicy/src/knoxAutoPolicy + +[Install] +WantedBy=multi-user.target diff --git a/src/packaging/post-install.sh b/src/packaging/post-install.sh new file mode 100644 index 00000000..23e066b3 --- /dev/null +++ b/src/packaging/post-install.sh @@ -0,0 +1,4 @@ +set -e + +/bin/systemctl daemon-reload +/bin/systemctl start knoxAutoPolicy.service