-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from freedomofpress/RPMBuilder
Adds rpm buider container.. swaps out build scripts
- Loading branch information
Showing
11 changed files
with
197 additions
and
55 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,12 @@ | ||
[[source]] | ||
url = "https://pypi.python.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[dev-packages] | ||
|
||
[packages] | ||
PyYAML = "*" | ||
|
||
[requires] | ||
python_version = "3" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,101 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Builds docker images using specs from folders and metadata config files. | ||
""" | ||
|
||
import argparse | ||
import os | ||
import shlex | ||
import subprocess | ||
import yaml | ||
|
||
|
||
CUR_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
def get_container_names(dir_name=CUR_DIRECTORY): | ||
""" | ||
Get me a list of sub-directories that contain a meta.yml. | ||
Assume these are container names we are interested in | ||
""" | ||
containers = [] | ||
|
||
for dir in os.listdir(dir_name): | ||
try: | ||
if ('meta.yml' in os.listdir(dir) and | ||
'Dockerfile' in os.listdir(dir)): | ||
containers.append(dir) | ||
except NotADirectoryError: | ||
continue | ||
|
||
return containers | ||
|
||
|
||
def extract_metadata(rootdir): | ||
""" Provide root directory of container files, reads that folders meta.yml, and returns the yaml object """ | ||
with open(os.path.join(rootdir, 'meta.yml'), 'r') as f: | ||
return yaml.load(f.read()) | ||
|
||
|
||
def run_command(command): | ||
""" | ||
Takes in a string command, runs said command as a subprocess, print to stdout live | ||
Taken from https://www.endpoint.com/blog/2015/01/28/getting-realtime-output-using-python | ||
""" | ||
process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE) | ||
|
||
while True: | ||
output = process.stdout.readline().decode() | ||
if output == '' and process.poll() is not None: | ||
break | ||
if output: | ||
print(output.strip()) | ||
rc = process.poll() | ||
return rc | ||
|
||
|
||
def build(image_name, dir=CUR_DIRECTORY): | ||
""" | ||
Build docker image. | ||
Assumes there is a dir structure of ./<container_name_dir>/ | ||
With at least `meta.yml` and `Dockerfile` within that folder. | ||
""" | ||
container_dir = os.path.join(dir, image_name) | ||
|
||
meta_data = extract_metadata(container_dir) | ||
|
||
# If build args exist in metadata. lets pull em out! | ||
try: | ||
opt_args = "" | ||
for build_arg in meta_data['args']: | ||
opt_args += "--build-arg={}={} ".format( | ||
build_arg, | ||
meta_data['args'][build_arg]) | ||
except KeyError: | ||
pass | ||
|
||
# Build docker command | ||
docker_cmd = ("docker build {opt} -t {tag}" | ||
" -f {dockerfile} {context}").format( | ||
opt=opt_args, | ||
tag=':'.join([meta_data['repo'], meta_data['tag']]), | ||
dockerfile=os.path.join(container_dir, 'Dockerfile'), | ||
context=container_dir) | ||
|
||
print("Running '{}'".format(docker_cmd)) | ||
run_command(docker_cmd) | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(description=__doc__) | ||
# Basically a folder that has a meta.yml and a Dockerfile | ||
parser.add_argument('container', | ||
type=str, | ||
help='container to build', | ||
choices=get_container_names()) | ||
|
||
args = parser.parse_args() | ||
|
||
build(args.container) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
FROM fedora:25 | ||
LABEL maintainer="Freedom of the Press Foundation" | ||
LABEL description="RedHat tooling for building RPMs" | ||
ARG FEDORA_PKGR_VER | ||
|
||
|
||
RUN echo "${FEDORA_PKGR_VER}" | ||
|
||
RUN dnf update -y && \ | ||
dnf install -y \ | ||
fedora-packager-${FEDORA_PKGR_VER}.noarch \ | ||
make \ | ||
python3-cryptography \ | ||
python3-devel \ | ||
python3-requests \ | ||
python3-setuptools \ | ||
vim && \ | ||
yum clean all | ||
|
||
ENV HOME /home/user | ||
RUN useradd --create-home --home-dir $HOME user \ | ||
&& chown -R user:user $HOME && \ | ||
su -c rpmdev-setuptree user | ||
|
||
WORKDIR $HOME/rpmbuild | ||
VOLUME $HOME/rpmbuild | ||
|
||
USER user | ||
|
||
CMD ["/usr/bin/bash"] |
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,5 @@ | ||
--- | ||
repo: "quay.io/freedomofpress/rpmbuilder" | ||
tag: "0.6.0.1-1.fc25" | ||
args: | ||
FEDORA_PKGR_VER: 0.6.0.1-1.fc25 |