From e1d8873e67abf94ef88cdb3d9866a71f33590a20 Mon Sep 17 00:00:00 2001 From: Luka Kroeger Date: Thu, 28 Oct 2021 21:47:48 +0200 Subject: [PATCH 1/3] fix: use user home with new config --- Dockerfile | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 268a89d..21c57f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,18 @@ -FROM python:3.9 +FROM python:3.9-slim ENV USER worker -ENV WORKDIR /app -ENV PATH "${WORKDIR}/${USER}/.local/bin:${PATH}" +ENV PATH "/home/${USER}/.local/bin:${PATH}" +RUN useradd -m $USER --shell /bin/bash -RUN useradd -m $USER -b $WORKDIR --shell /bin/bash - -WORKDIR $WORKDIR +WORKDIR /home/$USER COPY . . -RUN chown -R $USER:$USER $WORKDIR - - USER $USER RUN pip install --no-cache-dir --upgrade pip RUN pip install -r requirements.txt -ENV PYTHONPATH $WORKDIR +ENV PYTHONPATH "/home/$USER" ENTRYPOINT ["python", "notion_gcal_sync/__main__.py"] From c1f5e9ef34657a0237c3dfb6e440088c2c8ff0c4 Mon Sep 17 00:00:00 2001 From: Luka Kroeger Date: Thu, 28 Oct 2021 22:31:45 +0200 Subject: [PATCH 2/3] docs: Update docs for docker usage and update setup --- README.md | 90 +++++++++++++++++++++++++++++++++++++++++---------- docs/setup.md | 56 +++----------------------------- 2 files changed, 77 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index bdcbf5a..7d9b64e 100644 --- a/README.md +++ b/README.md @@ -9,37 +9,95 @@ Notion-GCal-Sync is a python application to bidirectional synchronize calendar e ## Getting started -Follow [these instructions](https://github.com/Ravio1i/notion-gcal-sync/blob/main/docs/setup.md). +1. Install package from [PyPi](https://pypi.org/project/notion-gcal-sync/) + + ```bash + pip install notion-gcal-sync + ``` + +2. Get your Google Calendar `credentials.json` [like this](https://github.com/Ravio1i/notion-gcal-sync/blob/main/docs/setup.md#setup-credentials-for-google-calendar) +3. Get your Notion Token [like this](https://github.com/Ravio1i/notion-gcal-sync/blob/main/docs/setup.md#setup-credentials-for-notion) +4. Set up the Notion page [like this]((https://github.com/Ravio1i/notion-gcal-sync/blob/main/docs/setup.md#setup-up-your-notion-page)) +5. Create config folder `~/.notion-gcal-sync` and copy the `credentials.json` inside + + **Linux (or WSL)** + ```bash + cp ~/Downloads/client_secret_*.apps.googleusercontent.com.json "~/.notion-gcal-sync/client_secret.json" + ``` + + **Windows** + Copy your `client_secret_*.apps.googleusercontent.com.json` as `client_secret.json` inside `C:\Users\dude\.notion-gcal-sync` + ```powershell + # TODO + ``` + + +6. Run the script and fill out the prompts. If not sure skip the optional bits. + 1. Make [sure you get your timezone right](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) + 1. Use your TZ database name as `timezone_name` + 2. Use the UTC DST offset as `timezone_diff` + 2. `google_mail`: Your mail you are using in google calendar want to have synced + 3. `notion_database_url` The url for the page you set up in 4. + 4. `notion_token`: The token you set up in 3. + + ```bash + notion-gcal-sync + + 2021-10-28 19:55:41,198 [INFO] /home/worker/.notion-gcal-sync/config.yml does not exist + Create non-existing /home/worker/.notion-gcal-sync/config.yml? [Y/n]: y + 2021-10-28 19:55:42,630 [INFO] Configuring /home/worker/.notion-gcal-sync/config.yml + default_event_length [60]: + no_date_action [skip]: + timezone_name [Europe/Berlin]: + timezone_diff [+02:00]: + google_mail (e.g name@gmail.com): cooldude@gmail.com + notion_database_url [https://www.notion.so/***?v=***&p=]: + notion_token: secret_ASDFASDFCASDF + ``` + +7. It will prompt you to authenticate yourself for google. This will create a `token.json`. + + ```bash + $ notion-gcal-sync + ... + Please visit this URL to authorize this application: + https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=*** + ``` + +For more information follow [these instructions](https://github.com/Ravio1i/notion-gcal-sync/blob/main/docs/setup.md). ## Usage -**IMPORTANT:** Make sure you followed the [setup](https://github.com/Ravio1i/notion-gcal-sync/blob/main/docs/setup.md) and +Make sure you followed the [setup](https://github.com/Ravio1i/notion-gcal-sync/blob/main/docs/setup.md) and configured the `config.yml` with your notion token and page for Notion API and gathered and setup credentials `client_secret.json` for Google Calendar API. -From pip and running directly - ```bash notion-gcal-sync ``` -With docker (Not the mounting of `client_secret.json` and `config.yml`) +### Docker +To run inside the container you need to add the volume at `~/.notion-gcal-sync` + +```yaml +docker run -v ~/.notion-gcal-sync:/home/worker/.notion-gcal-sync notion-gcal-sync +``` + + +If you want to update the setup within the cli or only map the credentials, you'll need to add interactive mode `-it` and for authenticating a new token you'll also need `--net=host` ```yaml docker run --net=host -it \ - -v $(pwd)/config.yml:/app/notion_gcal_sync/config.yml \ - -v $(pwd)/client_credentials.json:/app/notion_gcal_sync/client_credentials.json \ - notion-gcal-sync + -v ~/.notion-gcal-sync/client_credentials.json:/home/worker/notion-gcal-sync/client_credentials.json \ + notion-gcal-sync ``` -On first run or when token is old you will be asked to authorize the application. Follow the link and authorize with your -account. After authorization the application will continue. +If you do not want to mount, build it yourself with your credentials. -```bash -$ notion-gcal-sync -... -Please visit this URL to authorize this application: -https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=*** +```Dockerfile +FROM ghrc.io/ravio1i/notion-gcal-sync +COPY token.json /home/worker/token.json +COPY config.yml /home/worker/config.json ``` ## Notes @@ -54,8 +112,6 @@ BE AWARE OF THE FOLLOWING: * Recurrent original events are skipped. Recurrent occurrences of events are created one by one in notion. Changing in notion will change only an occurrence in GCal. -## Notes - With around ~2500 events in gcal the sync: * to get all events took ~1min diff --git a/docs/setup.md b/docs/setup.md index d8c53a6..5b15b9a 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -18,27 +18,13 @@ docker pull ghrc.io/ravio1i/notion-gcal-sync ## Configuration -Additionally, to installing the python package you will need to properly configure and authenticate. This requires the 2 files: +Additionally, to installing the python package you will need to properly configure and authenticate. +This requires the 2 files in your user home `~/.notion-gcal-sync` (`C:\Users\dude\.notion-gcal-sync`) * `config.yml` * `client_secret.yml` -The default `config.yml` is included in the installation and can be found in its python library directory. This file will be -configured in the following setup. To get the location of your `config.yml`: - -* Linux (or WSL): - ```bash - NOTION_GCAL_SYNC_LIB="$(pip list -v [--user] | grep notion-gcal-sync | awk '{print $3}')/notion_gcal_sync" - ls $NOTION_GCAL_SYNC_LIB - ``` - -* Windows: - - Search where your Python library got installed. - ```powershell - # TODO - ``` - +The default `config.yml` is included in the installation and can be found in the repo root. If no `config.yml` exists in the `~/.notion-gcal-sync` folder you'll be prompted on the next run of the application. ## Setup credentials for Google Calendar The following is a summary of [this](https://developers.google.com/workspace/guides/create-credentials) and will get you the @@ -72,22 +58,6 @@ credentials for authenticating against your Google calendar. The `token.json` will store the user's access and refresh tokens as json and is created automatically when the authorization flow completes for the first time. -10. Move your credentials into this folder as `client_secret.json`. - - **Linux (or WSL)** - ```bash - NOTION_GCAL_SYNC_LIB="$(pip list -v | grep notion-gcal-sync | awk '{print $3}')/notion_gcal_sync" - cp client_secret_*.apps.googleusercontent.com.json "$NOTION_GCAL_SYNC_LIB/client_secret.json" - ``` - - **Windows** - - Search where your Python library got installed and copy your `client_secret_*.apps.googleusercontent.com.json` - as `client_secret.json`. inside - ```powershell - # TODO - ``` - ## Setup credentials for Notion The following is a summary of [this](https://developers.notion.com/docs/authorization) and will set up your notion integration @@ -96,13 +66,7 @@ to authenticate this application for notion. 1. Navigate to [Notion Integrations](https://www.notion.so/my-integrations). 2. Click `Create new integration` and give it name, like `notion-gcal-sync`. 3. On the page of the integration copy the contents of your `Internal Integration Token`. -4. Insert your token data in your `config.yml`: - ```yaml - ... - notion: - ... - token: '***' - ``` + ### Set up your Notion page @@ -115,17 +79,6 @@ to authenticate this application for notion. 2. Click `Share` in the top right corner of your duplicated page and `Invite` your [Notion Integration](#setup-credentials-for-notion) with `Can edit` . -3. Copy the URL of your duplicated page and add it to your `config.yml`. - - **Append a `&p=` to the URL.** - - ```yaml - ... - notion: - notion_url: https://www.notion.so/[subdomain]/***?v=***&p= - token: '***' - ``` - ## Integrate your google calendars 1. Navigate to [Google Calendar](https://calendar.google.com) and go to Settings. @@ -149,7 +102,6 @@ to authenticate this application for notion. ### Columns -Automatic: You should not change these values yourself! * `Name (text)`: The name (summary) of an event. * `Date (date)`: The date of the event. If nothing is specified the `no_date_action` will be used. From 0a25272bda56d28544d6aae496d77941e1a90604 Mon Sep 17 00:00:00 2001 From: Luka Kroeger Date: Thu, 28 Oct 2021 22:44:24 +0200 Subject: [PATCH 3/3] ci: try again to add version to docker ci --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 484840b..2cef63a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,10 +85,12 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{raw}} type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}}.{{minor}}.{{patch}} flavor: | - latest=auto + latest=true - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc