Skip to content

Commit

Permalink
feat: use python-minimal container images and cleanup CI (#174)
Browse files Browse the repository at this point in the history
* use s2i-python and python-minimal container images
* ci cleanup/fix
* use 8080 as default port
* wheel based install
  • Loading branch information
hairmare authored Apr 23, 2022
1 parent dfe0abf commit 8a021ed
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 83 deletions.
50 changes: 1 addition & 49 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
name: Test and Release
name: Test

on:
pull_request:
push:
branches:
- main
tags:

jobs:
test:
Expand All @@ -21,47 +17,3 @@ jobs:
- name: Test
run: |
pytest --cov=app --cov-report=term --cov-fail-under=100
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Docker meta
id: docker_meta
uses: docker/[email protected]
with:
images: ghcr.io/radiorabe/catpage
flavor: |
latest=auto
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
release:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: go-semantic-release/[email protected]
with:
github-token: ${{ secrets.GH_PAT_TOKEN }}
74 changes: 74 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Publish Container Images

on:
push:
tags:
- 'v*.*.*'
pull_request:

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3

- name: Prepare additional Metadata
id: addtional_meta
run: |
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Prepare Image Metadata
id: meta
uses: docker/metadata-action@v3
with:
images: |
ghcr.io/radiorabe/catpage
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
labels: |
name=cat-page
summary=${{ github.event.repository.description }}
url=${{ github.event.repository.html_url }}
vcs-ref=${{ github.sha }}
revision=${{ github.sha }}
release=${{ github.sha }}
build-date=${{ steps.addtional_meta.outputs.created }}
io.k8s.display-name=Cat Page
io.k8s.description=${{ github.event.repository.description }}
io.openshift.tags=minimal rhel8 rabe s2i python python39 catpage
version=1
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: |
${{ steps.meta.outputs.labels }}
version=${{ steps.meta.outputs.version }}
21 changes: 21 additions & 0 deletions .github/workflows/semantic-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run semantic-release

on:
push:
branches:
- main

jobs:
semantic-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Run go-semantic-release
id: semrel
uses: go-semantic-release/action@v1
with:
github-token: ${{ secrets.RABE_ITREAKTION_GITHUB_TOKEN }}
33 changes: 9 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
FROM node:17.0-alpine as jsdep
FROM ghcr.io/radiorabe/s2i-python:0.1.1 AS build

WORKDIR /app
COPY --chown=1001:0 ./ /opt/app-root/src/

COPY package.json yarn.lock /app/
RUN npm install \
&& cp node_modules/typeface-fjalla-one/files/fjalla-one-* app/static/ \
&& python3 setup.py bdist_wheel

RUN yarn install

FROM python:3.9-alpine
FROM ghcr.io/radiorabe/python-minimal:0.2.3 AS app

WORKDIR /app
COPY --from=build /opt/app-root/src/dist/*.whl /tmp/dist/

ARG DEV=false

COPY requirements*.txt /app/

RUN [[ "x${DEV}" != "xfalse" ]] \
&& ( \
apk --no-cache add \
build-base \
libffi-dev \
openssl-dev \
&& pip install -r requirements-dev.txt \
) \
|| pip install -r requirements.txt

COPY . /app
COPY --from=jsdep /app/node_modules/typeface-fjalla-one/files/fjalla-one-* /app/app/static/

EXPOSE 5000
RUN python3 -mpip --no-cache-dir install /tmp/dist/*.whl \
&& rm -rf /tmp/dist/

USER nobody

Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
recursive-include app/templates *
recursive-include app/static *
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ See `python app/server.py --help` for usage message and configuration info.
### Docker

```bash
docker run --rm -ti -p 5000:5000 radiorabe/catpage
docker run --rm -ti -p 8080:8080 radiorabe/catpage
```

Connect to [localhost:5000](http://localhost:5000).
Connect to [localhost:8080](http://localhost:8080).

### Docker-compose

Expand Down
Empty file added app/__init__.py
Empty file.
18 changes: 11 additions & 7 deletions app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def config(parse=True):
)
parser.add_argument("--links", env_var="PAGE_LINKS", action="append", default=[])
parser.add_argument("--address", env_var="PAGE_ADDRESS", default="0.0.0.0")
parser.add_argument("--port", env_var="PAGE_PORT", default=5000)
parser.add_argument("--port", env_var="PAGE_PORT", default=8080)
parser.add_argument("--thread-pool", env_var="PAGE_THREADPOOL", default=30)

def add_bool_arg(parser, name, default=False):
Expand Down Expand Up @@ -199,11 +199,15 @@ def run_webserver(app, config): # pragma: no cover
cherrypy.engine.block()


if __name__ == "__main__": # pragma: no cover
def main(): # pragma: no cover
logger.info(f"Starting cat-page server version {__version__}")
config = config()
app = create_app(config)
if config.dev:
run_devserver(app, config)
cfg = config()
app = create_app(cfg)
if cfg.dev:
run_devserver(app, cfg)
else:
run_webserver(app, config)
run_webserver(app, cfg)


if __name__ == "__main__": # pragma: no cover
main()
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ services:
env_file:
- .env
ports:
- "5000:5000"
- "8080:8080"
27 changes: 27 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Set up cat-page."""

from setuptools import find_packages, setup

with open("requirements.txt") as file:
requirements = file.read().splitlines()


setup(
name="cat-page",
description="RaBe Cat Landing Page",
url="http://github.com/radiorabe/cat-page",
author="RaBe IT-Reaktion",
author_email="[email protected]",
license="AGPL-3",
version_config=True,
setup_requires=["setuptools-git-versioning"],
install_requires=requirements,
packages=find_packages(exclude=("tests",)),
include_package_data=True,
entry_points={"console_scripts": ["catpage=app.server:main"]},
zip_safe=True,
classifiers=[
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: GNU Affero General Public License v3",
],
)

0 comments on commit 8a021ed

Please sign in to comment.