-
Notifications
You must be signed in to change notification settings - Fork 112
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 #13 from ehelms/add-dockerfile
Fixes #4188: Add Pulp 3 container image built from PyPi
- Loading branch information
Showing
17 changed files
with
215 additions
and
1 deletion.
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
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 @@ | ||
#!/bin/bash | ||
|
||
cd containers | ||
|
||
ansible-playbook build.yaml |
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,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 |
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 @@ | ||
[defaults] | ||
retry_files_enabled = False | ||
transport = local | ||
nocows = 1 | ||
stdout_callback = yaml |
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,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 }}" |
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 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"] |
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,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" |
21 changes: 21 additions & 0 deletions
21
containers/images/pulp-api/container-assets/wait_on_database_migrations.sh
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 @@ | ||
#!/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
29
containers/images/pulp-api/container-assets/wait_on_postgres.py
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,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) |
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 @@ | ||
FROM pulp-api:latest | ||
|
||
COPY container-assets/pulp-content /usr/bin/pulp-content | ||
|
||
CMD ["/usr/bin/pulp-content"] |
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 @@ | ||
#!/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" |
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 @@ | ||
FROM pulp-api:latest | ||
|
||
COPY container-assets/pulp-resource-manager /usr/bin/pulp-resource-manager | ||
|
||
CMD ["/usr/bin/pulp-resource-manager"] |
6 changes: 6 additions & 0 deletions
6
containers/images/pulp-resource-manager/container-assets/pulp-resource-manager
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 @@ | ||
#!/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'" |
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 @@ | ||
FROM pulp-api:latest | ||
|
||
COPY container-assets/pulp-worker /usr/bin/pulp-worker | ||
|
||
CMD ["/usr/bin/pulp-worker"] |
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 @@ | ||
#!/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'" |
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,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 }}" |
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,10 @@ | ||
--- | ||
images: | ||
- pulp-api | ||
- pulp-content | ||
- pulp-worker | ||
- pulp-resource-manager | ||
registry: quay.io | ||
project: pulp | ||
tag: latest | ||
plugins: [] |