Skip to content

Commit

Permalink
Add Dockerfile that builds and packages ClusterRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
cmcginty committed Apr 5, 2018
1 parent 72ae67d commit 6491513
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.egg-info/

# .git/
.python-version
build_results/
dist/
test/

**/__pycache__
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Docker workflow for building and packaging ClusterRunner to an RPM.
#

# STAGE 1: Python-Manylinux (RHEL5) base with Python 3.4 enabled to create linux_x86_64 pex.
FROM quay.io/pypa/manylinux1_x86_64@sha256:1fc8ee3bc9d668222a519d84d8c3b3e2bbc3eabe4595a1661d7b037a038d2e87 AS stage1
ENV PATH="/opt/python/cp34-cp34m/bin:${PATH}"

WORKDIR /ClusterRunner

COPY Makefile *requirements.txt ./
RUN make init-dev wheels
COPY . .
RUN make dist/clusterrunner

# STAGE 2: CentOS 7 base w/ fpm to package pex into an rpm.
FROM cdrx/fpm-centos:7

WORKDIR /root
RUN yum install epel-release -y && yum install git python34 python34-pip -y
COPY . .
COPY --from=stage1 /ClusterRunner/dist/clusterrunner ./dist/
RUN ./setup.py --version
RUN make rpm
21 changes: 13 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
DISTDIR := ./dist
CR_BIN := $(DISTDIR)/clusterrunner
CR_CONF := ./conf/default_clusterrunner.conf
CR_UNK_VERSION := 0.0 # Default CR version when git repo is missing.

# Macro for printing a colored message to stdout
print_msg = @printf "\n\033[1;34m***%s***\033[0m\n" "$(1)"
Expand Down Expand Up @@ -77,6 +78,7 @@ PEX_ARGS := -v --no-pypi --cache-dir=$(WHEEL_CACHE) --cache-ttl=0

# TODO: Consider using "pip download --platform" when direct downloading of
# cross-platform wheels is supported.
.INTERMEDIATE: $(WHEEL_CACHE)
wheels $(WHEEL_CACHE): requirements.txt
$(call print_msg, Creating wheels cache... )
mkdir -p $(WHEEL_CACHE)
Expand All @@ -96,21 +98,24 @@ RPM_USER := jenkins
RPM_GROUP := engineering
RPM_PREINSTALL := conf/preinstall.rpm
# Auto-detect packaging info from python setup.py
RPM_DESCRIPTION = $(shell python ./setup.py --description 2>/dev/null)
RPM_LICENSE = $(shell python ./setup.py --license 2>/dev/null)
RPM_NAME = $(shell python ./setup.py --name 2>/dev/null)
RPM_URL = $(shell python ./setup.py --url 2>/dev/null)
RPM_VENDOR = $(shell python ./setup.py --contact 2>/dev/null)
RPM_VERSION = $(shell python ./setup.py --version 2>/dev/null)
RPM_DESCRIPTION = $(shell python3 ./setup.py --description 2>/dev/null)
RPM_LICENSE = $(shell python3 ./setup.py --license 2>/dev/null)
RPM_NAME = $(shell python3 ./setup.py --name 2>/dev/null)
RPM_URL = $(shell python3 ./setup.py --url 2>/dev/null)
RPM_VENDOR = $(shell python3 ./setup.py --contact 2>/dev/null)
RPM_VERSION = $(shell python3 ./setup.py --version 2>/dev/null)
# Collect all package info fields into fpm args
FPM_INFO_ARGS = --name $(RPM_NAME) --version $(RPM_VERSION) \
FPM_INFO_ARGS = --name "$(RPM_NAME)" --version "$(RPM_VERSION)" \
--license "$(RPM_LICENSE)" --description "$(RPM_DESCRIPTION)" \
--vendor "$(RPM_VENDOR)" --maintainer "$(RPM_VENDOR)" --url $(RPM_URL)
--vendor "$(RPM_VENDOR)" --maintainer "$(RPM_VENDOR)" --url "$(RPM_URL)"
# Expand all dependencies into fpm args
FPM_DEPEND_ARGS = $(addprefix --depends , $(RPM_DEPENDS))

.PHONY: rpm
rpm: $(CR_BIN)
ifeq ($(RPM_VERSION), $(CR_UNK_VERSION))
$(error Version cannot be $(CR_UNK_VERSION))
endif
rm -f $(DISTDIR)/*.rpm
fpm -s dir -t rpm $(FPM_INFO_ARGS) $(FPM_DEPEND_ARGS) \
--package $(DISTDIR) \
Expand Down
4 changes: 3 additions & 1 deletion app/util/autoversioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _calculate_source_version():
hash_extension = '' if head_commit_is_on_trunk else '-{}'.format(head_commit_hash[:7])
mod_extension = '' if not _repo_has_uncommited_changes() else '-mod'
return '{}.{}{}{}'.format(_MAJOR_MINOR_VERSION, commit_count, hash_extension, mod_extension)
except subprocess.CalledProcessError:
except (subprocess.CalledProcessError, FileNotFoundError):
return None


Expand Down Expand Up @@ -104,6 +104,7 @@ def _get_commit_hash_from_revision_param(revision_param):
:type revision_param: str
:rtype: str
:raises FileNotFoundError: if git command is not available.
"""
return _execute_local_git_command('rev-parse', '--verify', revision_param).strip()

Expand All @@ -117,6 +118,7 @@ def _execute_local_git_command(*args):
:type args: tuple
:return: The output of the git command
:rtype: str
:raises FileNotFoundError: if git command is not available.
"""
command_output = subprocess.check_output(
['git'] + list(args),
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ configobj==5.0.6
fysom==2.1.2
Logbook==0.7.0
prometheus_client==0.0.19
psutil==2.1.2
psutil==2.2.0
PyYAML==3.11
requests==2.3.0
termcolor==1.1.0
Expand Down

0 comments on commit 6491513

Please sign in to comment.