Skip to content

Commit

Permalink
Merge pull request #32 from antonplagemann/development
Browse files Browse the repository at this point in the history
v4.0.0 Added docker support
  • Loading branch information
antonplagemann committed Dec 22, 2021
2 parents 7c63dc4 + 5b4d268 commit caae23b
Show file tree
Hide file tree
Showing 44 changed files with 5,131 additions and 2,541 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.github
**/.git
**/.gitignore
**/.vscode
**/__pycache__
**/logs/*
**/data/*
*.properties
*.bat
*.json
*.pickle
*.log
*.db
*.md
*.yml
**/conf.py
data
logs
test
.mypy_cache
Dockerfile
.env
.env.example
.pylintrc
.dockerignore
38 changes: 38 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Example config file with every option
# Separate multiple values with comma

# -------------Required-----------------------
# Your Monica api token (without 'Bearer ')
TOKEN=YOUR_TOKEN_HERE

# -------------Optional-----------------------
# Your Monica base url
BASE_URL=https://app.monicahq.com/api

# Create reminders for birthdays and deceased days?
CREATE_REMINDERS=True
# Delete Monica contact if the corresponding Google contact has been deleted?
DELETE_ON_SYNC=True
# Do a street reversal in address sync if the first character is a number?
# (e.g. from '13 Auenweg' to 'Auenweg 13')
STREET_REVERSAL=False

# What fields should be synced? (both directions)
# Names and birthday are mandatory
FIELDS=career,address,phone,email,labels,notes

# Define contact labels/tags/groups you want to include or exclude from sync.
# Exclude labels have the higher priority.
# Both lists empty means every contact is included
# Example: 'GOOGLE_LABELS_INCLUDE=Family,My Friends' will only process contacts labeled as 'Family' or 'My Friends'.
# Applies for Google -> Monica sync
GOOGLE_LABELS_INCLUDE=
GOOGLE_LABELS_EXCLUDE=
# Applies for Monica -> Google sync back
MONICA_LABELS_INCLUDE=
MONICA_LABELS_EXCLUDE=

# Define custom file paths
DATABASE_FILE=data/syncState.db
GOOGLE_TOKEN_FILE=data/token.pickle
GOOGLE_CREDENTIALS_FILE=data/credentials.json
30 changes: 30 additions & 0 deletions .github/actions/cleanup-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'Cleanup test environment'
description: 'Restores changed Google contacts and renames log files'

inputs:
TEST_RUNNER:
description: 'The system used to run the scripts (python/docker)'
required: true
REPO_TOKEN:
description: 'A GitHub Personal Access token with repo scope'
required: true

runs:
using: "composite"
steps:
- name: Restore original data
run: python test/ChaosMonkey.py --restore
shell: bash

- name: Rename log files
run: |
mv logs/monkey.log logs/${{ inputs.TEST_RUNNER }}_monkey.log
mv logs/setup.log logs/${{ inputs.TEST_RUNNER }}_setup.log
mv data/syncState.db data/${{ inputs.TEST_RUNNER }}_syncState.db
shell: bash

- name: Upload Google token to repo secrets
run: python test/UpdateToken.py
env:
REPO_TOKEN: ${{ inputs.REPO_TOKEN }}
shell: bash
64 changes: 64 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: 'Setup test environment'
description: 'Sets up a new Monica instance, installs dependencies, and creates/retrieves sync tokens'

inputs:
GOOGLE_TOKEN:
description: The token.pickle file content (base64 encoded string)
required: true
MONICA_URL:
required: false
default: http://localhost:8080/api
CREATE_REMINDERS:
required: true
DELETE_ON_SYNC:
required: true
STREET_REVERSAL:
required: true
FIELDS:
required: true
GOOGLE_LABELS_INCLUDE:
required: true
GOOGLE_LABELS_EXCLUDE:
required: true
MONICA_LABELS_INCLUDE:
required: true
MONICA_LABELS_EXCLUDE:
required: true

runs:
using: "composite"
steps:
- name: Start new Monica instance
run: docker-compose -f test/docker-compose-monica.yml up -d
shell: bash

- name: Create env file
run: |
touch .env data/token.pickle
echo "${{ inputs.GOOGLE_TOKEN }}" >> data/token.pickle
echo BASE_URL="${{ inputs.MONICA_URL }}" >> .env
echo CREATE_REMINDERS="${{ inputs.CREATE_REMINDERS || true }}" >> .env
echo DELETE_ON_SYNC="${{ inputs.DELETE_ON_SYNC || true }}" >> .env
echo STREET_REVERSAL="${{ inputs.STREET_REVERSAL || false }}" >> .env
echo FIELDS="${{ inputs.FIELDS || 'career,address,phone,email,labels,notes' }}" >> .env
echo GOOGLE_LABELS_INCLUDE="${{ inputs.GOOGLE_LABELS_INCLUDE }}" >> .env
echo GOOGLE_LABELS_EXCLUDE="${{ inputs.GOOGLE_LABELS_EXCLUDE }}" >> .env
echo MONICA_LABELS_INCLUDE="${{ inputs.MONICA_LABELS_INCLUDE }}" >> .env
echo MONICA_LABELS_EXCLUDE="${{ inputs.MONICA_LABELS_EXCLUDE }}" >> .env
shell: bash

- name: Install requirements
run: python -m pip install --upgrade pip && pip install -r requirements.txt -r test/requirements.txt
shell: bash

- name: Create API token at Monica instance
run: python test/SetupToken.py
shell: bash

- name: Create database file and monkey state
run: python test/ChaosMonkey.py
shell: bash

- name: Set folder permissions for non-root containers
run: sudo chmod 777 data logs -R
shell: bash
37 changes: 37 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "CodeQL"

on:
push:
branches:
- main
pull_request:
types: ['opened', 'reopened', 'synchronize']
schedule:
- cron: '31 0 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
41 changes: 41 additions & 0 deletions .github/workflows/docker-cd-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Docker Release CD

on:
release:
types: [published]

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: "Create tags for Docker image"
id: docker_meta
uses: docker/metadata-action@v3.6.1
with:
tag-latest: true
images: antonplagemann/google-monica-sync
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
no-cache: true
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
35 changes: 35 additions & 0 deletions .github/workflows/docker-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Docker CD

on:
push:
branches:
- main

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
no-cache: true
push: true
tags: antonplagemann/google-monica-sync:latest
Loading

0 comments on commit caae23b

Please sign in to comment.