Initial commit
This commit is contained in:
		
						commit
						e73142c21f
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | |||
| data/ | ||||
| .env | ||||
							
								
								
									
										59
									
								
								anki-sync/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								anki-sync/Dockerfile
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,59 @@ | |||
| ARG ANKISYNCD_ROOT=/opt/ankisyncd | ||||
| ARG PYTHONUSERBASE=/opt/venv | ||||
| 
 | ||||
| # -- BUILDER -- | ||||
| FROM library/python:3.9-buster as builder | ||||
| 
 | ||||
| ARG ANKISYNCD_ROOT | ||||
| WORKDIR ${ANKISYNCD_ROOT} | ||||
| 
 | ||||
| COPY bin/download-release.sh ./bin/download-release.sh | ||||
| 
 | ||||
| ARG PYTHONUSERBASE | ||||
| RUN sh ./bin/download-release.sh && \ | ||||
| 	pip3 install --upgrade pip && \ | ||||
|     pip3 install --user -r ./release/requirements.txt | ||||
| 
 | ||||
| # -- DEPLOYER -- | ||||
| FROM python:3.9-slim-buster | ||||
| 
 | ||||
| # Copy Python dependencies | ||||
| ARG PYTHONUSERBASE | ||||
| ENV PYTHONUSERBASE=${PYTHONUSERBASE} | ||||
| COPY --from=builder ${PYTHONUSERBASE} ${PYTHONUSERBASE} | ||||
| 
 | ||||
| # Copy Anki Sync Server release and scripts | ||||
| ARG ANKISYNCD_ROOT | ||||
| COPY --from=builder ${ANKISYNCD_ROOT}/release ${ANKISYNCD_ROOT} | ||||
| WORKDIR ${ANKISYNCD_ROOT} | ||||
| 
 | ||||
| # Move ankisyncctl.py to the working directory and make it executable | ||||
| RUN mv /opt/ankisyncd/ankisyncd_cli/ankisyncctl.py /opt/ankisyncd/ankisyncctl.py && \ | ||||
|     chmod +x /opt/ankisyncd/ankisyncctl.py | ||||
| 
 | ||||
| # Create data volume. | ||||
| ARG ANKISYNCD_DATA_ROOT=/srv/ankisyncd | ||||
| VOLUME ${ANKISYNCD_DATA_ROOT} | ||||
| 
 | ||||
| # Set default environment variables. | ||||
| ARG ANKISYNCD_PORT=27701 | ||||
| ARG ANKISYNCD_BASE_URL=/sync/ | ||||
| ARG ANKISYNCD_BASE_MEDIA_URL=/msync/ | ||||
| 
 | ||||
| ENV ANKISYNCD_HOST=0.0.0.0 \ | ||||
| 	ANKISYNCD_PORT=${ANKISYNCD_PORT} \ | ||||
| 	ANKISYNCD_DATA_ROOT=${ANKISYNCD_DATA_ROOT} \ | ||||
| 	ANKISYNCD_BASE_URL=${ANKISYNCD_BASE_URL} \ | ||||
| 	ANKISYNCD_BASE_MEDIA_URL=${ANKISYNCD_BASE_MEDIA_URL} \ | ||||
| 	ANKISYNCD_AUTH_DB_PATH=/data/auth.db \ | ||||
| 	ANKISYNCD_SESSION_DB_PATH=/data/session.db \ | ||||
| 	ANKISYNCD_DATA_ROOT=/data | ||||
| 
 | ||||
| COPY bin/entrypoint.sh ./bin/entrypoint.sh | ||||
| 
 | ||||
| EXPOSE ${ANKISYNCD_PORT} | ||||
| 
 | ||||
| # TODO: Change to ENTRYPOINT. Currently CMD to allow shell access if needed. | ||||
| CMD ["/bin/sh", "./bin/entrypoint.sh"] | ||||
| 
 | ||||
| HEALTHCHECK --interval=60s --timeout=3s CMD python -c "import requests; requests.get('http://127.0.0.1:${ANKISYNCD_PORT}/')" | ||||
							
								
								
									
										15
									
								
								anki-sync/bin/download-release.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										15
									
								
								anki-sync/bin/download-release.sh
									
									
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| #!/bin/sh | ||||
| # file: download-release.sh | ||||
| 
 | ||||
| 
 | ||||
| mkdir -p release | ||||
| 
 | ||||
| cd release | ||||
| 
 | ||||
| git clone https://github.com/ankicommunity/anki-sync-server | ||||
| 
 | ||||
| mv anki-sync-server/src/* . | ||||
| 
 | ||||
| rm -rf anki-sync-server | ||||
| 
 | ||||
| cd .. | ||||
							
								
								
									
										15
									
								
								anki-sync/bin/entrypoint.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										15
									
								
								anki-sync/bin/entrypoint.sh
									
									
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| #!/bin/sh | ||||
| # file: entrypoint.sh | ||||
| 
 | ||||
| # if [ -f "/app/data/auth.db" ]; then | ||||
| #     echo "auth.db found" | ||||
| # else | ||||
| #     echo "Creating new authentication database: auth.db." | ||||
| #     sqlite3 /app/data/auth.db 'CREATE TABLE auth (user VARCHAR PRIMARY KEY, hash VARCHAR)' | ||||
| # fi | ||||
| 
 | ||||
| # echo "Updating database schema" | ||||
| # python3 utils/migrate_user_tables.py | ||||
| 
 | ||||
| echo "Starting anki-sync-server" | ||||
| python3 -m ankisyncd | ||||
							
								
								
									
										14
									
								
								anki-sync/docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								anki-sync/docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | |||
| version: '3.7' | ||||
| services: | ||||
| 
 | ||||
|   anki_sync_server: | ||||
|     image: ${DOCKER_IMAGE:-anki-sync-server}:${DOCKER_VERSION:-latest} | ||||
|     build: | ||||
|       context: . | ||||
|       dockerfile: Dockerfile | ||||
|       args: | ||||
|         - ANKISYNCD_PORT=${ANKISYNCD_PORT:-27701} | ||||
|         - ANKISYNCD_BASE_URL=${ANKISYNCD_BASE_URL:-/sync/} | ||||
|         - ANKISYNCD_BASE_MEDIA_URL=${ANKISYNCD_BASE_MEDIA_URL:-/msync/} | ||||
|         - ANKISYNCD_AUTH_DB_PATH=${ANKISYNCD_AUTH_DB_PATH:-./auth.db} | ||||
|         - ANKISYNCD_SESSION_DB_PATH=${ANKISYNCD_SESSION_DB_PATH:-./session.db} | ||||
							
								
								
									
										13
									
								
								docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| version: '3' | ||||
| services: | ||||
|   anki-sync-server: | ||||
|     build: ./anki-sync | ||||
|     environment: | ||||
|       - ANKISYNCD_DATA_ROOT=/data | ||||
|       - ANKISYNCD_AUTH_DB_PATH=/data/auth.db | ||||
|       - ANKISYNCD_SESSION_DB_PATH=/data/session.db | ||||
|     ports: | ||||
|       - "${ANKI_PORT}:27701" | ||||
|     volumes: | ||||
|       - "${ANKI_VOLUME_PATH}:/data" | ||||
| 
 | ||||
							
								
								
									
										59
									
								
								install.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										59
									
								
								install.sh
									
									
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,59 @@ | |||
| #!/bin/bash | ||||
| 
 | ||||
| # Set variables | ||||
| SERVICE_FILE="service/anki-sync-server.service" | ||||
| SYSTEMD_DIR="/etc/systemd/system" | ||||
| ENV_SAMPLE="sample.env" | ||||
| ENV_TARGET=".env" | ||||
| 
 | ||||
| # Check if root | ||||
| if [[ $EUID -ne 0 ]]; then | ||||
|     echo "This script must be run as root." | ||||
|     exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Copy service file to systemd directory | ||||
| if [ -e "$SERVICE_FILE" ]; then | ||||
|     cp -n "$SERVICE_FILE" "$SYSTEMD_DIR" | ||||
|     if [ $? -eq 0 ]; then | ||||
|         echo "Service file copied successfully." | ||||
|         systemctl daemon-reload | ||||
|         if [ $? -eq 0 ]; then | ||||
|             echo "Daemon reloaded successfully." | ||||
|         else | ||||
|             echo "Failed to reload the daemon." | ||||
|             exit 1 | ||||
|         fi | ||||
|     else | ||||
|         echo "Failed to copy the service file." | ||||
|         exit 1 | ||||
|     fi | ||||
| else | ||||
|     echo "Service file $SERVICE_FILE does not exist." | ||||
|     exit 1 | ||||
| fi | ||||
| 
 | ||||
| # Copy sample.env to .env if it does not already exist | ||||
| if [ ! -e "$ENV_TARGET" ]; then | ||||
|     if [ -e "$ENV_SAMPLE" ]; then | ||||
|         cp "$ENV_SAMPLE" "$ENV_TARGET" | ||||
|         if [ $? -eq 0 ]; then | ||||
|             echo ".env file created successfully." | ||||
|         else | ||||
|             echo "Failed to create .env file." | ||||
|             exit 1 | ||||
|         fi | ||||
|     else | ||||
|         echo "Sample env file $ENV_SAMPLE does not exist." | ||||
|         exit 1 | ||||
|     fi | ||||
| else | ||||
|     echo ".env file already exists, skipping." | ||||
| fi | ||||
| 
 | ||||
| # Remind user to create data directory | ||||
| echo "Remember to create the data directory on your local machine." | ||||
| 
 | ||||
| # Script completed successfully | ||||
| exit 0 | ||||
| 
 | ||||
							
								
								
									
										1
									
								
								sample.env
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								sample.env
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | |||
| .env | ||||
							
								
								
									
										14
									
								
								service/anki-sync-server.service
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								service/anki-sync-server.service
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | |||
| [Unit] | ||||
| Description=Anki Sync Server | ||||
| Requires=docker.service | ||||
| After=docker.service | ||||
| 
 | ||||
| [Service] | ||||
| WorkingDirectory=/var/lib/anki | ||||
| ExecStart=/usr/local/bin/docker-compose up | ||||
| ExecStop=/usr/local/bin/docker-compose down | ||||
| Restart=always | ||||
| EnvironmentFile=/var/lib/anki/.env | ||||
| 
 | ||||
| [Install] | ||||
| WantedBy=multi-user.target | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user