Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #358 from gilesknap/bind_host
Browse files Browse the repository at this point in the history
Bind host
  • Loading branch information
gilesknap authored May 20, 2022
2 parents 94c6a25 + 978c25f commit cb30b35
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 19 deletions.
7 changes: 5 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \
WORKDIR /workspace
COPY . .

# install runtime from DIST if there is one

# install runtime from DIST if there is one
RUN mkdir -p /root/.local && \
test -d dist && \
if [ -d dist ] ; then \
touch requirements.txt && \
pip install --user -r requirements.txt dist/*.whl || :
pip install --user -r requirements.txt dist/*.whl ; \
fi

FROM base as runtime

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ jobs:
tags: |
type=ref,event=branch
type=ref,event=tag
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ github.event_name != 'pull_request' }}
type=raw,value=pr
# required for multi-arch build
Expand Down
19 changes: 19 additions & 0 deletions docs/how-to/windows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,22 @@ in a far cleaner way.
The integration
if particularly good on Windows 11.
See https://docs.microsoft.com/en-us/windows/wsl/install.

.. _WindowsDocker:

Initial Setup on Windows for Docker desktop
===========================================

If you want to run the app in a container then there are some additional
steps required on Windows.

First you need to have installed Docker Desktop from
https://www.docker.com/products/docker-desktop/

- make sure leave ticked 'use WSL2 instead of Hyper V'
- if you already have docker installed with Hyper V consider re-installing with
WSL2




16 changes: 9 additions & 7 deletions docs/tutorials/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ You are ready to run gphotos-sync for the first time, either locally or
inside of a container. The first run will require a user login see
`Login`

.. _Container:

Execute in a container
======================
Expand All @@ -35,17 +36,18 @@ Hence the typical way to launch the container with docker runtime would be::

$ CONFIG=$HOME/.config/gphotos-sync
$ STORAGE=$HOME/My_photos_backup
$ docker run --rm -v $CONFIG:/config -v $STORAGE:/storage --net=host -it ghcr.io/gilesknap/gphotos-sync /storage
$ docker run --rm -v $CONFIG:/config -v $STORAGE:/storage -p 8080:8080 -it ghcr.io/gilesknap/gphotos-sync /storage

The options --net=host -it are required for the first invocation only, so that the
browser can find authentication service.
The options ``-p 8080:8080 -it`` are required for the first invocation only,
so that the browser can find authentication service.

Note that the authentication flow uses a redirect url that sends authentication
token back to the process. The default redirect is localhost:8080 you can
adjust these with ``--host <HOSTNAME> --port<PORT_NUMBER>``. At present the
flow only accepts localhost for host so I'm not sure what the option is for.
token back to the process. The default redirect is localhost:8080 and you can
adjust the port with ``--port<PORT_NUMBER>``. The
flow only allows localhost for security reasons so the first run must always
be done on a machine with a browser.

Note that if you are running on a NAS or other headless server you will first
If you are running on a NAS or other headless server you will first
need to run locally so that you can do initial login flow with a browser.
Then copy <TARGET>/.gphotos.token to the server. For this
first run you could use the following options so that no backup is performed:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ install_requires =
pyyaml>=4.2b1
types-PyYAML
psutil
google-auth-oauthlib
google-auth-oauthlib @ https://github.com/gilesknap/google-auth-library-python-oauthlib/archive/refs/tags/v0.5.2b1.zip
types-requests

[options.extras_require]
Expand Down
4 changes: 0 additions & 4 deletions src/gphotos_sync/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,6 @@ def __init__(self):
type=int,
default=8080,
)
parser.add_argument(
"--host", help="hostname for the login flow redirect", default="localhost"
)
parser.add_help = True

def setup(self, args: Namespace, db_path: Path):
Expand Down Expand Up @@ -339,7 +336,6 @@ def setup(self, args: Namespace, db_path: Path):
credentials_file,
secret_file,
int(args.max_retries),
host=args.host,
port=args.port,
)
self.auth.authorize()
Expand Down
7 changes: 4 additions & 3 deletions src/gphotos_sync/authorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __init__(
token_file: Path,
secrets_file: Path,
max_retries: int = 5,
host: str = "localhost",
port: int = 8080,
):
"""A very simple class to handle Google API authorization flow
Expand All @@ -44,7 +43,6 @@ def __init__(
self.session = None
self.token = None
self.secrets_file = secrets_file
self.host = host
self.port = port

try:
Expand Down Expand Up @@ -93,7 +91,10 @@ def authorize(self):
flow = InstalledAppFlow.from_client_secrets_file(
self.secrets_file, scopes=self.scope
)
flow.run_local_server(open_browser=False, host=self.host, port=self.port)
# localhost and bind to 0.0.0.0 always works even in a container.
flow.run_local_server(
open_browser=False, bind_addr="0.0.0.0", port=self.port
)

self.session = flow.authorized_session()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_credentials/.gphotos.token
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"access_token": "ya29.a0ARrdaM-IGzrK-mE0Rqk-YeZb8mViF6UhTj7Z4h-t3Jzh0KXFRvMYFEQQT8Pn7cJW9kVnuU7PNs7pbCpQT1Tck-DQFX3zAHIORdddq2TBqD8VIqGJMwkm7u4wOb5uh83AQbuAN9s_FxXy-292qa3Cq--HAWb0Wg", "expires_in": 3599, "scope": ["https://www.googleapis.com/auth/photoslibrary.readonly", "https://www.googleapis.com/auth/photoslibrary.sharing"], "token_type": "Bearer", "expires_at": 1652804307.991652, "refresh_token": "1//03CEqAzsnP-8PCgYIARAAGAMSNwF-L9Irz4_ilhRw0HIwVImT4gTCUPlV8YaCTYQiIjD4juWOI5eQh_-Rzh9nTmBND0jliOnabq4"}
{"access_token": "ya29.a0ARrdaM-M6_B3tlQ89_ujmzYD59rRbD5HFUL-9PT13qjZaMAMG3GCoF6yjKJ3q5BZc6KYTgE_waVeprrYfKq0sUg9wYMLJK2QoIwJ5i7E0fyEqA7Jdi0Uj00UvZ8MN7yLulBGeORsQczEuWZqNMW4rwWzt2SqOg", "expires_in": 3599, "scope": ["https://www.googleapis.com/auth/photoslibrary.sharing", "https://www.googleapis.com/auth/photoslibrary.readonly"], "token_type": "Bearer", "expires_at": 1652904084.5309072, "refresh_token": "1//03CEqAzsnP-8PCgYIARAAGAMSNwF-L9Irz4_ilhRw0HIwVImT4gTCUPlV8YaCTYQiIjD4juWOI5eQh_-Rzh9nTmBND0jliOnabq4"}

0 comments on commit cb30b35

Please sign in to comment.