Skip to content

Commit

Permalink
Use poetry to manage dependencies
Browse files Browse the repository at this point in the history
Drops spec file and setup.py.
  • Loading branch information
hluk committed Sep 1, 2022
1 parent b7f9530 commit 095b925
Show file tree
Hide file tree
Showing 12 changed files with 1,740 additions and 354 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/resultsdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry tox tox-gh-actions
pip install poetry 'tox-docker>=4.0.0a2' 'tox>=4.0.0b2'
- name: Test with tox
run: tox -e py
run: tox

- name: Run coveralls-python
env:
Expand Down Expand Up @@ -86,15 +86,37 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry podman-compose
- name: Update the Application Version
run: poetry version "$(./get-version.sh)"

- name: Get image tag from git branch
id: get-image-tag
run: |
export TAG=$(sed 's/[^0-9a-zA-Z_.-]/__/g' <<< "$GITHUB_REF_NAME") &&
echo "::set-output name=tag::$TAG"
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.IMAGE_NAME }}
tags: >-
${{ steps.get-image-tag.outputs.tag }}
${{ github.ref == 'refs/heads/develop' && 'latest' || '' }}
${{ github.sha }}
containerfiles: Dockerfile
build-args: |
GITHUB_SHA=${{ github.sha }}
- name: Log in to the image registry
if: github.event_name == 'push' && github.actor != 'dependabot[bot]'
Expand Down
2 changes: 0 additions & 2 deletions .s2i/environment

This file was deleted.

127 changes: 82 additions & 45 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,59 +1,96 @@
# This will produce an image to be used in Openshift
# Build should be triggered from repo root like:
# docker build -f openshift/Dockerfile \
# --tag <IMAGE_TAG>
FROM registry.access.redhat.com/ubi8/ubi:8.5 as builder

FROM registry.fedoraproject.org/fedora:35
LABEL \
name="ResultsDB application" \
vendor="ResultsDB developers" \
license="GPLv2+" \
description="ResultsDB is a results store engine for, but not limited to, Fedora QA tools." \
usage="https://pagure.io/taskotron/resultsdb/blob/develop/f/openshift/README.md" \
build-date=""

USER root
COPY ./resultsdb.spec /opt/app-root/src/resultsdb/resultsdb.spec

# install dependencies defined in RPM spec file
RUN dnf -y install \
findutils \
# hadolint ignore=DL3033,DL4006,SC2039,SC3040
RUN set -exo pipefail \
&& mkdir -p /mnt/rootfs \
# install builder dependencies
&& yum install -y \
--setopt install_weak_deps=false \
--nodocs \
python39 \
# install runtime dependencies
&& yum install -y \
--installroot=/mnt/rootfs \
--releasever=8 \
--setopt install_weak_deps=false \
--nodocs \
httpd \
mod_ssl \
python3-mod_wsgi \
python3-pip \
python3-psycopg2 \
python3-stomppy \
rpm-build \
&& rpm --query --requires --specfile /opt/app-root/src/resultsdb/resultsdb.spec | xargs -d '\n' dnf -y install
python39 \
python39-mod_wsgi \
&& yum --installroot=/mnt/rootfs clean all \
&& rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* \
# https://python-poetry.org/docs/master/#installing-with-the-official-installer
&& curl -sSL https://install.python-poetry.org | python3 - \
&& python3 -m venv --system-site-packages /venv \
# compatibility with previous images
&& ln -s mod_wsgi-express-3.9 /mnt/rootfs/usr/bin/mod_wsgi-express-3

COPY . /opt/app-root/src/resultsdb/
# install using --no-deps option to ensure nothing comes from PyPi
RUN pip3 install --no-deps /opt/app-root/src/resultsdb
ENV \
PIP_DEFAULT_TIMEOUT=100 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1 \
PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
PYTHONUNBUFFERED=1

WORKDIR /build
COPY . .

# hadolint ignore=SC1091
RUN set -ex \
&& export PATH=/root/.local/bin:$PATH \
&& . /venv/bin/activate \
&& pip install --no-cache-dir -r requirements.txt \
&& poetry build --format=wheel \
&& version=$(poetry version --short) \
&& pip install --no-cache-dir dist/resultsdb-"$version"-py3*.whl \
&& deactivate \
&& mv /venv /mnt/rootfs \
&& mkdir -p /mnt/rootfs/app \
&& cp -v entrypoint.sh /mnt/rootfs/app

# fix apache config for container use
RUN sed -i 's#^WSGISocketPrefix .*#WSGISocketPrefix /tmp/wsgi#' /opt/app-root/src/resultsdb/conf/resultsdb.conf
RUN sed -i 's#^WSGISocketPrefix .*#WSGISocketPrefix /tmp/wsgi#' conf/resultsdb.conf \
# install configuration
&& install -d /mnt/rootfs/usr/share/resultsdb/conf \
&& install -p -m 0644 conf/resultsdb.conf /mnt/rootfs/usr/share/resultsdb/conf/ \
&& install -p -m 0644 conf/resultsdb.wsgi /mnt/rootfs/usr/share/resultsdb/ \
&& install -d /mnt/rootfs/etc/resultsdb \
&& install -p -m 0644 conf/resultsdb.conf /mnt/rootfs/etc/httpd/conf.d/ \
# install alembic configuration and migrations
&& install -p -m 0644 alembic.ini /mnt/rootfs/usr/share/resultsdb/alembic.ini \
&& cp -a resultsdb/alembic /mnt/rootfs/usr/share/resultsdb/alembic \
&& chmod -R 0755 /mnt/rootfs/usr/share/resultsdb/alembic

# config files
RUN install -d /usr/share/resultsdb/conf \
&& install -p -m 0644 /opt/app-root/src/resultsdb/conf/resultsdb.conf /usr/share/resultsdb/conf/ \
&& install -p -m 0644 /opt/app-root/src/resultsdb/conf/resultsdb.wsgi /usr/share/resultsdb/ \
&& install -d /etc/resultsdb \
&& install -p -m 0644 /opt/app-root/src/resultsdb/conf/resultsdb.conf /etc/httpd/conf.d/
# --- Final image
FROM scratch
ARG GITHUB_SHA
LABEL \
name="ResultsDB application" \
vendor="ResultsDB developers" \
license="GPLv2+" \
description="ResultsDB is a results store engine for, but not limited to, Fedora QA tools." \
usage="https://pagure.io/taskotron/resultsdb/blob/develop/f/openshift/README.md" \
url="https://github.com/release-engineering/resultsdb" \
vcs-type="git" \
vcs-ref=$GITHUB_SHA \
io.k8s.display-name="ResultsDB"

# alembic
RUN install -p -m 0644 /opt/app-root/src/resultsdb/alembic.ini /usr/share/resultsdb/alembic.ini
RUN cp -a /opt/app-root/src/resultsdb/resultsdb/alembic /usr/share/resultsdb/alembic
RUN chmod -R 0755 /usr/share/resultsdb/alembic
ENV \
PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
PYTHONUNBUFFERED=1 \
WEB_CONCURRENCY=8

# clean up
RUN rm -rf /opt/app-root/src/resultsdb \
&& dnf -y autoremove findutils rpm-build \
&& dnf clean all
COPY --from=builder /mnt/rootfs/ /
COPY --from=builder /etc/yum.repos.d/ubi.repo /etc/yum.repos.d/ubi.repo
WORKDIR /app

# EXPOSE 5001/tcp
USER 1001
EXPOSE 5001
CMD ["mod_wsgi-express-3", "start-server", "/usr/share/resultsdb/resultsdb.wsgi", \
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["mod_wsgi-express-3.9", "start-server", "/usr/share/resultsdb/resultsdb.wsgi", \
"--user", "apache", "--group", "apache", \
"--port", "5001", "--threads", "5", \
"--include-file", "/etc/httpd/conf.d/resultsdb.conf", \
Expand Down
8 changes: 8 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# ENTRYPOINT for the container.
# Activates virtualenv before running any commands.
set -e

# shellcheck disable=SC1091
. /venv/bin/activate
exec "$@"
42 changes: 42 additions & 0 deletions get-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# SPDX-License-Identifier: GPL-2.0+

# Prints the current version based on the current git revision.

set -e

if [[ -n "$GITHUB_SHA" ]]; then
if [[ $GITHUB_REF =~ ^ref/tags/ ]]; then
echo "${GITHUB_REF#refs/tags/}"
else
last_version=$(poetry version --short)
echo "$last_version+git.${GITHUB_SHA:0:7}"
fi
exit
fi

if [ "$(git tag | wc -l)" -eq 0 ] ; then
# never been tagged since the project is just starting out
lastversion="0.0"
revbase=""
else
lasttag="$(git describe --abbrev=0 HEAD)"
lastversion="$lasttag"
revbase="^$lasttag"
fi
if [ "$(git rev-list $revbase HEAD | wc -l)" -eq 0 ] ; then
# building a tag
version="$lastversion"
else
# git builds count as a pre-release of the next version
version="$lastversion"
version="${version%%[a-z]*}" # strip non-numeric suffixes like "rc1"
# increment the last portion of the version
version="${version%.*}.$((${version##*.} + 1))"
commitcount=$(git rev-list $revbase HEAD | wc -l)
commitsha=$(git rev-parse --short HEAD)
version="${version}.dev${commitcount}+git.${commitsha}"
fi

echo $version

0 comments on commit 095b925

Please sign in to comment.