Skip to content

Commit

Permalink
feat(docker): added docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
rwxd committed Dec 24, 2022
1 parent cf1cc72 commit 4fa4e7f
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
repository:
name: "wallabag2readwise"
description: "Sync wallabag annotations to readwise highlights"
topics: "wallabag, readwise, sync"
description: "Export / synchronize wallabag annotations to readwise highlights"
topics: "wallabag, readwise, sync, export"
53 changes: 52 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ jobs:
run: pre-commit run --show-diff-on-failure --all-files
env:
SKIP: "no-commit-to-branch"
push:

pypi:
runs-on: ubuntu-latest
needs:
- test
Expand All @@ -46,3 +47,53 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}

container:
runs-on: ubuntu-latest
needs:
- test
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags') or github.ref == 'main')
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
# list of Docker images to use as base name for tags
images: |
rwxd/excalidraw
ghcr.io/rwxd/excalidraw
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Log in to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@d398f07826957cd0a18ea1b059cf1207835e60bc
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_TOKEN }}

- name: Build and push master Docker image
uses: docker/[email protected]
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.10-alpine

WORKDIR /app

COPY requirements.txt .

RUN : \
pip --no-cache-dir install -r requirements.txt

COPY . .

RUN pip install .

ENTRYPOINT ["wallabag2readwise", "daemon"]
54 changes: 51 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

## Description

Pushes wallabag annotations from entries to Readwise highlights.
Exports / synchronizes annotations from [wallabag](https://github.com/wallabag/wallabag) to [Readwise](https://readwise.io/) article highlights.

This tool can be run as a cli tool or as a (docker) container.

Rate limiting of the Readwise API is supported.

## Installation

### CLI

```bash
python3 -m pip install wallabag2readwise
```
Expand All @@ -16,17 +22,59 @@ or with [pipx](https://github.com/pypa/pipx)
pipx install wallabag2readwise
```

### Docker / Container

```bash
docker pull ghcr.io/rwxd/wallabag2readwise:latest
```

```bash
docker run ghcr.io/rwxd/wallabag2readwise:latest --wait-time 60 ...
```

#### Docker-Compose

```yaml
version: "3.9"
services:
wallabag2readwise:
image: ghcr.io/rwxd/wallabag2readwise:latest
container_name: wallabag2readwise
restart: unless-stopped
environment:
READWISE_TOKEN: ''
WALLABAG_URL: ''
WALLABAG_USER: ''
WALLABAG_PASSWORD: ''
WALLABAG_CLIENT_ID: ''
WALLABAG_CLIENT_SECRET: ''
# env_file:
# - .env
```

```bash
docker-compose up -d && docker-compose logs -f
```

## Usage

### Commands

```bash
wallabag2readwise
wallabag2readwise push
```

#### Daemon

Run continuously and push new annotations to Readwise every 60 minutes.
(The container is automatically in daemon mode.)

```bash wallabag2readwise daemon --wait-time 60
```

### Configuration

Get a new Readwise API Token from [this url](https://readwise.io/access_token).
Get a new Readwise API Token from <https://readwise.io/access_token>.

Create a new wallabag API client in your instance <https://my-wallabag.com/developer/client/create>.

Expand Down
12 changes: 11 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from setuptools import setup
from os import path
from subprocess import check_output

with open("./requirements.txt") as f:
required = f.read().splitlines()
Expand All @@ -8,9 +9,18 @@
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()

version = '1.2.0'

try:
version = (
check_output(['git', 'describe', '--tags']).strip().decode().replace('v', '')
)
except:
pass

setup(
name='wallabag2readwise',
version='1.1.1',
version=version,
description='Push wallabag annotations to Readwise highlights',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
39 changes: 35 additions & 4 deletions wallabag2readwise/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from wallabag2readwise.readwise import ReadwiseConnector

from wallabag2readwise.wallabag import WallabagConnector
from time import sleep
from wallabag2readwise.output import console
import importlib.metadata


app = typer.Typer()
Expand Down Expand Up @@ -30,7 +33,35 @@ def push(
push_annotations(wallabag, readwise)


# TODO: Daemon
# @app.command()
# def daemon():
# pass
@app.command()
def daemon(
wallabag_url: str = typer.Option(
..., envvar='WALLABAG_URL', help='url to your wallabag instance'
),
wallabag_user: str = typer.Option(..., envvar='WALLABAG_USER'),
wallabag_password: str = typer.Option(..., envvar='WALLABAG_PASSWORD', prompt=True),
wallabag_client_id: str = typer.Option(..., envvar='WALLABAG_CLIENT_ID'),
wallabag_client_secret: str = typer.Option(..., envvar='WALLABAG_CLIENT_SECRET'),
readwise_token: str = typer.Option(..., envvar='READWISE_TOKEN', prompt=True),
wait_time: int = typer.Option(60, help='time to wait between runs in minutes'),
):

console.print(f'> Starting daemon with {wait_time} minutes wait time')
while True:
wallabag = WallabagConnector(
wallabag_url,
wallabag_user,
wallabag_password,
wallabag_client_id,
wallabag_client_secret,
)
readwise = ReadwiseConnector(readwise_token)
push_annotations(wallabag, readwise)

console.print(f'=> Waiting {wait_time} minutes')
sleep(wait_time * 60)


@app.command()
def version():
console.print(importlib.metadata.version('wallabag2readwise'))

0 comments on commit 4fa4e7f

Please sign in to comment.