Code Monkey home page Code Monkey logo

go-bin-rpm's Introduction

go-bin-rpm

travis Status Go Report Card GoDoc MIT License

Create binary rpm package with ease

Using a json files to declare rules, it then performs necessary operations to invoke rpmbuild and build the package.

This tool is part of the go-github-release workflow

See the demo.

TOC

Install

Check the release page!

Glide

mkdir -p $GOPATH/src/github.com/mh-cbon/go-bin-rpm
cd $GOPATH/src/github.com/mh-cbon/go-bin-rpm
git clone https://github.com/mh-cbon/go-bin-rpm.git .
glide install
go install

linux rpm/deb repository

wget -O - https://raw.githubusercontent.com/mh-cbon/latest/master/bintray.sh \
| GH=mh-cbon/go-bin-rpm sh -xe
# or
curl -L https://raw.githubusercontent.com/mh-cbon/latest/master/bintray.sh \
| GH=mh-cbon/go-bin-rpm sh -xe

linux rpm/deb standalone package

curl -L https://raw.githubusercontent.com/mh-cbon/latest/master/install.sh \
| GH=mh-cbon/go-bin-rpm sh -xe
# or
wget -q -O - --no-check-certificate \
https://raw.githubusercontent.com/mh-cbon/latest/master/install.sh \
| GH=mh-cbon/go-bin-rpm sh -xe

Usage

Requirements

A centos/fedora/redhat system, vagrant, travis, docker, whatever.

Workflow overview

To create a binary package you need to

  • build your application binaries
  • invoke go-bin-rpm to generate the package
  • create rpm repositories on travis hosted on gh-pages using this script

Json file

For a real world example including service, shortcuts, env, see this

For a casual example to provide a simple binary, see this

JSON tokens

Several tokens are provided to consume into the JSON file.

name description example
!version! The version number provided in the command line, or in the JSON file. 1.0.2
!arch! The architecture short name provided in the command line or in the JSON file. amd64
!name! The name of the project provided in the JSON file. hello

CLI

go-bin-rpm -help

NAME:
   go-bin-rpm - Generate a binary rpm package

USAGE:
   go-bin-rpm <cmd> <options>
   
VERSION:
   1.0.0
   
COMMANDS:
     generate-spec  Generate the SPEC file
     generate       Generate the package
     test           Test the package json file
     help, h        Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help
   --version, -v  print the version

go-bin-rpm generate-spec -help

NAME:
   go-bin-rpm generate-spec - Generate the SPEC file

USAGE:
   go-bin-rpm generate-spec [command options] [arguments...]

OPTIONS:
   --file value, -f value  Path to the rpm.json file (default: "rpm.json")
   -a value, --arch value  Target architecture of the build
   --version value         Target version of the build

go-bin-rpm generate -help

NAME:
   go-bin-rpm generate - Generate the package

USAGE:
   go-bin-rpm generate [command options] [arguments...]

OPTIONS:
   --file value, -f value        Path to the rpm.json file (default: "rpm.json")
   -b value, --build-area value  Path to the build area (default: "pkg-build")
   -a value, --arch value        Target architecture of the build
   -o value, --output value      File path to the resulting rpm file
   --version value               Target version of the build

go-bin-rpm test -help

NAME:
   go-bin-rpm test - Test the package json file

USAGE:
   go-bin-rpm test [command options] [arguments...]

OPTIONS:
   --file value, -f value  Path to the rpm.json file (default: "rpm.json")

Recipes

Installing generated package

TLDR

# install
sudo rpm -ivh pkg.rpm
# upgrade
sudo rpm -Uvh pkg.rpm
# remove
sudo rpm -evv nx pkg.rpm

Vagrant recipe

Please check the demo app here

Travis recipe

  • get a github repo
  • get a travis account
  • connect your github account to travis and register your repo
  • install travis client gem install --user travis
  • run travis encrypt --add -r YOUR_USERNAME/dummy GH_TOKEN=xxxx
  • run travis setup releases
  • personalize the .travis.yml
  sudo: required
  services:
  - docker
  language: go
  go:
  - 1.8
  - 1.9
  env:
    matrix:
    - OKARCH=amd64 OSARCH=amd64
    - OKARCH=386 OSARCH=i386
    global:
    - VERSION=${TRAVIS_TAG}
    - GH_USER=${TRAVIS_REPO_SLUG%/*}
    - GH_APP=${TRAVIS_REPO_SLUG#*/}
    - JFROG_CLI_OFFER_CONFIG=false
    - secure: iTmECM/2XzLk4/bMm4xCYcVyKJj6kV815wLlFyCMzcBHoQmOjYxWu6s36sQ9SecPu/fjE67+rJ6opPpeMz9SRTa34+L64vA0gRA61TynC3NUOIkvzs0y956fhxVGPF5knLnKGeWIHHObfxwo8ovvY+utWI4DqYwfWoIzGZ7Etc1Pp/zY4rIFYiNpRHH5zpvKG3+wjDx6ciUmZASM4ZFEY9OY5LlnOKxaxTFz71i0SZJO18fNTX1NrWEf55pU35CzVpk1rZ1V7cKt1i7k9MqWWwG5RXIzjLWjTx2aFJOchTj2kV7MM8FPk3FcQIiJ0JCPqkaVMNWTa3f++wH85fk2r4ErlVGvtG6xuHAy7uM4GBPX2nmUnEXIlg8qVHgYqUxg18qi92osJIVv3WZgNrL42dRQMHDcEf0b0NMEifpsPES65CnVQPMEZlN+eXzgVMMKS9s/Vf5B8HziDxkTy/crghqMQtff2HZ1eyH1gmLMA9HXQIFWCsAIEfrrgP5doNIfsHJaWP31agSyrHhGMI8y77kVj9K/cxL0XVq9mKlXtnI7S5OKgDD1Dn/PuUPkfrPFQ0wxCfXJ+FyqSyckUd7rTlihJKOlmEvHif3y7BK+qCbj/G7JveQGLKHt/fiIbo00PBvalLSSJDQEsFyO+cKLsR8uVyX/BgaMed6qt2RrzYE=
  before_install:
  - sudo apt-get -qq update
  - mkdir -p ${GOPATH}/bin
  - cd ~
  - curl https://glide.sh/get | sh
  install:
  - cd $GOPATH/src/github.com/${TRAVIS_REPO_SLUG}
  - glide install
  - go install
  script: echo "pass"
  before_deploy:
  - docker pull fedora
  - mkdir -p build/$OSARCH
  - GOOS=linux GOARCH=$OKARCH go build --ldflags "-X main.VERSION=$VERSION" -o build/$OSARCH/$GH_APP
    main.go
  - cp $GOPATH/bin/go-bin-rpm tmp
  - |
    docker run -v $PWD:/mnt/travis fedora /bin/sh -c "cd /mnt/travis && (curl -s -L https://bintray.com/bincrafters/public-rpm/rpm > /etc/yum.repos.d/w.repo) && dnf install go-bin-rpm changelog rpm-build -y --quiet && go-bin-rpm generate --file rpm.json -a $OSARCH --version $VERSION -o $GH_APP-$OSARCH-$VERSION.rpm"
  - rm -f ./tmp
  - cp $GH_APP-$OSARCH-$VERSION.rpm $GH_APP-$OKARCH.rpm
  - curl -fL https://getcli.jfrog.io | sh
  - ./jfrog bt pc --key=$BTKEY --user=$GH_USER --licenses=MIT --vcs-url=https://github.com/$GH_USER/rpm
    $GH_USER/rpm/$GH_APP || echo "package already exists"
  - ./jfrog bt upload --override=true --key $BTKEY --publish=true $GH_APP-$OSARCH-$VERSION.rpm
    $GH_USER/rpm/$GH_APP/$VERSION pool/$POOL/$GH_APP/
  - curl -X POST -u ${GH_USER}:${BTKEY} https://api.bintray.com/calc_metadata/${GH_USER}/rpm
  deploy:
    provider: releases
    api_key:
      secure: CY2nebPdr2CSCZW34QCtlw/IdbaHl5T77xPFlmvXB2Z+0SnO0RTW7JvFMa2mDYxa6ibZ6dR2br9YwdgJYnqV+PnXCizvZ5KPqpHxE31ta4s1IokZr+v9J+deGvUdk60oF5mxkqcGgAtScEGC5ZVJ/0EqAn64o4+H3fOQfA1pYTpzUBL/c9yUNqAFLFDVXz1sd7eSccPwf1uthdhndybMgatogfQuUBmm3vNJYYheAF8XCimBmrsIkPed+OKfhkDqUCTdgSTOQWvv0Uf8ib5VUH0w+UV8Wx69/KNKVhp/f7Nhf6GCKT1AKh/fQxjpRaWdkQLsn7nqPVuF0dHYV/mtdo4EP0FDj+2a3LvtGpEst90Mo0SRzauhqCQqCopyOf3JKkKPqTyMRDKAzYWAymjeLGaPda4wOxNROWV7yBuXNTTUmU2GDPUMULnLA7v+0ml6wd3gGCOMU5It8Iynkuxts8ATlpa0qels3memQITfhkTdR3CFT2mr/frkDiVOtqnp6BJoQIjhSMXoMRfnSpnNOszsiLNa9pM+hNG3HeZN0MQ+gTlRgqmTSitvllr751oUhgNzjv35FDxaywFwKlqtaJfX9UVCLxcBTvDcP4ZKHJRbgFOmffv2mnKi1S8K26LUkuLZDKvCZgrw8iM1KjvPX/GP9tXaxgLrfsfQOcOGGGs=
    file_glob: true
    file:
    - $GH_APP-$OKARCH.rpm
    skip_cleanup: true
    overwrite: true
    true:
      tags: true

useful rpm commands

# check dependencies before install
rpm -qpR pkg.rpm
# show info of a package before install
rpm -qip pkg.rpm
# install with no dependencies
rpm -ivh --nodeps pkg.rpm
# show info of installed package
rpm -qi pkg
# check installed package
rpm -q pkg
# list files of installed package
rpm -ql pkg

Readings of interest

Release the project

gump patch -d # check
gump patch # bump

History

CHANGELOG

go-bin-rpm's People

Contributors

mh-cbon avatar solvingj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-bin-rpm's Issues

unintended BuildRequires

Although I did not specify anything related to desktop-file-utils, I get the following in a spec files:

...
BuildRequires:desktop-file-utils
...
%{_datadir}/applications/.desktop
%{_datadir}/pixmaps/my-utility-name
...
%post
echo "Executing Post-Installation Tasks";
desktop-file-install --vendor='' --dir=%{buildroot}%{_datadir}/applications/my-utility-name %{buildroot}/%{_datadir}/applications/.desktop

I did have echo "Executing Post-Installation Tasks"; in one of shell files, but no ref to desktop-file-install.

It also generate some temp files:

$ cat /tmp/rpm-desktops671710608/.desktop
[Desktop Entry]
GenericName=!name!
Type=Application
Categories=Utility;
Keywords=my-keyword;
StartupNotify=false
DBusActivatable=false
NoDisplay=false
Terminal=false

Error generating "noarch" RPM's. No error generating "all" DEB with go-bin-deb

The log below shows the output of the go-bin-rpm command, and the error is fairly clear. It's trying to "require" the current platforms specific standard library for C++.

Obviously, somewhere there's an option in the pipeline were one can clarify that the package "requires" the STL for C++ in an "architecture-agnostic" way, but I don't know where that is. Is it in the C++ build system, or is it in the rpm.json file, is it in the C++ build files somewhere?

Note: I've also included my rpm.json below.

Another reason it's perplexing is that I was able to use go-bin-deb to generate the equivalent cross-architecture .deb package with go-bin-deb. I also did test and install that on both a 32 and 64 bin Debian machines.

Overall, I am not sure it's something that can be fixed in go-bin-rpm, but this will definitely come up again for future users so I thought we should figure it out and document it if possible.

[root@localhost go-github-release-test]# go-bin-rpm generate --file rpm-creation-data.json --version  0.0.1 --arch noarch -o  go-github-release-test-noarch-0.0.1.rpm
Building target platforms: noarch
Building for target noarch
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.rXqM4j
+ umask 022
+ cd /root/go-github-release-test/pkg-build/BUILD
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.VVmuU4
+ umask 022
+ cd /root/go-github-release-test/pkg-build/BUILD
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.EFGBKP
+ umask 022
+ cd /root/go-github-release-test/pkg-build/BUILD
+ '[' /root/go-github-release-test/pkg-build/BUILDROOT/go-github-release-test-0.0.1-1.noarch '!=' / ']'
+ rm -rf /root/go-github-release-test/pkg-build/BUILDROOT/go-github-release-test-0.0.1-1.noarch
++ dirname /root/go-github-release-test/pkg-build/BUILDROOT/go-github-release-test-0.0.1-1.noarch
+ mkdir -p /root/go-github-release-test/pkg-build/BUILDROOT
+ mkdir /root/go-github-release-test/pkg-build/BUILDROOT/go-github-release-test-0.0.1-1.noarch
+ mkdir -p /root/go-github-release-test/pkg-build/BUILDROOT/go-github-release-test-0.0.1-1.noarch//usr/bin
+ cp /root/go-github-release-test/build/go-github-release-test /root/go-github-release-test/pkg-build/BUILDROOT/go-github-release-test-0.0.1-1.noarch//usr/bin
+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
+ /usr/lib/rpm/redhat/brp-python-hardlink
+ /usr/lib/rpm/redhat/brp-java-repack-jars
Processing files: go-github-release-test-0.0.1-1.noarch
Provides: go-github-release-test = 0.0.1-1
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires: libc.so.6()(64bit) libc.so.6(GLIBC_2.2.5)(64bit) libgcc_s.so.1()(64bit) libm.so.6()(64bit) libstdc++.so.6()(64bit) libstdc++.so.6(GLIBCXX_3.4)(64bit) rtld(GNU_HASH)
error: Arch dependent binaries in noarch package


RPM build errors:
    Arch dependent binaries in noarch package
exit status 1
[root@localhost go-github-release-test]#

RPM Build definition file:

{
  "name": "go-github-release-test",
  "summary": "Test of go-github-release process",
  "description": "Test of go-github-release process",
  "changelog-cmd": "changelog rpm",
  "license": "LICENSE",
  "url": "http://github.com/solvingj/go-github-release-test",
  "files": [
    {
      "from": "build/!name!",
      "to": "%{_bindir}/",
      "base": "build",
      "type": ""
    }
  ],
  "copyrights": [
    {
      "files": "*",
      "copyright": "2017 Jerry Wiltse",
      "license": "MIT",
      "file": "LICENSE"
    }
  ],
  "requires": [
	"rpm-build", 
	"changelog"	
  ]
}

environment variables in rpm.json and command-line options

Provided environment variable in rpm.json:

  "envs": {
    "MY_APP_VER": "!version!"
  }

The expectation was that it would convert the !version! to the value supplies in --version 1.0.

It did not happen:

cat /tmp/rpm-envs550071300/my-app.sh
#!/bin/bash

MY_APP_VER=!version!

export MY_APP_VER

Base Fedora Docker Image does not have rpmbuild

I was trying to understand the contents of create-package.sh and I found this:

docker run -v $PWD/:${TRAVIS_BUILD_DIR} fedora /bin/sh -c "cd ${TRAVIS_BUILD_DIR} && sh ./docker.sh"
sudo chown travis:travis ./*-*.rpm

This fedora docker image returns the following error when trying to use go-bin-rpm in it:

exec: "rpmbuild": executable file not found in $PATH

Obviously mh-cbon was able to package RPM's on this image, but I don't understand how.

Can anyone comment?

spec %clean

Let's say I have a configuration file that has:

  "preinst": "rpmbuild/pre_installation.sh",
  "postinst": "rpmbuild/post_installation.sh",
  "prerm": "rpmbuild/pre_removal.sh",
  "postrm": "rpmbuild/post_removal.sh",
  "verify": "rpmbuild/verification.sh",
  "clean": "rpmbuild/cleanup.sh",

When I generate a spec file, it outputs:

%clean

%pre
echo "Executing Pre-Installation Tasks";


%post
echo "Executing Post-Installation Tasks";


%preun
echo "Executing Pre-Removal Tasks";


%postun
echo "Executing Post-Removal Tasks";


%verifyscript
echo "Executing Verification Tasks";

No %clean phase.

I guess adding something like the below to

if content := readFile(p.PreInst); content != "" {
would do it:

	if content := readFile(p.CleanBuildDir); content != "" {
		spec += fmt.Sprintf("\n%%clean\n%s\n", content)
}

To get the following out:

%clean
rm -rf $RPM_BUILD_ROOT

"generate --output" requires a filename, docs indicate it should take directory (and it should)

The documentation says the following:

-o value, --output value Output package to this path

The documentation for go-bin-deb says the following:

-output value, -o value Output directory for the debian package files

In the case of this library (go-bin-rpm), i have to provide a file path with the full filename.

It would be vastly preferred if it actually did take a "directory" because the tool generates the correct filenames inside the pkg-build directory, and I just want to copy the result file out to a destination directory.

binary in rpm without debuginfo

use the tool to make rpm, the binary file in rpm without debuginfo after install. Could u update this tool to add a debuginfo rpm package when use it to make rpm?

Add --release option

I think it makes sense to allow adding release as a command-line parameter:

go-bin-rpm generate-spec --version 5.1 --release 1 --file rpm.json --arch 386

If I do go-bin-rpm generate-spec --version 5.1 --file rpm.json --arch 386 and add release 1 in rpm.json, I get the following spec file output:

Version: 5.1.0
Release: 1

I would expect Version: 5.1, but get 5.1.0 instead.

rpm update vs rpm uninstall

"prerm" and "postrm" in json file, cannot distinguish shell from update or uninstall. In addition, can u provide completed syntax explain in json file?

Add Source0 to rpm.json

Source0: The full URL for the compressed archive containing the (original) pristine source code, as upstream released it. "Source" is synonymous with "Source0". If you give a full URL (and you should), its basename will be used when looking in the SOURCES directory. If possible, embed %{name} and %{version}, so that changes to either will go to the right place. Preserve timestamps when downloading source files. If there is more than one source, name them Source1, Source2 and so on. If you're adding whole new files in addition to the pristine sources, list them as sources after the pristine sources. A copy of each of these sources will be included in any SRPM you create, unless you specifically direct otherwise. See Source URL for more information on special cases (e.g. revision control).

Reference: https://fedoraproject.org/wiki/How_to_create_an_RPM_package

We shouldn't append the $PATCH number version

I aware of the document talking about the packaging tag https://fedoraproject.org/wiki/Packaging:Naming?rd=Packaging:NamingGuidelines#Version_Tag

Therefore, In my perspective, we should allow creating packages that the original version has only the $MAJOR.$MINOR-$WHATEVER

e.x: ca-proxy-12.70-sp02-linux-x86-64.bin

For this case, we are expecting to create a package called ca-proxy-12.70-sp02-linux-x86-64.rpm instead of that, the current go-bin-rpm is creating ca-proxy-12.70.0-sp02-linux-x86-64.rpm (adding extra/invalid $PATCH number)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.