From 54727daa85d64d109affcc4bfbdf22defe5edc8f Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Sun, 8 Mar 2020 12:16:10 -0400 Subject: [PATCH] Upload container images This is an initial go at building this Python package and uploading an image for it. This will be followed up with some changes which will make it easier to execute with an entrypoint and environment variables later. Change-Id: Ie2219fc96f32554bde1cac37faa0b961dc53b95e --- .zuul.yaml | 60 ++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 31 ++++++++++++++++++++++ bindep.txt | 1 + lodgeit/application.py | 8 +++++- requirements.txt | 4 ++- setup.cfg | 12 +++++++++ setup.py | 20 ++++++++++++++ 7 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 bindep.txt create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.zuul.yaml b/.zuul.yaml index 87263da..694890d 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -1,11 +1,71 @@ +- secret: + name: lodgeit-opendev-dockerhub + data: + username: opendevzuul + password: !encrypted/pkcs1-oaep + - D6Z2bpBW0RSHMeqZP1PwjlJA8nLIac0BPKNMefelwHXeqD1w0pHTQ4W7MNvbmpmqxO0YG + vWOS5wxCuUJ37gELGfBRvWwvbnrfzhlh+nHqfZ2rh/8wYJuMV4HZOEnjJ5gHQSGldRW4g + +woxkkcJ/GzakyITAm/FhUiyMB6G3E6NLo8YDm/WTKsEtRmUtSbQMkGaZLfXY1QwCA9pN + 7lYLr6Pibd2PQzCQWq1CAr4BJGdc10r/LWxyWC4EphF4RxsKLWNEktkT+ZfP2K9+tNtrL + /nkwdc9IUjSqWFa8JUQy0GREghpOW7GgMthoqvADgpdxOoqIhyC4gpFfciC2jXbsMC0pV + 3kkCGQbv29LJ/gJ4QcqJHZ00OvI76XrE5CwQ7MFu+KIcTdoQtorIMOOx9ey/5UybJYlh9 + nHnZP6UwMPQuxkbdJhlwhUnGKXaiJWGs97gHWVwcrThT/IEEKfFata2/Wn4dXlSr6u4t/ + Xt34+eZOfqaGGdOjo/+U3IrxeMIM+KZl30/30vNBM95TxNxZ9JKR7XmOFwUWWxNc7LQng + soT47t74JaCpeUeX8otlpSKz9N+rFWkphrFai3qakKgqxpjyZ7k12veNhdrcqMLVrsOSI + EKTCnKphRQKSiMe0WjiaIvXNEGeIXMu6PlCIYvexzlrlUJJfc95Er+OlY7vvHg= + +- job: + name: lodgeit-build-opendev-image + parent: opendev-build-docker-image + description: Build OpenDev Docker images for LodgeIt + requires: + - python-base-container-image + - python-builder-container-image + provides: lodgeit-container-image + vars: &lodgeit_opendev_image_vars + zuul_work_dir: src/opendev.org/opendev/lodgeit + docker_images: + - context: . + repository: opendevorg/lodgeit + target: lodgeit + +- job: + name: lodgeit-upload-opendev-image + parent: opendev-upload-docker-image + description: Build OpenDev LodgeIt Docker images and upload to Docker Hub. + requires: + - python-base-container-image + - python-builder-container-image + provides: lodgeit-container-image + vars: *lodgeit_opendev_image_vars + secrets: + - name: docker_credentials + secret: lodgeit-opendev-dockerhub + pass-to-parent: true + +- job: + name: lodgeit-promote-opendev-image + parent: opendev-promote-docker-image + description: Promote previously uploaded LodgeIt Docker images. + vars: *lodgeit_opendev_image_vars + secrets: + - name: docker_credentials + secret: lodgeit-opendev-dockerhub + pass-to-parent: true + - project: check: jobs: - tox-pep8 - tox-py27 - tox-py36 + - lodgeit-build-opendev-image gate: jobs: - tox-pep8 - tox-py27 - tox-py36 + - lodgeit-upload-opendev-image + promote: + jobs: + - lodgeit-promote-opendev-image diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c6845d0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# Copyright (c) 2020 VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM opendevorg/python-builder as builder +COPY . /tmp/src +RUN assemble + +FROM opendevorg/python-base as lodgeit +COPY --from=builder /output/ /output +RUN /output/install-from-bindep + +USER nobody +EXPOSE 9000 +ENV LODGEIT_DBURI sqlite:////tmp/lodgeit.db +ENV LODGEIT_SECRET_KEY changeMe +CMD ["uwsgi", "--master", \ + "--processes", "4", \ + "--http-socket", "0.0.0.0:9000", \ + "--wsgi-file", "/usr/local/bin/lodgeit-wsgi"] diff --git a/bindep.txt b/bindep.txt new file mode 100644 index 0000000..5d1c22e --- /dev/null +++ b/bindep.txt @@ -0,0 +1 @@ +gcc [compile] diff --git a/lodgeit/application.py b/lodgeit/application.py index c4e932d..fcc3129 100644 --- a/lodgeit/application.py +++ b/lodgeit/application.py @@ -75,8 +75,14 @@ class LodgeIt(object): self.cleanup_callbacks) -def make_app(dburi, secret_key, debug=False, shell=False): +def make_app(dburi=None, secret_key=None, debug=False, shell=False): """Apply the used middlewares and create the application.""" + + if dburi is None: + dburi = os.getenv('LODGEIT_DBURI') + if secret_key is None: + secret_key = os.getenv('LODGEIT_SECRET_KEY') + static_path = os.path.join(os.path.dirname(__file__), 'static') app = LodgeIt(dburi, secret_key) if debug: diff --git a/requirements.txt b/requirements.txt index b0cf666..74e7964 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,9 +2,11 @@ six Jinja2 Werkzeug<0.16 Pygments -SQLAlchemy==0.9.7 +SQLAlchemy +PyMySQL simplejson Babel pillow pytz MarkupSafe +uwsgi diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..971f31d --- /dev/null +++ b/setup.cfg @@ -0,0 +1,12 @@ +[metadata] +name = lodgeit +description-file = + README +license = BSD +summary = LodgeIt implements a pastebin +author = OpenDev +author-email = openstack-infra@lists.openstack.org + +[entry_points] +wsgi_scripts = + lodgeit-wsgi = lodgeit.application:make_app diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4795395 --- /dev/null +++ b/setup.py @@ -0,0 +1,20 @@ +# Copyright (c) 2020 VEXXHOST, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import setuptools + +setuptools.setup( + setup_requires=['pbr>=2.0.0'], + pbr=True)