diff --git a/.dockerignore b/.dockerignore index a759298..0529cd3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,6 @@ bin/ -Dockerfile* \ No newline at end of file +Dockerfile* +.dockerignore +.idea/ +baronial*.tar.gz +azure-pipelines.yml diff --git a/.gitignore b/.gitignore index 28a17c9..83786f1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ baronial *.exe bin/ +version.txt +revision.txt +baronial*.tar.gz # System specific filesystem junk .DS_Store \ No newline at end of file diff --git a/Dockerfile.alpine b/Dockerfile.alpine index b9715ed..c24fc5e 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,6 +1,6 @@ -ARG BASE_IMAGE=golang:alpine +ARG alpine_version=3.9 -FROM ${BASE_IMAGE} AS builder +FROM golang:alpine${alpine_version} AS builder RUN apk add --no-cache --update alpine-sdk gcc make git @@ -13,7 +13,7 @@ RUN make install CMD /bin/bash -FROM alpine AS execution +FROM alpine:${alpine_version} AS execution COPY --from=builder /go/bin/baronial /usr/local/bin diff --git a/Dockerfile.fedora b/Dockerfile.fedora new file mode 100644 index 0000000..8a5685c --- /dev/null +++ b/Dockerfile.fedora @@ -0,0 +1,28 @@ +ARG tag=29 + +FROM fedora:${tag} AS rpm-builder + +RUN dnf install -y gcc rpm-build rpm-devel rpmlint make python bash coreutils diffutils patch rpmdevtools go perl +RUN rpmdev-setuptree + +WORKDIR /usr/src/baronial + +ADD . . + +ARG release=1 +RUN make baronial.tar.gz && \ + version=$(cat ./version.txt) && \ + rpm_version=$(echo ${version} | perl ./packaging/redhat/redhatify-version.pl) && \ + cp ./baronial.tar.gz ${HOME}/rpmbuild/SOURCES/ && \ + mv ${HOME}/rpmbuild/SOURCES/baronial.tar.gz ${HOME}/rpmbuild/SOURCES/baronial-${rpm_version}.tar.gz && \ + rpmbuild --define "raw_version ${version}" --define "rpm_version ${rpm_version}" --define "release ${release}" -ba ./packaging/redhat/baronial.spec + +FROM fedora:${tag} AS execution + +WORKDIR /root + +COPY --from=rpm-builder /root/rpmbuild/RPMS/x86_64/baronial-*.rpm ./baronial.rpm + +RUN rpm -i baronial.rpm && rm baronial.rpm + +CMD /bin/bash diff --git a/Makefile b/Makefile index 68d3e38..19854a6 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,6 @@ SRC = $(shell find . -name '*.go' -type f) TEST_SRC = $(shell find . -name '*_test.go' -type f) -# Define the current git revision being packed into each of the build products. -REVISION = $(shell sh ./get-revision.sh) -VERSION = $(shell sh ./get-version.sh) - # Define high-level build targets. .PHONY: all all: darwin linux windows test lint @@ -20,23 +16,35 @@ darwin: bin/darwin/baronial.gz windows: bin/windows/baronial.exe .PHONY: docker -docker: bin/docker/baronial-alpine.tar.gz bin/docker/baronial-debian.tar.gz +docker: bin/docker/baronial-alpine.tar.gz bin/docker/baronial-debian.tar.gz bin/docker/baronial-fedora.tar.gz + +version.txt: ${SRC} + sh ./get-version.sh > version.txt + +revision.txt: ${SRC} + sh ./get-revision.sh > revision.txt # Define specific build targets. -bin/darwin/baronial: ${SRC} .git/HEAD go.sum - GOOS=darwin go build -ldflags "-X github.com/marstr/baronial/cmd.revision=${REVISION} -X github.com/marstr/baronial/cmd.version=${VERSION}" -o bin/darwin/baronial +bin/darwin/baronial: ${SRC} go.sum version.txt + mkdir -p bin/darwin + GOOS=darwin go build -ldflags "-X github.com/marstr/baronial/cmd.revision=$(cat ./revision.txt) -X github.com/marstr/baronial/cmd.version=$(cat ./version.txt)" -o bin/darwin/baronial bin/darwin/baronial.gz: bin/darwin/baronial gzip -kf bin/darwin/baronial -bin/linux/baronial: ${SRC} .git/HEAD go.sum - GOOS=linux go build -ldflags "-X github.com/marstr/baronial/cmd.revision=${REVISION} -X github.com/marstr/baronial/cmd.version=${VERSION}" -o bin/linux/baronial +bin/linux/baronial: ${SRC} go.sum version.txt + mkdir -p bin/linux + GOOS=linux go build -ldflags "-X github.com/marstr/baronial/cmd.revision=$(cat ./revision.txt) -X github.com/marstr/baronial/cmd.version=$(cat ./version.txt))" -o bin/linux/baronial bin/linux/baronial.gz: bin/linux/baronial gzip -kf bin/linux/baronial -bin/windows/baronial.exe: ${SRC} .git/HEAD go.sum - GOOS=windows go build -ldflags "-X github.com/marstr/baronial/cmd.revision=${REVISION} -X github.com/marstr/baronial/cmd.version=${VERSION}" -o bin/windows/baronial.exe +bin/linux/baronial-%.rpm: ${SRC} go.sum version.txt packaging/redhat/baronial.spec packaging/redhat/redhatify-version.pl + docker build -t mars + +bin/windows/baronial.exe: ${SRC} go.sum + mkdir -p bin/windows + GOOS=windows go build -ldflags "-X github.com/marstr/baronial/cmd.revision=$(cat ./revision.txt) -X github.com/marstr/baronial/cmd.version=$(cat ./version.txt)" -o bin/windows/baronial.exe bin/docker/baronial-alpine.tar.gz: ${SRC} Dockerfile.alpine mkdir -p bin/docker @@ -48,6 +56,14 @@ bin/docker/baronial-debian.tar.gz: ${SRC} Dockerfile.debian docker build -t marstr/baronial:debian -f Dockerfile.debian . docker save marstr/baronial:debian | gzip > bin/docker/baronial-debian.tar.gz +bin/docker/baronal-fedora.tar.gz: ${SRC} Dockerfile.fedora + mkdir -p bin/docker + docker build -t marstr/baronial:fedora -f Dockerfile.fedora . + docker save marstr/baronial:fedora | gzip > bin/docker/baronial-fedora.tar.gz + +baronial.tar.gz: ${SRC} LICENSE version.txt revision.txt + bash ./archive-src.sh + # Ensure that the Go dependency tree is satisfied. go.sum: go.mod go mod verify @@ -66,12 +82,12 @@ lint: ${SRC} ${TEST_SRC} # Install this build on the local system. .PHONY: install -install: ${SRC} - go install -ldflags "-X github.com/marstr/baronial/cmd.revision=${REVISION} -X github.com/marstr/baronial/cmd.version=${VERSION}" +install: ${SRC} version.txt + go install -ldflags "-X github.com/marstr/baronial/cmd.revision=$(cat ./revision.txt) -X github.com/marstr/baronial/cmd.version=$(cat ./version.txt)" # Remove all build products from the current system. .PHONY: clean clean: rm -rf bin - docker rmi -f marstr/baronial:debian - docker rmi -f marstr/baronial:alpine \ No newline at end of file + rm -f revision.txt version.txt baronial.tar.gz + docker rmi -f marstr/baronial:debian || docker rmi -f marstr/baronial:alpine || docker rmi -f marstr/baronial:fedora diff --git a/archive-src.sh b/archive-src.sh new file mode 100755 index 0000000..840bc89 --- /dev/null +++ b/archive-src.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -ev + +dest="baronial-$(cat ./version.txt)" +mkdir -p ${dest} +cp -r -t ${dest} cmd/ internal/ go.mod go.sum Makefile LICENSE version.txt revision.txt main.go +tar -czvf "baronial.tar.gz" ${dest} +rm -rf ${dest} diff --git a/go.mod b/go.mod index 12ec159..b1703de 100644 --- a/go.mod +++ b/go.mod @@ -9,4 +9,9 @@ require ( github.com/sirupsen/logrus v1.2.0 github.com/spf13/cobra v0.0.3 github.com/spf13/viper v1.3.1 + golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480 // indirect + golang.org/x/lint v0.0.0-20190409202823-959b441ac422 // indirect + golang.org/x/net v0.0.0-20190420063019-afa5a82059c6 // indirect + golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a // indirect + golang.org/x/tools v0.0.0-20190420181800-aa740d480789 // indirect ) diff --git a/go.sum b/go.sum index afcc090..f25bff8 100644 --- a/go.sum +++ b/go.sum @@ -51,11 +51,25 @@ github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1: golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480 h1:O5YqonU5IWby+w98jVUG9h7zlCWCcH4RHyPVReBmhzk= +golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422 h1:QzoH/1pFpZguR8NrRHLcO6jKqfv2zpuSqZLgdm7ZmjI= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a h1:1n5lsVfiQW3yfsRGu98756EH1YthsFqr/5mxHduZW2A= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a h1:XCr/YX7O0uxRkLq2k1ApNQMims9eCioF9UpzIPBDmuo= +golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190420181800-aa740d480789 h1:FF0rjo15h51+N6642mf5S3QuplmKo2aCrJUYkHTx85s= +golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= diff --git a/packaging/redhat/baronial.spec b/packaging/redhat/baronial.spec new file mode 100644 index 0000000..40bbd09 --- /dev/null +++ b/packaging/redhat/baronial.spec @@ -0,0 +1,27 @@ +Name: baronial +Version: %{rpm_version} +Release: %{release} +Summary: Scriptable personal finance tooling +License: GPLv3 +Source0: ./baronial-%{rpm_version}.tar.gz + +%define debug_package %{nil} + +BuildRequires: make go git + +%prep +%setup -q -n baronial-%{raw_version} + +%build +make bin/linux/baronial + +%install +mkdir -p %{buildroot}/usr/bin +install -m 755 bin/linux/baronial %{buildroot}/usr/bin/baronial + +%files +%license LICENSE +/usr/bin/baronial + +%description +Command line budgeting application. diff --git a/packaging/redhat/redhatify-version.pl b/packaging/redhat/redhatify-version.pl new file mode 100644 index 0000000..99f2cfd --- /dev/null +++ b/packaging/redhat/redhatify-version.pl @@ -0,0 +1,17 @@ +#!/usr/bin/env perl + +use strict; +use warnings FATAL => 'all'; + +while(my $row = ) { + if ($row =~ /^[vV]?(?\d+(?:\.\d+){0,2})(?:-(?\S+))?$/) { + my $transformed = $+{version}; + + + if (defined $+{tag}) { + $transformed = $transformed . "~" . $+{tag}; + } + + print($transformed . "\n"); + } +}