Skip to content

Commit

Permalink
Merge pull request #119 from ankicommunity/release/v2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
VikashKothary authored Jan 16, 2022
2 parents 2854f92 + ddc7924 commit a8c91b4
Show file tree
Hide file tree
Showing 20 changed files with 1,601 additions and 810 deletions.
43 changes: 30 additions & 13 deletions Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
#/bin/make
#!/usr/bin/env make

ANKI_SERVER_NAME ?= "Anki Sync Server"
ANKI_SERVER_VERSION ?= "v0.1.0"
ANKI_SERVER_DESCRIPTION ?= "Self-hosted Anki Sync Server."
ENV ?= local
ANKISYNCD_NAME ?= Anki Sync Server
ANKISYNCD_VERSION ?= v2.3.0
ANKISYNCD_DESCRIPTION ?= Self-hosted Anki Sync Server.

ENV ?= local
-include config/.env.${ENV}
-include config/secrets/.env.*.${ENV}
export

.DEFAULT_GOAL := help
.PHONY: help #: Display list of command and exit.
help:
@awk 'BEGIN {FS = " ?#?: "; print ""${ANKI_SERVER_NAME}" "${ANKI_SERVER_VERSION}"\n"${ANKI_SERVER_DESCRIPTION}"\n\nUsage: make \033[36m<command>\033[0m\n\nCommands:"} /^.PHONY: ?[a-zA-Z_-]/ { printf " \033[36m%-10s\033[0m %s\n", $$2, $$3 }' $(MAKEFILE_LIST)
@${AWK} 'BEGIN {FS = " ?#?: "; print "${ANKISYNCD_NAME} ${ANKISYNCD_VERSION}\n${ANKISYNCD_DESCRIPTION}\n\nUsage: make \033[36m<command>\033[0m\n\nCommands:"} /^.PHONY: ?[a-zA-Z_-]/ { printf " \033[36m%-10s\033[0m %s\n", $$2, $$3 }' $(MAKEFILE_LIST)

.PHONY: docs #: Build and serve documentation.
docs: print-env
@${MKDOCS} ${MKDOCS_OPTION} -f docs/mkdocs.yml
docs:
@${MKDOCS} ${MKDOCS_CMD} -f docs/mkdocs.yml ${MKDOCS_OPTS}

.PHONY: tests #: Run unit tests.
tests:
@${UNITTEST} discover -s tests

.PHONY: notebooks #: Run jupyter notebooks.
notebooks:
@${JUPYTER} ${JUPYTER_OPTION}
.PHONY: run
run:
@${PYTHON} src/ankisyncd/__main__.py

# Run scripts using make
%:
@test -f scripts/${*}.sh
@${SHELL} scripts/${*}.sh
@if [[ -f "scripts/${*}.sh" ]]; then \
${BASH} "scripts/${*}.sh"; fi

.PHONY: init #: Download Python dependencies.
init:
@${POETRY} install

.PHONY: release #: Create new Git release and tags.
release: release-branch release-tags

.PHONY: open
open:
@${OPEN} ${ANKISYNCD_URL}
77 changes: 60 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ It supports Python 3 and Anki 2.1.
- [Installing](#installing)
- [Installing (Docker)](#installing-docker)
- [Setting up Anki](#setting-up-anki)
- [Anki 2.1](#anki-21)
- [Anki 2.0](#anki-20)
- [AnkiDroid](#ankidroid)
- [Anki 2.1](#anki-21)
- [Anki 2.0](#anki-20)
- [AnkiDroid](#ankidroid)
- [Development](#development)
- [Testing](#testing)
- [ENVVAR configuration overrides](#envvar-configuration-overrides)
- [Support for other database backends](#support-for-other-database-backends)
</details>
Expand Down Expand Up @@ -59,42 +61,54 @@ Installing
requests to ankisyncd.

An example configuration with ankisyncd running on the same machine as Nginx
and listening on port `27702` may look like:
and listening on port `27702` may look like ([entire config template click me](https://github.com/ankicommunity/anki-sync-server/blob/develop/docs/nginx.conf)):

```
```nginx
server {
listen 27701;
server_name default;
location / {
proxy_http_version 1.0;
proxy_pass http://localhost:27702/;
}
listen 27701;
server_name default;
location / {
proxy_http_version 1.0;
proxy_pass http://127.0.0.1:27702/;
}
}
```
5. Run ankisyncd:
$ python -m ankisyncd
```
$ python -m ankisyncd
```
---
Installing (Docker)
-------------------
Follow [these instructions](https://github.com/kuklinistvan/docker-anki-sync-server#usage).
Follow [these instructions](https://github.com/ankicommunity/anki-devops-services#about-this-docker-image).
Setting up Anki
---------------
### Install addon from ankiweb (support 2.1)
1.on add-on window,click `Get Add-ons` and fill in the textbox with the code `358444159`
2.there,you get add-on `custom sync server redirector`,choose it.Then click `config` below right
3.apply your server ip address
if this step is taken,the following instructions regarding addon setting 2.1( including 2.1.28 and above) can be skipped.
### Anki 2.1.28 and above
Create a new directory in [the add-ons folder][addons21] (name it something
like ankisyncd), create a file named `__init__.py` containing the code below
and put it in the `ankisyncd` directory.
import os
addr = "http://127.0.0.1:27701/" # put your server address here
os.environ["SYNC_ENDPOINT"] = addr + "sync/"
os.environ["SYNC_ENDPOINT_MEDIA"] = addr + "msync/"
Expand All @@ -106,7 +120,7 @@ like ankisyncd), create a file named `__init__.py` containing the code below
and put it in the `ankisyncd` directory.
import anki.sync, anki.hooks, aqt
addr = "http://127.0.0.1:27701/" # put your server address here
anki.sync.SYNC_BASE = "%s" + addr
def resetHostNum():
Expand All @@ -119,7 +133,7 @@ Create a file (name it something like ankisyncd.py) containing the code below
and put it in `~/Anki/addons`.
import anki.sync
addr = "http://127.0.0.1:27701/" # put your server address here
anki.sync.SYNC_BASE = addr
anki.sync.SYNC_MEDIA_BASE = addr + "msync/"
Expand All @@ -142,6 +156,35 @@ Even though the AnkiDroid interface will request an email address, this is not
required; it will simply be the username you configured with `ankisyncctl.py
adduser`.
Development
-----------
### Testing
0. Prerequites
This project uses [GNU Make](https://www.gnu.org/software/make/) to simplify the development commands. It also uses [Poetry](https://python-poetry.org/) to manage the Python dependencies. Ensure they are installed.
1. Create a config for your local environment.
```bash
$ cp config/.env.example config/.env.local
```

See [ENVVAR configuration overrides](#envvar-configuration-overrides) for more information.

2. Download Python dependencies.

```bash
$ make init
```

3. Run unit tests.

```bash
$ make tests
```

ENVVAR configuration overrides
------------------------------

Expand Down
39 changes: 25 additions & 14 deletions config/.env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# .env.example (anki-sync-server)

## Make
MKDOCS=mkdocs
JUPYTER=jupyter
# file: .env.example (ankisyncd)
# cp config/.env.example config/.env.local

## Ankisyncd
ANKISYNCD_HOST=0.0.0.0
Expand All @@ -12,17 +9,31 @@ ANKISYNCD_BASE_URL=/sync/
ANKISYNCD_BASE_MEDIA_URL=/msync/
ANKISYNCD_AUTH_DB_PATH=./auth.db
ANKISYNCD_SESSION_DB_PATH=./session.db

ANKISYNCD_FULL_SYNC_MANAGER
ANKISYNCD_SESSION_MANAGER
ANKISYNCD_USER_MANAGER
ANKISYNCD_COLLECTION_WRAPPER
### ANKISYNCD_FULL_SYNC_MANAGER
### ANKISYNCD_SESSION_MANAGER
### ANKISYNCD_USER_MANAGER
### ANKISYNCD_COLLECTION_WRAPPER
ANKISYNCD_URL=http://${ANKISYNCD_HOST}:${ANKISYNCD_PORT}

## Mkdocs
MKDOCS_OPTION=serve
MKDOCS_HOST=localhost
MKDOCS_PORT=5000
MKDOCS_OPTS=-a ${MKDOCS_HOST}:${MKDOCS_PORT}
MKDOCS_CMD=serve

## Jupyter
JUPYTER_OPTION=lab
### JUPYTER_CMD
### JUPYTER_NOTEBOOK_DIR

## Make
AWK=awk
BASH=bash
POETRY=poetry
PYTHON=python
MKDOCS=mkdocs
JUPYTER=jupyter
UNITTEST=python -m unittest

## Path
PATH:=.venv/bin/path:${PATH}
## Shell
SHELL=${BASH}
PATH:=.venv/bin:${PATH}
4 changes: 3 additions & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ site_author: Anki Community
site_url: https://ankicommunity.github.io/anki-sync-server
repo_url: https://github.com/ankicommunity/anki-sync-server
docs_dir: src
site_dir: build
site_dir: build
plugins:
- mkdocs-jupyter
29 changes: 29 additions & 0 deletions docs/src/nginx/nginx.example.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# file: nginx.example.conf
# description: Example nginx.conf to set up a reverse proxy.

worker_processes 1;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;

keepalive_timeout 65;
client_max_body_size 2048m;

server {
listen 27701;
# server_name should be modified (LAN eg: 192.168.1.43 )
server_name default;


location / {
proxy_http_version 1.0;
proxy_pass http://127.0.0.1:27702/;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,6 @@
"source": [
"col.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit a8c91b4

Please sign in to comment.