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

Commit cb30b35

Browse files
authored
Merge pull request #358 from gilesknap/bind_host
Bind host
2 parents 94c6a25 + 978c25f commit cb30b35

File tree

8 files changed

+40
-19
lines changed

8 files changed

+40
-19
lines changed

.devcontainer/Dockerfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \
2121
WORKDIR /workspace
2222
COPY . .
2323

24+
# install runtime from DIST if there is one
25+
2426
# install runtime from DIST if there is one
2527
RUN mkdir -p /root/.local && \
26-
test -d dist && \
28+
if [ -d dist ] ; then \
2729
touch requirements.txt && \
28-
pip install --user -r requirements.txt dist/*.whl || :
30+
pip install --user -r requirements.txt dist/*.whl ; \
31+
fi
2932

3033
FROM base as runtime
3134

.github/workflows/code.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ jobs:
206206
tags: |
207207
type=ref,event=branch
208208
type=ref,event=tag
209-
type=raw,value=latest,enable={{is_default_branch}}
209+
type=raw,value=latest,enable=${{ github.event_name != 'pull_request' }}
210210
type=raw,value=pr
211211
212212
# required for multi-arch build

docs/how-to/windows.rst

+19
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,22 @@ in a far cleaner way.
6767
The integration
6868
if particularly good on Windows 11.
6969
See https://docs.microsoft.com/en-us/windows/wsl/install.
70+
71+
.. _WindowsDocker:
72+
73+
Initial Setup on Windows for Docker desktop
74+
===========================================
75+
76+
If you want to run the app in a container then there are some additional
77+
steps required on Windows.
78+
79+
First you need to have installed Docker Desktop from
80+
https://www.docker.com/products/docker-desktop/
81+
82+
- make sure leave ticked 'use WSL2 instead of Hyper V'
83+
- if you already have docker installed with Hyper V consider re-installing with
84+
WSL2
85+
86+
87+
88+

docs/tutorials/installation.rst

+9-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ You are ready to run gphotos-sync for the first time, either locally or
2020
inside of a container. The first run will require a user login see
2121
`Login`
2222

23+
.. _Container:
2324

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

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

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

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

48-
Note that if you are running on a NAS or other headless server you will first
50+
If you are running on a NAS or other headless server you will first
4951
need to run locally so that you can do initial login flow with a browser.
5052
Then copy <TARGET>/.gphotos.token to the server. For this
5153
first run you could use the following options so that no backup is performed:

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ install_requires =
3636
pyyaml>=4.2b1
3737
types-PyYAML
3838
psutil
39-
google-auth-oauthlib
39+
google-auth-oauthlib @ https://github.com/gilesknap/google-auth-library-python-oauthlib/archive/refs/tags/v0.5.2b1.zip
4040
types-requests
4141

4242
[options.extras_require]

src/gphotos_sync/Main.py

-4
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,6 @@ def __init__(self):
303303
type=int,
304304
default=8080,
305305
)
306-
parser.add_argument(
307-
"--host", help="hostname for the login flow redirect", default="localhost"
308-
)
309306
parser.add_help = True
310307

311308
def setup(self, args: Namespace, db_path: Path):
@@ -339,7 +336,6 @@ def setup(self, args: Namespace, db_path: Path):
339336
credentials_file,
340337
secret_file,
341338
int(args.max_retries),
342-
host=args.host,
343339
port=args.port,
344340
)
345341
self.auth.authorize()

src/gphotos_sync/authorize.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def __init__(
2323
token_file: Path,
2424
secrets_file: Path,
2525
max_retries: int = 5,
26-
host: str = "localhost",
2726
port: int = 8080,
2827
):
2928
"""A very simple class to handle Google API authorization flow
@@ -44,7 +43,6 @@ def __init__(
4443
self.session = None
4544
self.token = None
4645
self.secrets_file = secrets_file
47-
self.host = host
4846
self.port = port
4947

5048
try:
@@ -93,7 +91,10 @@ def authorize(self):
9391
flow = InstalledAppFlow.from_client_secrets_file(
9492
self.secrets_file, scopes=self.scope
9593
)
96-
flow.run_local_server(open_browser=False, host=self.host, port=self.port)
94+
# localhost and bind to 0.0.0.0 always works even in a container.
95+
flow.run_local_server(
96+
open_browser=False, bind_addr="0.0.0.0", port=self.port
97+
)
9798

9899
self.session = flow.authorized_session()
99100

tests/test_credentials/.gphotos.token

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +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"}
1+
{"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 commit comments

Comments
 (0)