Skip to content

Commit

Permalink
Merge pull request #13 from ehelms/add-dockerfile
Browse files Browse the repository at this point in the history
Fixes #4188: Add Pulp 3 container image built from PyPi
  • Loading branch information
bmbouter committed Apr 17, 2019
2 parents 73b9788 + 764dfc3 commit 7012b62
Show file tree
Hide file tree
Showing 17 changed files with 215 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ addons:
before_install: .travis/before_install.sh
install: .travis/install.sh
before_script: .travis/before_script.sh
script: .travis/script.sh
script:
- .travis/script.sh
- .travis/test-container-images.sh
jobs:
include:
- stage: deploy
Expand Down
5 changes: 5 additions & 0 deletions .travis/test-container-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

cd containers

ansible-playbook build.yaml
23 changes: 23 additions & 0 deletions containers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Pulp 3 Containers

This directory contains assets and tooling for building Pulp 3 container images. The current image is an all-in-one image with different runtime scripts to assume each of the roles: pulp-core, pulp-worker and pulp-resource-manager.

## Build

The base image can be built with the help of an Ansible script. To build the base image:

ansible-playbook build.yaml

The image can be customized to include any number of plugins as a build argument:

ansible-playbook build.yaml -e '{"plugins": ["pulp_file", "pulp_ansible"]}'

## Push Image to Registry

The built image can be pushed to a registry using an Ansible playbook. The default configuration will attempt to push the image to `quay.io/pulp`:

ansible-playbook push.yaml

The image can be pushed to custom registry by specifying variables via the command line:

ansible-playbook push.yaml -e registry=docker.io -e project=myproject
5 changes: 5 additions & 0 deletions containers/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[defaults]
retry_files_enabled = False
transport = local
nocows = 1
stdout_callback = yaml
26 changes: 26 additions & 0 deletions containers/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- hosts: localhost
gather_facts: no
vars:
container_cli: 'docker'
vars_files:
- vars/defaults.yaml
tasks:
- name: 'Check for podman'
command: 'which podman'
register: podman_exists
ignore_errors: true

- set_fact:
container_cli: 'podman'
when: podman_exists | success

- name: 'Build images'
command: "{{ container_cli }} build --network host --no-cache --build-arg VERSION={{ tag }} --build-arg PLUGINS=\"{{ plugins | join(' ') }}\" -t {{ item }}:{{ tag }} ."
args:
chdir: "images/{{ item }}"
with_items: "{{ images }}"

- name: 'Tag images'
command: "{{ container_cli }} tag {{ item }}:{{ tag }} {{ registry }}/{{ project }}/{{ item }}:{{ tag }}"
with_items: "{{ images }}"
30 changes: 30 additions & 0 deletions containers/images/pulp-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM centos:7

ARG PLUGINS=""

RUN echo "tsflags=nodocs" >> /etc/yum.conf && \
yum -y install epel-release centos-release-scl && \
yum -y install wget git rh-python36-python-pip && \
yum clean all

ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
ENV PYTHONUNBUFFERED=0
ENV DJANGO_SETTINGS_MODULE=pulpcore.app.settings

RUN mkdir -p /etc/pulp

RUN scl enable rh-python36 'pip install gunicorn'
RUN scl enable rh-python36 'pip install pulpcore'
RUN scl enable rh-python36 'pip install pulpcore-plugin pulpcore[postgres] pulpcore[mysql]'
RUN scl enable rh-python36 'pip install $PLUGINS'

RUN scl enable rh-python36 "django-admin collectstatic --noinput"

COPY container-assets/wait_on_postgres.py /usr/bin/wait_on_postgres.py
COPY container-assets/wait_on_database_migrations.sh /usr/bin/wait_on_database_migrations.sh
COPY container-assets/pulp-api /usr/bin/pulp-api


CMD ["/usr/bin/pulp-api"]
7 changes: 7 additions & 0 deletions containers/images/pulp-api/container-assets/pulp-api
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

/usr/bin/wait_on_postgres.py

scl enable rh-python36 'django-admin migrate --noinput'

exec scl enable rh-python36 "gunicorn -b 0.0.0.0:8000 pulpcore.app.wsgi:application"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

database_migrated=false

echo "Checking for database migrations"
while [ $database_migrated = false ]; do
scl enable rh-python36 "pulp-manager showmigrations | grep '\[ \]'"
if [ $? -gt 0 ]; then
echo "Database migrated!"
database_migrated=true
else
sleep 5
fi
done

if [ $database_migrated = false ]; then
echo "Database not migrated in time, exiting"
exit 1
else
exit 0
fi
29 changes: 29 additions & 0 deletions containers/images/pulp-api/container-assets/wait_on_postgres.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python

import sys
import socket
import time
import os

if __name__ == '__main__':

postgres_is_alive = False
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tries = 0
print("Waiting on postgresql to start...")
while not postgres_is_alive and tries < 100:
tries += 1
try:
print("Checking postgres host %s" % os.environ['POSTGRES_SERVICE_HOST'])
s.connect((os.environ['POSTGRES_SERVICE_HOST'], 5432))
except socket.error:
time.sleep(3)
else:
postgres_is_alive = True

if postgres_is_alive:
print("Postgres started!")
sys.exit(0)
else:
print("Unable to reach postgres on port 5432")
sys.exit(1)
5 changes: 5 additions & 0 deletions containers/images/pulp-content/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM pulp-api:latest

COPY container-assets/pulp-content /usr/bin/pulp-content

CMD ["/usr/bin/pulp-content"]
6 changes: 6 additions & 0 deletions containers/images/pulp-content/container-assets/pulp-content
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

/usr/bin/wait_on_postgres.py
/usr/bin/wait_on_database_migrations.sh

exec scl enable rh-python36 "gunicorn -b 0.0.0.0:8000 pulpcore.content:server"
5 changes: 5 additions & 0 deletions containers/images/pulp-resource-manager/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM pulp-api:latest

COPY container-assets/pulp-resource-manager /usr/bin/pulp-resource-manager

CMD ["/usr/bin/pulp-resource-manager"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

/usr/bin/wait_on_postgres.py
/usr/bin/wait_on_database_migrations.sh

exec scl enable rh-python36 "rq worker --url 'redis://$REDIS_SERVICE_HOST:$REDIS_SERVICE_PORT' -n resource_manager@%h -w 'pulpcore.tasking.worker.PulpWorker'"
5 changes: 5 additions & 0 deletions containers/images/pulp-worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM pulp-api:latest

COPY container-assets/pulp-worker /usr/bin/pulp-worker

CMD ["/usr/bin/pulp-worker"]
6 changes: 6 additions & 0 deletions containers/images/pulp-worker/container-assets/pulp-worker
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

/usr/bin/wait_on_postgres.py
/usr/bin/wait_on_database_migrations.sh

exec scl enable rh-python36 "rq worker --url 'redis://${REDIS_SERVICE_HOST}:${REDIS_SERVICE_PORT}' -n reserved_resource_worker_${PULP_WORKER_NUMBER}@${HOSTNAME} -w 'pulpcore.tasking.worker.PulpWorker'"
23 changes: 23 additions & 0 deletions containers/push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- hosts: localhost
vars:
container_cli: 'docker'
vars_files:
- vars/defaults.yaml
tasks:
- name: 'Check for podman'
command: 'which podman'
register: podman_exists
ignore_errors: true

- set_fact:
container_cli: 'podman'
when: podman_exists | success

- name: 'Tag images'
command: "{{ container_cli }} tag {{ item }}:{{ tag }} {{ registry }}/{{ project }}/{{ item }}:{{ tag }}"
with_items: "{{ images }}"

- name: 'Push images'
command: "{{ container_cli }} push {{ registry }}/{{ project }}/{{ item }}:{{ tag }}"
with_items: "{{ images }}"
10 changes: 10 additions & 0 deletions containers/vars/defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
images:
- pulp-api
- pulp-content
- pulp-worker
- pulp-resource-manager
registry: quay.io
project: pulp
tag: latest
plugins: []

0 comments on commit 7012b62

Please sign in to comment.