-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Packaging: Introducing RPM packaging
- Loading branch information
Showing
10 changed files
with
278 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
PYTHON ?= python | ||
ifeq ($(origin VIRTUAL_ENV), undefined) | ||
DIST_PYTHON ?= poetry run $(PYTHON) | ||
else | ||
DIST_PYTHON ?= $(PYTHON) | ||
endif | ||
|
||
NAME = ansible-builder | ||
IMAGE_NAME ?= $(NAME) | ||
PIP_NAME = ansible_builder | ||
LONG_VERSION := $(shell poetry version) | ||
VERSION := $(filter-out $(NAME), $(LONG_VERSION)) | ||
ifeq ($(OFFICIAL),yes) | ||
RELEASE ?= 1 | ||
else | ||
ifeq ($(origin RELEASE), undefined) | ||
RELEASE := 0.git$(shell date -u +%Y%m%d%H).$(shell git rev-parse --short HEAD) | ||
endif | ||
endif | ||
|
||
# RPM build variables | ||
MOCK_BIN ?= mock | ||
MOCK_CONFIG ?= epel-7-x86_64 | ||
|
||
RPM_NVR = $(NAME)-$(VERSION)-$(RELEASE)$(RPM_DIST) | ||
RPM_DIST ?= $(shell rpm --eval '%{?dist}' 2>/dev/null) | ||
RPM_ARCH ?= $(shell rpm --eval '%{_arch}' 2>/dev/null) | ||
|
||
# Provide a fallback value for RPM_ARCH | ||
ifeq ($(RPM_ARCH),) | ||
RPM_ARCH = $(shell uname -m) | ||
endif | ||
|
||
.PHONY: clean dist sdist dev shell rpm srpm docs | ||
|
||
clean: | ||
rm -rf dist | ||
rm -rf build | ||
rm -rf ansible-builder.egg-info | ||
rm -rf rpm-build | ||
find . -type f -regex ".*\py[co]$$" -delete | ||
|
||
dist: | ||
poetry build | ||
|
||
sdist: dist/$(NAME)-$(VERSION).tar.gz | ||
|
||
# Generate setup.py transiently for the sdist so we don't have to deal with | ||
# packaging poetry as a RPM for rpm build time dependencies. | ||
dist/$(NAME)-$(VERSION).tar.gz: | ||
dephell deps convert --from=pyproject.toml --to=setup.py | ||
$(DIST_PYTHON) setup.py sdist | ||
|
||
dev: | ||
poetry install | ||
|
||
shell: | ||
poetry shell | ||
|
||
test: | ||
tox | ||
|
||
docs: | ||
cd docs && make html | ||
|
||
rpm: | ||
MOCK_CONFIG=$(MOCK_CONFIG) docker-compose -f packaging/rpm/docker-compose.yml build | ||
MOCK_CONFIG=$(MOCK_CONFIG) docker-compose -f packaging/rpm/docker-compose.yml \ | ||
run --rm -e RELEASE=$(RELEASE) rpm-builder "make mock-rpm" | ||
|
||
srpm: | ||
MOCK_CONFIG=$(MOCK_CONFIG) docker-compose -f packaging/rpm/docker-compose.yml build | ||
MOCK_CONFIG=$(MOCK_CONFIG) docker-compose -f packaging/rpm/docker-compose.yml \ | ||
run --rm -e RELEASE=$(RELEASE) rpm-builder "make mock-srpm" | ||
|
||
mock-rpm: rpm-build/$(RPM_NVR).$(RPM_ARCH).rpm | ||
|
||
rpm-build/$(RPM_NVR).$(RPM_ARCH).rpm: rpm-build/$(RPM_NVR).src.rpm | ||
$(MOCK_BIN) -r $(MOCK_CONFIG) --arch=noarch \ | ||
--resultdir=rpm-build \ | ||
--rebuild rpm-build/$(RPM_NVR).src.rpm | ||
|
||
mock-srpm: rpm-build/$(RPM_NVR).src.rpm | ||
|
||
rpm-build/$(RPM_NVR).src.rpm: dist/$(NAME)-$(VERSION).tar.gz rpm-build rpm-build/$(NAME).spec | ||
$(MOCK_BIN) -r $(MOCK_CONFIG) --arch=noarch \ | ||
--resultdir=rpm-build \ | ||
--spec=rpm-build/$(NAME).spec \ | ||
--sources=rpm-build \ | ||
--buildsrpm | ||
|
||
rpm-build/$(NAME).spec: | ||
ansible -c local -i localhost, all \ | ||
-m template \ | ||
-a "src=packaging/rpm/$(NAME).spec.j2 dest=rpm-build/$(NAME).spec" \ | ||
-e version=$(VERSION) \ | ||
-e release=$(RELEASE) | ||
|
||
rpm-build: sdist | ||
mkdir -p $@ | ||
cp dist/$(NAME)-$(VERSION).tar.gz rpm-build/$(NAME)-$(VERSION)-$(RELEASE).tar.gz | ||
|
||
print-%: | ||
@echo $($*) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM centos:7 | ||
|
||
RUN yum install -y epel-release | ||
RUN yum install -y make mock python3 which git gcc python3-devel | ||
|
||
# Fix output of rpm --eval '%{?dist}' | ||
RUN sed -i "s/.el7.centos/.el7/g" /etc/rpm/macros.dist | ||
|
||
RUN pip3 install -IU poetry ansible dephell[full] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM centos:8 | ||
|
||
RUN dnf install -y epel-release | ||
RUN yum install -y make mock python3-pip which git gcc python3-devel | ||
|
||
RUN pip3 install -IU poetry ansible dephell[full] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
%global pypi_name ansible-builder | ||
|
||
Name: %{pypi_name} | ||
Version: {{ version }} | ||
Release: {{ release }}%{?dist} | ||
Summary: An Ansible execution environment builder | ||
|
||
License: ASL 2.0 | ||
URL: https://github.com/ansible/ansible-builder | ||
Source0: https://github.com/ansible/%{name}/archive/%{version}.tar.gz?/%{name}-%{version}-{{ release }}.tar.gz | ||
BuildArch: noarch | ||
|
||
BuildRequires: python3 | ||
BuildRequires: python3-setuptools | ||
BuildRequires: python3-rpm-macros | ||
|
||
|
||
%if 0%{?fedora} || 0%{?rhel} > 7 | ||
Requires: python3-pyyaml | ||
%else | ||
Requires: python36-PyYAML | ||
%endif | ||
|
||
%description | ||
An Ansible execution environment builder | ||
|
||
%prep | ||
%autosetup -n %{pypi_name}-%{version} | ||
|
||
%build | ||
%py3_build | ||
|
||
%install | ||
%py3_install | ||
|
||
%files | ||
%defattr(-,root,root) | ||
|
||
%files | ||
%{python3_sitelib}/* | ||
%{_bindir}/ansible-builder | ||
|
||
%changelog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
version: '3' | ||
services: | ||
rpm-builder: | ||
build: | ||
dockerfile: Dockerfile.${MOCK_CONFIG} | ||
context: . | ||
image: builder-rpm-builder:${MOCK_CONFIG} | ||
environment: | ||
MOCK_BIN: "mock --old-chroot" | ||
MOCK_CONFIG: | ||
RELEASE: | ||
OFFICIAL: | ||
volumes: | ||
- ../../:/ansible-builder | ||
- mock-cache:/var/cache/mock | ||
entrypoint: ["/bin/bash", "-c"] | ||
working_dir: /ansible-builder | ||
privileged: true | ||
volumes: | ||
mock-cache: |
Oops, something went wrong.