From 75459d288039b895b2af6dcafd2d3fd5f9ec3cc7 Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Wed, 8 Feb 2023 11:22:38 +0000 Subject: [PATCH] docker --- .github/workflows/docker-publish.yaml | 48 +++++++++++++++++++ .github/workflows/python-publish.yaml | 7 +-- Dockerfile | 2 +- .../formatters/html_formatter.py | 5 +- .../formatters/templates/html_template.html | 2 +- 5 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/docker-publish.yaml diff --git a/.github/workflows/docker-publish.yaml b/.github/workflows/docker-publish.yaml new file mode 100644 index 0000000..5332961 --- /dev/null +++ b/.github/workflows/docker-publish.yaml @@ -0,0 +1,48 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + release: + types: [published] + push: + branches: [ "dockerize" ] + tags: [ "v*.*.*" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: bellingcat/auto-archiver + + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/python-publish.yaml b/.github/workflows/python-publish.yaml index 07f1405..d9294f7 100644 --- a/.github/workflows/python-publish.yaml +++ b/.github/workflows/python-publish.yaml @@ -11,12 +11,9 @@ name: Upload Python Package on: release: types: [published] - push: - branches: - - dockerize - tags: - - 'v*.*.*' + branches: [ "dockerize" ] + tags: [ "v*.*.*" ] permissions: contents: read diff --git a/Dockerfile b/Dockerfile index 4e15424..b189de1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ RUN pip install --upgrade pip && \ # TODO: avoid copying unnecessary files, including .git COPY Pipfile Pipfile.lock ./ RUN pipenv install --python=3.10 --system --deploy -ENV IS_DOCKER=1 +# ENV IS_DOCKER=1 # doing this at the end helps during development, builds are quick COPY ./src/ . diff --git a/src/auto_archiver/formatters/html_formatter.py b/src/auto_archiver/formatters/html_formatter.py index aa56e72..cb00111 100644 --- a/src/auto_archiver/formatters/html_formatter.py +++ b/src/auto_archiver/formatters/html_formatter.py @@ -4,6 +4,7 @@ import mimetypes, uuid, os, pathlib from jinja2 import Environment, FileSystemLoader from urllib.parse import quote +from ..version import __version__ from ..core import Metadata, Media from . import Formatter @@ -28,13 +29,13 @@ class HtmlFormatter(Formatter): "detect_thumbnails": {"default": True, "help": "if true will group by thumbnails generated by thumbnail enricher by id 'thumbnail_00'"}, } - def format(self, item: Metadata) -> Media: content = self.template.render( url=item.get_url(), title=item.get_title(), media=item.media, - metadata=item.get_clean_metadata() + metadata=item.get_clean_metadata(), + version=__version__ ) html_path = os.path.join(item.get_tmp_dir(), f"formatted{str(uuid.uuid4())}.html") with open(html_path, mode="w", encoding="utf-8") as outf: diff --git a/src/auto_archiver/formatters/templates/html_template.html b/src/auto_archiver/formatters/templates/html_template.html index 340b286..68e54d5 100644 --- a/src/auto_archiver/formatters/templates/html_template.html +++ b/src/auto_archiver/formatters/templates/html_template.html @@ -162,7 +162,7 @@ {% endfor %} -

Made with bellingcat/auto-archiver

+

Made with bellingcat/auto-archiver v{{ version }}