make files around

This commit is contained in:
David Newhall II
2019-06-19 02:52:58 -07:00
parent ffc7fda83b
commit 78f254bee8
5 changed files with 5 additions and 9 deletions
@@ -0,0 +1,34 @@
#
# building static go binary with golang container
#
FROM golang:stretch as builder
RUN mkdir -p $GOPATH/pkg/mod $GOPATH/bin
RUN apt-get update \
&& apt-get install -y curl \
&& curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh \
&& mkdir -p $GOPATH/src/github.com/davidnewhall
COPY . $GOPATH/src/github.com/davidnewhall/unifi-poller
WORKDIR $GOPATH/src/github.com/davidnewhall/unifi-poller
RUN dep ensure \
&& CGO_ENABLED=0 make linux
#
# creating container for run
# to use this container use the following command:
#
# docker run -d -v /your/config/up.conf:/etc/unifi-poller/up.conf golift/unifi-poller
#
# by using "-e UNIFI_PASSWORD=your-secret-pasword" you can avoid this configuration in the config file
#
FROM scratch
COPY --from=builder /go/src/github.com/davidnewhall/unifi-poller/unifi-poller.linux /unifi-poller
COPY --from=builder /go/src/github.com/davidnewhall/unifi-poller/examples/up.conf.example /etc/unifi-poller/up.conf
VOLUME [ "/etc/unifi-poller"]
ENTRYPOINT [ "/unifi-poller" ]
@@ -0,0 +1,70 @@
# Homebrew Formula Template. Built by Makefile: `make fomula`
require "language/go"
class UnifiPoller < Formula
version "{{Version}}"
sha256 "{{SHA256}}"
url "{{URL}}/archive/v#{version}.tar.gz"
head "{{URL}}"
desc "{{Desc}}"
homepage "{{URL}}"
depends_on "go" => :build
depends_on "dep"
def install
ENV["GOPATH"] = buildpath
bin_path = buildpath/"src/github.com/davidnewhall/unifi-poller"
# Copy all files from their current location (GOPATH root)
# to $GOPATH/src/github.com/davidnewhall/unifi-poller
bin_path.install Dir["*"]
cd bin_path do
system "dep", "ensure"
system "make", "install", "VERSION=#{version}", "PREFIX=#{prefix}", "ETC=#{etc}"
# If this fails, the user gets a nice big warning about write permissions on their
# #{var}/log folder. The alternative could be letting the app silently fail
# to start when it cannot write logs. This is better. Fix perms; reinstall.
system "touch", "#{var}/log/unifi-poller.log"
end
end
def caveats
s = <<-EOS
This application will not work until the config file has authentication
information for a Unifi Controller and an Influx Database. Edit the config
file at #{etc}/unifi-poller/up.conf then start the application with
brew services start unifi-poller ~ log file: #{var}/log/unifi-poller.log
The manual explains the config file options: man unifi-poller
EOS
end
def plist; <<-EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{bin}/unifi-poller</string>
<string>-c</string>
<string>#{etc}/unifi-poller/up.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>#{var}/log/unifi-poller.log</string>
<key>StandardOutPath</key>
<string>#{var}/log/unifi-poller.log</string>
</dict>
</plist>
EOS
end
test do
assert_match "unifi-poller v#{version}", shell_output("#{bin}/unifi-poller -v 2>&1", 2)
end
end