diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index ee866491..9df632d7 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,11 +1,7 @@ -name: Test and Release +name: Test on: pull_request: - push: - branches: - - main - tags: jobs: test: @@ -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/metadata-action@v3.7.0 - 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/action@v1.17 - with: - github-token: ${{ secrets.GH_PAT_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..27d1f27f --- /dev/null +++ b/.github/workflows/release.yaml @@ -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 }} diff --git a/.github/workflows/semantic-release.yaml b/.github/workflows/semantic-release.yaml new file mode 100644 index 00000000..88865625 --- /dev/null +++ b/.github/workflows/semantic-release.yaml @@ -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 }} diff --git a/Dockerfile b/Dockerfile index 2cd2e61c..83fc5056 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..284595d1 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +recursive-include app/templates * +recursive-include app/static * diff --git a/README.md b/README.md index 62c13e17..fd62e535 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/server.py b/app/server.py index 10c84d81..8ce1fbf8 100644 --- a/app/server.py +++ b/app/server.py @@ -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): @@ -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() diff --git a/docker-compose.yaml b/docker-compose.yaml index 023bb5dc..cab9f627 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,4 +7,4 @@ services: env_file: - .env ports: - - "5000:5000" + - "8080:8080" diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..3d010cad --- /dev/null +++ b/setup.py @@ -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="it@rabe.ch", + 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", + ], +)