Skip to content

Instantly share code, notes, and snippets.

@erchn
Created February 1, 2017 19:34
Show Gist options
  • Save erchn/a399f79c0a528232de2574c8c97d655e to your computer and use it in GitHub Desktop.
Save erchn/a399f79c0a528232de2574c8c97d655e to your computer and use it in GitHub Desktop.
Running rbenv in production using RPMs (tested on centos 6)
pathadd() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="$1:${PATH:+"$PATH:"}"
fi
}
# rbenv setup
export RBENV_ROOT=/opt/rbenv
pathadd /opt/rbenv/bin
# if interactive
if [ -n "$PS1" ]; then
# if rbenv is not already a function
if ! type -t rbenv | grep -q function; then
eval "$(rbenv init -)"
fi
else
# non-interactive, just add shims path
pathadd /opt/rbenv/shims
fi
export PATH
unset -f pathadd
%define _major 1
%define _minor 9
%define _patch 3
%define _minor_patch p551
%define VERSION %{_major}.%{_minor}.%{_patch}
%define ruby_lib_version %{_major}.%{_minor}.%{_patch}-%{_minor_patch}
Name: rbenv-ruby%{_major}%{_minor}
Version: %{VERSION}
Release: %{_minor_patch}.4%{?dist}
Summary: A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.
Group: Development/Language
License: (Ruby or BSD) and Public Domain
URL: https://www.ruby-lang.org/en/
Source0: ruby-%{version}.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires: rbenv-devel
BuildRequires: libyaml-devel openssl-devel libffi-devel readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel
BuildRequires: byacc
%if 0%{?rhel_version} >= 700 || 0%{?centos_version} >= 700
BuildRequires: libdb-devel
%else
BuildRequires: db4-devel
%endif
Requires: rbenv
%description
A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.
%prep
%setup -q -n ruby-%{version}%{_minor_patch}
%build
%define _prefix %{rbenv_root}/versions/%{ruby_lib_version}
%configure \
--with-ruby-pc='ruby.pc' \
--enable-shared \
--disable-rpath \
--mandir=%{_prefix}/share/man \
--disable-install-doc \
--disable-install-rdoc \
--disable-install-capi \
--with-ruby-version='%{VERSION}'
make %{?_smp_mflags} COPY="cp -p" Q=
%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=%{buildroot}
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/ld.so.conf.d/
cat > $RPM_BUILD_ROOT/%{_sysconfdir}/ld.so.conf.d/%{name}.conf <<EOF
%{_libdir}
EOF
%post
/sbin/ldconfig
export RBENV_ROOT=%{rbenv_root}
%{rbenv_root}/bin/rbenv sh-rehash
%postun -p /sbin/ldconfig
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%{_prefix}
%{_sysconfdir}/ld.so.conf.d/%{name}.conf
%doc ChangeLog
%doc doc/ChangeLog-*
%changelog
* Wed Feb 1 2017 Ethan Erchinger <[email protected]> - 1.9.3
- support ruby 1.9.3
* Sat Jan 11 2015 墨泪<[email protected]> - 2.2.0
- initial import
%define _major 2
%define _minor 3
%define _patch 3
%define VERSION %{_major}.%{_minor}.%{_patch}
%define ruby_lib_version %{_major}.%{_minor}
Name: rbenv-ruby%{_major}%{_minor}
Version: %{VERSION}
Release: 1%{?dist}
Summary: A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.
Group: Development/Language
License: (Ruby or BSD) and Public Domain
URL: https://www.ruby-lang.org/en/
Source0: ruby-%{version}.tar.gz
Source1: operating_system.rb
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires: rbenv-devel
BuildRequires: libyaml-devel openssl-devel libffi-devel readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel
BuildRequires: byacc
%if 0%{?rhel_version} >= 700 || 0%{?centos_version} >= 700
BuildRequires: libdb-devel
%else
BuildRequires: db4-devel
%endif
Requires: rbenv
%description
A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.
%prep
%setup -q -n ruby-%{version}
%build
%define _prefix %{rbenv_root}/versions/%{version}
%configure \
--with-ruby-pc='ruby.pc' \
--enable-shared \
--disable-rpath \
--mandir=%{_prefix}/share/man \
--disable-install-doc \
--disable-install-rdoc \
--disable-install-capi \
--enable-load-relative \
--with-rubylibprefix=%{_prefix} \
--with-ruby-version='%{ruby_lib_version}'
make %{?_smp_mflags} COPY="cp -p" Q=
%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=%{buildroot}
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/ld.so.conf.d/
cat > $RPM_BUILD_ROOT/%{_sysconfdir}/ld.so.conf.d/%{name}.conf <<EOF
%{_libdir}
EOF
%define rubygems_default_dir %{_libdir}/ruby/%{ruby_lib_version}/rubygems/defaults
mkdir -p %{buildroot}/%{rubygems_default_dir}
cp %{SOURCE1} %{buildroot}/%{rubygems_default_dir}/operating_system.rb
%post
/sbin/ldconfig
%{rbenv_root}/bin/rbenv rehash
%postun -p /sbin/ldconfig
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%{_prefix}
%{_sysconfdir}/ld.so.conf.d/%{name}.conf
%doc README.md
%lang(ja) %doc README.ja.md
%doc ChangeLog
%doc doc/ChangeLog-*
%changelog
* Sat Jan 11 2015 墨泪<[email protected]> - 2.2.0
- initial import
%define _prefix /opt
Name: rbenv
Version: 1.1.0
Release: 6%{?dist}
Summary: rbenv is a tool for simple Ruby version management.
Group: System/Applications
License: MIT
URL: https://github.com/sstephenson/rbenv
Source0: rbenv-%{version}.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildArch: noarch
%description
Use rbenv to pick a Ruby version for your application and guarantee that your
development environment matches production. Put rbenv to work with Bundler
for painless Ruby upgrades and bulletproof deployments.
%package devel
Summary: Macros and development tools for packagin rbenv ruby versions
Group: System/Applications
License: MIT
Requires: %{name} = %{version}-%{release}
BuildArch: noarch
%description devel
Macros and development tools for packagin rbenv ruby versions
%prep
%setup -q
%build
:
%install
rm -rf $RPM_BUILD_ROOT
%define rbenv_root %{_prefix}/rbenv
mkdir -p $RPM_BUILD_ROOT/%{rbenv_root}
cp -r * $RPM_BUILD_ROOT/%{rbenv_root}
install -d -m0555 $RPM_BUILD_ROOT/%{rbenv_root}/shims
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/profile.d/
cat > $RPM_BUILD_ROOT/%{_sysconfdir}/profile.d/rbenv.sh <<'EOF'
pathadd() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="$1:${PATH:+"$PATH:"}"
fi
}
# rbenv setup
export RBENV_ROOT=%{rbenv_root}
pathadd %{rbenv_root}/bin
# if interactive
if [ -n "$PS1" ]; then
# if rbenv is not already a function
if ! type -t rbenv | grep -q function; then
eval "$(rbenv init -)"
fi
else
# non-interactive, just add shims path
pathadd %{rbenv_root}/shims
fi
export PATH
unset -f pathadd
EOF
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rpm
cat > $RPM_BUILD_ROOT/%{_sysconfdir}/rpm/macros.rbenv <<EOF
%%rbenv_root %{rbenv_root}
EOF
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%{_prefix}
%doc README.md LICENSE
%attr(0755,root,root) %dir %{rbenv_root}/shims
%attr(0755,root,root) %{_sysconfdir}/profile.d/rbenv.sh
%files devel
%{_sysconfdir}/rpm/macros.rbenv
%changelog
* Fri Jan 06 2017 ethan.erchinger<[email protected]> - 1.1.0
- upgrade to 1.1.0
* Sat Jan 11 2015 ruohan.chen<[email protected]> - 0.4.0
- initial import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment