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 #353 from gilesknap/dockerhub
Browse files Browse the repository at this point in the history
add dockerhub to ci
add --port and --host for redirect uri
  • Loading branch information
gilesknap authored May 17, 2022
2 parents eb3f9ad + 0b53e44 commit 3b986fa
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ VOLUME /config /storage

ENTRYPOINT ["gphotos-sync"]
CMD ["--version"]

EXPOSE 8080

2 changes: 1 addition & 1 deletion .devcontainer/local_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ echo building $container_name ...

# run the build with required build-args for a runtime build
ln -s ../dist .
podman build --build-arg BASE=python:3.10-slim -t $container_name .. --file ./Dockerfile
docker build --build-arg BASE=python:3.10-slim -t $container_name .. --file ./Dockerfile
unlink dist
13 changes: 11 additions & 2 deletions .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ jobs:
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Log in to GitHub Docker Registry
uses: docker/login-action@v1
with:
Expand All @@ -192,7 +198,10 @@ jobs:
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
images: |
ghcr.io/${{ github.repository }}
# github repo and dockerhub tag must match for this to work
${{ github.repository }}
# all pull requests share a single tag 'pr'
tags: |
type=ref,event=branch
Expand All @@ -209,7 +218,7 @@ jobs:
uses: docker/setup-buildx-action@v1

- name: Build runtime image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
file: .devcontainer/Dockerfile
context: .
Expand Down
17 changes: 17 additions & 0 deletions docs/how-to/windows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ As an alternative to typing the full path you can add the Scripts folder
to your path. See
https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/.

Using the installer downloadable from https://www.python.org/downloads/ will have
the same effect and includes a checkbox to add python to your Windows Path.

Virtual Environment
-------------------
It is recommended you create a virtual environment to run you python code in to
avoid messing up your root python install. In the below example we create a virtual
environment on the desktop. In the below example we assume that python has been
added to your window path variable as above.

- Create a new folder on your desktop called 'GPhotosSync'
- Hold shift and right click on your desktop and click 'Open PowerShell window here'
- type ``python -m venv GPhotosSync`` this will create a virtual environment
- next activate the environment using the command ``.\GPhotosSync\Scripts\activate.ps1``
- you can then install gphotos-sync using the command ``pip install gphotos-sync``
- You run it the same way as listed above. But now you need to activate the virtual environment every time you run it.

Symlinks
--------

Expand Down
9 changes: 7 additions & 2 deletions docs/tutorials/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ Hence the typical way to launch the container with docker runtime would be::
$ STORAGE=$HOME/My_photos_backup
$ docker run --rm -v $CONFIG:/config -v $STORAGE:/storage --net=host -it ghcr.io/gilesknap/gphotos-sync /storage

The option --net=host is required for the first invocation only, so that the
browser can find authentication service.
The options --net=host -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.

Note that 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.
Expand Down
20 changes: 18 additions & 2 deletions src/gphotos_sync/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self):
parser.add_argument(
"--compare-folder",
action="store",
help="root of the local folders to compare to the Photos Library",
help="DEPRECATED: root of the local folders to compare to the Photos Library",
)
parser.add_argument(
"--favourites-only",
Expand Down Expand Up @@ -239,13 +239,15 @@ def __init__(self):
parser.add_argument(
"--max-retries",
help="Set the number of retries on network timeout / failures",
type=int,
default=20,
)
parser.add_argument(
"--max-threads",
help="Set the number of concurrent threads to use for parallel "
"download of media - reduce this number if network load is "
"excessive",
type=int,
default=20,
)
parser.add_argument(
Expand Down Expand Up @@ -295,6 +297,15 @@ def __init__(self):
"the default value is `{0}-{1} {2}`",
default=None,
)
parser.add_argument(
"--port",
help="Set the port for login flow redirect",
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 @@ -324,7 +335,12 @@ def setup(self, args: Namespace, db_path: Path):
)

self.auth = Authorize(
scope, credentials_file, secret_file, int(args.max_retries)
scope,
credentials_file,
secret_file,
int(args.max_retries),
host=args.host,
port=args.port,
)
self.auth.authorize()

Expand Down
6 changes: 5 additions & 1 deletion src/gphotos_sync/authorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ 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
for the requests library. Includes saving the token and automatic
Expand All @@ -42,6 +44,8 @@ def __init__(
self.session = None
self.token = None
self.secrets_file = secrets_file
self.host = host
self.port = port

try:
with secrets_file.open("r") as stream:
Expand Down Expand Up @@ -89,7 +93,7 @@ def authorize(self):
flow = InstalledAppFlow.from_client_secrets_file(
self.secrets_file, scopes=self.scope
)
flow.run_local_server(open_browser=False)
flow.run_local_server(open_browser=False, host=self.host, 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_XfiNiGzh9enmSbl1vGGg5m9R5ncbyaPgXxU7BOpQ4ZADLtjTTyPLzTOy1bBaN-iAnyieHMYl3aXny-zp0oosViqJJwrh828a74bX6IAgjFT7DqgcBCWZz73XWrmPHY8qi83NhEiEL5lKFVQqxL0NQKA", "expires_in": 3599, "scope": ["https://www.googleapis.com/auth/photoslibrary.readonly", "https://www.googleapis.com/auth/photoslibrary.sharing"], "token_type": "Bearer", "expires_at": 1652634949.3542655, "refresh_token": "1//03CEqAzsnP-8PCgYIARAAGAMSNwF-L9Irz4_ilhRw0HIwVImT4gTCUPlV8YaCTYQiIjD4juWOI5eQh_-Rzh9nTmBND0jliOnabq4"}
{"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"}

0 comments on commit 3b986fa

Please sign in to comment.