Skip to content

Commit 4a0752f

Browse files
authored
Merge pull request #201 from timvaillancourt/build_bin_docker
Build binary+rpm in Docker under the correct OS
2 parents d40d636 + 845cae5 commit 4a0752f

File tree

3 files changed

+97
-20
lines changed

3 files changed

+97
-20
lines changed

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
FROM centos:centos7
2-
ARG RELEASE
32
MAINTAINER Tim Vaillancourt <[email protected]>
3+
44
RUN yum install -y https://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-4.noarch.rpm epel-release && \
55
yum install -y Percona-Server-MongoDB-34-tools zbackup && yum clean all
6-
RUN curl -Lo /usr/bin/mongodb-consistent-backup https://github.com/Percona-Lab/mongodb_consistent_backup/releases/download/$RELEASE/mongodb-consistent-backup.el7.centos.x86_64 && \
7-
chmod +x /usr/bin/mongodb-consistent-backup
6+
7+
ADD build/rpm/RPMS/x86_64/mongodb_consistent_backup*.el*.centos.x86_64.rpm /
8+
RUN yum localinstall -y /mongodb_consistent_backup*.el*.centos.x86_64.rpm && \
9+
yum clean all && rm -f /mongodb_consistent_backup*.el*.centos.x86_64.rpm
10+
11+
USER mongodb_consistent_backup
812
ENTRYPOINT ["mongodb-consistent-backup"]
913
CMD ["--help"]

Makefile

Lines changed: 88 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
#
33

44
NAME=mongodb_consistent_backup
5+
BIN_NAME?=mongodb-consistent-backup
56
VERSION=$(shell cat VERSION | cut -d- -f1)
7+
GIT_COMMIT?=$(shell git show 2>/dev/null | awk 'NR==1{print $$2}')
68
PREFIX?=/usr/local
9+
ARCH?=x86_64
710
BASEDIR?=$(DESTDIR)$(PREFIX)
811
BINDIR?=$(BASEDIR)/bin
912
SHAREDIR?=$(BASEDIR)/share
1013
DOCKER_TAG?="$(NAME):$(VERSION)"
14+
DOCKER_BASE_IMAGE?=$(shell awk '/FROM/{print $$2}' Dockerfile)
15+
MAKE_DIR=$(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
1116

17+
all: bin/$(BIN_NAME)
1218

13-
all: bin/mongodb-consistent-backup
19+
bin/$(BIN_NAME): setup.py requirements.txt README.rst VERSION scripts/build.sh $(NAME)/*.py $(NAME)/*/*.py $(NAME)/*/*/*.py
20+
BIN_NAME=$(BIN_NAME) GIT_COMMIT=$(GIT_COMMIT) PYTHON_BIN=$(PYTHON_BIN) VIRTUALENV_BIN=$(VIRTUALENV_BIN) bash scripts/build.sh
1421

15-
bin/mongodb-consistent-backup: setup.py requirements.txt README.rst VERSION scripts/build.sh $(NAME)/*.py $(NAME)/*/*.py $(NAME)/*/*/*.py
16-
PYTHON_BIN=$(PYTHON_BIN) VIRTUALENV_BIN=$(VIRTUALENV_BIN) bash scripts/build.sh
17-
18-
install: bin/mongodb-consistent-backup
22+
install: bin/$(BIN_NAME)
1923
mkdir -p $(BINDIR) $(SHAREDIR)/$(NAME) || true
20-
install -m 0755 bin/mongodb-consistent-backup $(BINDIR)/mongodb-consistent-backup
24+
install -m 0755 bin/$(BIN_NAME) $(BINDIR)/mongodb-consistent-backup
2125
install -m 0644 conf/mongodb-consistent-backup.example.conf $(SHAREDIR)/$(NAME)/example.conf
2226
install -m 0644 LICENSE $(SHAREDIR)/$(NAME)/LICENSE
2327
install -m 0644 README.rst $(SHAREDIR)/$(NAME)/README.rst
@@ -26,21 +30,90 @@ flake8:
2630
# Ignore long-lines and space-aligned = and : for now
2731
flake8 --ignore E221,E241,E501 $(PWD)/$(NAME)
2832

33+
rpm: bin/$(BIN_NAME)
34+
mkdir -p $(MAKE_DIR)/build/rpm/SOURCES
35+
cp -f $(MAKE_DIR)/{LICENSE,README.rst} build/rpm/SOURCES
36+
cp -f $(MAKE_DIR)/bin/$(BIN_NAME) build/rpm/SOURCES/mongodb-consistent-backup
37+
cp -f $(MAKE_DIR)/conf/mongodb-consistent-backup.example.conf build/rpm/SOURCES/mongodb-consistent-backup.conf
38+
rpmbuild -D "_topdir $(MAKE_DIR)/build/rpm" -D "version $(VERSION)" -bb $(MAKE_DIR)/scripts/$(NAME).spec
39+
2940
uninstall:
3041
rm -f $(BINDIR)/mongodb-consistent-backup
3142
rm -rf $(SHAREDIR)/$(NAME)
3243

33-
rpm: bin/mongodb-consistent-backup
34-
rm -rf build/rpm 2>/dev/null || true
35-
mkdir -p build/rpm/SOURCES
36-
cp -f $(PWD)/{LICENSE,README.rst} build/rpm/SOURCES
37-
cp -f $(PWD)/bin/mongodb-consistent-backup build/rpm/SOURCES/mongodb-consistent-backup
38-
cp -f $(PWD)/conf/mongodb-consistent-backup.example.conf build/rpm/SOURCES/mongodb-consistent-backup.conf
39-
rpmbuild -D "_topdir $(PWD)/build/rpm" -D "version $(VERSION)" -bb scripts/$(NAME).spec
44+
# Build CentOS7 RPM (in Docker)
45+
build/rpm/RPMS/$(ARCH)/$(NAME)-$(VERSION)-1.el7.centos.$(ARCH).rpm:
46+
mkdir -p $(MAKE_DIR)/build/rpm/RPMS/$(ARCH)
47+
docker run --rm \
48+
-v "$(MAKE_DIR)/bin:/src/bin:Z" \
49+
-v "$(MAKE_DIR)/conf:/src/conf:Z" \
50+
-v "$(MAKE_DIR)/mongodb_consistent_backup:/src/mongodb_consistent_backup:Z" \
51+
-v "$(MAKE_DIR)/scripts:/src/scripts:Z" \
52+
-v "$(MAKE_DIR)/tmp/pip:/src/tmp/pip:Z" \
53+
-v "$(MAKE_DIR)/setup.py:/src/setup.py:Z" \
54+
-v "$(MAKE_DIR)/requirements.txt:/src/requirements.txt:Z" \
55+
-v "$(MAKE_DIR)/Makefile:/src/Makefile:Z" \
56+
-v "$(MAKE_DIR)/README.rst:/src/README.rst:Z" \
57+
-v "$(MAKE_DIR)/LICENSE:/src/LICENSE:Z" \
58+
-v "$(MAKE_DIR)/VERSION:/src/VERSION:Z" \
59+
-v "$(MAKE_DIR)/build/rpm/RPMS/$(ARCH):/src/build/rpm/RPMS/$(ARCH):Z" \
60+
-it centos:centos7 \
61+
/bin/bash -c "yum install -y python-devel python-virtualenv gcc make libffi-devel openssl-devel rpm-build && \
62+
make -C /src GIT_COMMIT=$(GIT_COMMIT) BIN_NAME=mongodb-consistent-backup.el7.centos.$(ARCH) rpm && \
63+
/src/bin/mongodb-consistent-backup.el7.centos.$(ARCH) --version"
64+
65+
centos7: build/rpm/RPMS/$(ARCH)/$(NAME)-$(VERSION)-1.el7.centos.$(ARCH).rpm
66+
67+
# Build Debian8 Binary (in Docker - .deb package soon!)
68+
bin/mongodb-consistent-backup.debian8.$(ARCH):
69+
docker run --rm \
70+
-v "$(MAKE_DIR)/bin:/src/bin:Z" \
71+
-v "$(MAKE_DIR)/conf:/src/conf:Z" \
72+
-v "$(MAKE_DIR)/mongodb_consistent_backup:/src/mongodb_consistent_backup:Z" \
73+
-v "$(MAKE_DIR)/scripts:/src/scripts:Z" \
74+
-v "$(MAKE_DIR)/tmp/pip:/src/tmp/pip:Z" \
75+
-v "$(MAKE_DIR)/setup.py:/src/setup.py:Z" \
76+
-v "$(MAKE_DIR)/requirements.txt:/src/requirements.txt:Z" \
77+
-v "$(MAKE_DIR)/Makefile:/src/Makefile:Z" \
78+
-v "$(MAKE_DIR)/README.rst:/src/README.rst:Z" \
79+
-v "$(MAKE_DIR)/LICENSE:/src/LICENSE:Z" \
80+
-v "$(MAKE_DIR)/VERSION:/src/VERSION:Z" \
81+
-it debian:jessie \
82+
/bin/bash -c "apt-get update && apt-get install -y python2.7-minimal python2.7-dev python-virtualenv gcc make libffi-dev libssl-dev && \
83+
make -C /src GIT_COMMIT=$(GIT_COMMIT) BIN_NAME=mongodb-consistent-backup.debian8.$(ARCH).tmp && \
84+
mv -vf /src/bin/mongodb-consistent-backup.debian8.$(ARCH).tmp /src/bin/mongodb-consistent-backup.debian8.$(ARCH) && \
85+
/src/bin/mongodb-consistent-backup.debian8.$(ARCH) --version"
4086

41-
docker: bin/mongodb-consistent-backup
42-
docker build --no-cache --tag $(DOCKER_TAG) --build-arg "RELEASE=$(VERSION)" .
87+
debian8: bin/mongodb-consistent-backup.debian8.$(ARCH)
88+
89+
# Build Debian9 Binary (in Docker - .deb package soon!)
90+
bin/mongodb-consistent-backup.debian9.$(ARCH):
91+
docker run --rm \
92+
-v "$(MAKE_DIR)/bin:/src/bin:Z" \
93+
-v "$(MAKE_DIR)/conf:/src/conf:Z" \
94+
-v "$(MAKE_DIR)/mongodb_consistent_backup:/src/mongodb_consistent_backup:Z" \
95+
-v "$(MAKE_DIR)/scripts:/src/scripts:Z" \
96+
-v "$(MAKE_DIR)/tmp/pip:/src/tmp/pip:Z" \
97+
-v "$(MAKE_DIR)/setup.py:/src/setup.py:Z" \
98+
-v "$(MAKE_DIR)/requirements.txt:/src/requirements.txt:Z" \
99+
-v "$(MAKE_DIR)/Makefile:/src/Makefile:Z" \
100+
-v "$(MAKE_DIR)/README.rst:/src/README.rst:Z" \
101+
-v "$(MAKE_DIR)/LICENSE:/src/LICENSE:Z" \
102+
-v "$(MAKE_DIR)/VERSION:/src/VERSION:Z" \
103+
-it debian:stretch \
104+
/bin/bash -c "apt-get update && apt-get install -y python2.7-minimal python2.7-dev python-virtualenv gcc make libffi-dev libssl-dev && \
105+
make -C /src GIT_COMMIT=$(GIT_COMMIT) BIN_NAME=mongodb-consistent-backup.debian9.$(ARCH).tmp && \
106+
mv -vf /src/bin/mongodb-consistent-backup.debian9.$(ARCH).tmp /src/bin/mongodb-consistent-backup.debian9.$(ARCH) && \
107+
/src/bin/mongodb-consistent-backup.debian9.$(ARCH) --version"
108+
109+
debian9: bin/mongodb-consistent-backup.debian9.$(ARCH)
110+
111+
docker: build/rpm/RPMS/$(ARCH)/$(NAME)-$(VERSION)-1.el7.centos.$(ARCH).rpm
112+
docker build --no-cache --tag $(DOCKER_TAG) .
43113
docker tag $(DOCKER_TAG) $(NAME):latest
114+
docker run --rm -it $(DOCKER_TAG) --version
115+
116+
release: centos7 debian8 debian9 docker
44117

45118
clean:
46119
rm -rf bin build $(NAME).egg-info tmp 2>/dev/null

scripts/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -x
44

5-
name=mongodb-consistent-backup
5+
name=${BIN_NAME:-mongodb-consistent-backup}
66
mod_name=mongodb_consistent_backup
77
rootdir=$(readlink -f $(dirname $0)/..)
88
srcdir=${rootdir}/${mod_name}
@@ -15,6 +15,7 @@ venvdir=${builddir}/venv
1515
output_file=${bindir}/${name}
1616
require_file=${builddir}/requirements.txt
1717
version_file=${builddir}/VERSION
18+
git_commit=${GIT_COMMIT:-unknown}
1819

1920
python_bin=${PYTHON_BIN}
2021
if [ -z "$python_bin" ]; then
@@ -73,7 +74,6 @@ if [ -d ${srcdir} ]; then
7374
exit 1
7475
fi
7576

76-
git_commit=$(git show 2>/dev/null | awk 'NR==1{print $2}')
7777
if [ -z "$git_commit" ]; then
7878
echo "Warning: cannot find git commit hash!"
7979
else

0 commit comments

Comments
 (0)