Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
24bd073
Create new copydoc file if webpage is new
samhotep Sep 30, 2024
1cdd670
conditionally create a new folder
samhotep Sep 30, 2024
d5a58aa
Fixed linter issues
samhotep Sep 30, 2024
dc95eea
Updated requirements
samhotep Sep 30, 2024
f09f131
Put copydoc in subfolder
samhotep Sep 30, 2024
5488028
Use hardcoded values for the google drive folder and copydoc template
samhotep Sep 30, 2024
db773b6
Store credentials in a temp file
samhotep Sep 30, 2024
afaee11
Moved google creds to env variable
samhotep Oct 1, 2024
c8246a6
Use demo database URL
samhotep Oct 1, 2024
4311ff9
Reformat site.yaml
samhotep Oct 1, 2024
faf111b
Point production to dedicated db
samhotep Oct 1, 2024
ee921a3
Removed secret key definition
samhotep Oct 2, 2024
02682bb
Updated demo secrets
samhotep Oct 2, 2024
33a37be
Moved drive env variables to settings
samhotep Oct 2, 2024
3f22c42
Removed redundant code
samhotep Oct 2, 2024
1ee286d
Updated google drive module
samhotep Oct 7, 2024
a0047b2
Use physical creds
samhotep Oct 7, 2024
13eb0f5
Removed service account env variable
samhotep Oct 7, 2024
c1ce393
Pass only private key as env
samhotep Oct 8, 2024
471bd36
declared env variables explicitly for python ci
samhotep Oct 8, 2024
c401f38
dont duplicate subfolders
samhotep Oct 8, 2024
ce84b45
Added private key to demo
samhotep Oct 8, 2024
39db5be
Returned file url after copydoc creation
samhotep Oct 8, 2024
99410c0
Use explicit naming for private keys
samhotep Oct 8, 2024
e410d2b
Merge branch 'main' into create-copydocs-endpoint
samhotep Oct 8, 2024
3447d26
Update CI.yml
samhotep Oct 8, 2024
1642cbe
Added env variables to playwright
samhotep Oct 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ VALKEY_HOST=localhost
VALKEY_PORT=6379
GH_TOKEN=token
REPO_ORG=https://github.com/canonical
SQLALCHEMY_DATABASE_URI=postgresql://postgres:postgres@localhost:5432/postgres
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/content
TASK_DELAY=30
DIRECTORY_API_TOKEN=token
JIRA_EMAIL=email@example.com
JIRA_TOKEN=token
JIRA_URL=https://warthogs.atlassian.net
JIRA_LABELS=sites_BAU
JIRA_COPY_UPDATES_EPIC=KAN-1
GOOGLE_CREDENTIALS=googlecreds
GOOGLE_DRIVE_FOLDER_ID=googlecreds
COPYD0C_TEMPLATE_ID=googlecreds
GOOGLE_PRIVATE_KEY=base64encodedprivatekey
GOOGLE_PRIVATE_KEY_ID=privatekeyid
28 changes: 24 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,23 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run service
env:
GOOGLE_PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
GOOGLE_PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }}
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
SECRET_KEY: secret_key
VALKEY_HOST: localhost
VALKEY_PORT: 6379
GH_TOKEN: token
REPO_ORG: https://github.com/canonical
JIRA_EMAIL: example@canonical.com
JIRA_TOKEN: jiratoken
JIRA_URL: https://example.atlassian.net
JIRA_LABELS: somelabel
JIRA_COPY_UPDATES_EPIC: WD-9999999
GOOGLE_DRIVE_FOLDER_ID: folderid
COPYDOC_TEMPLATE_ID: templateid
run: |
set -a
source .env
set +a
talisker.gunicorn webapp.app:app --daemon --bind 0.0.0.0:8104
curl --head --fail --retry-delay 1 --retry 30 --retry-connrefused http://localhost:8104

Expand Down Expand Up @@ -150,6 +163,9 @@ jobs:
run: DOCKER_BUILDKIT=1 docker build --tag websites-content-system .

- name: Run image
env:
GOOGLE_PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
GOOGLE_PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }}
run: |
docker run \
-p 8104:8104 \
Expand All @@ -158,12 +174,16 @@ jobs:
-e VALKEY_PORT=6379 \
-e GH_TOKEN=token \
-e REPO_ORG=https://github.com/canonical \
-e SQLALCHEMY_DATABASE_URI=postgresql://postgres:postgres@localhost:5432/postgres \
-e DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres \
-e JIRA_EMAIL=example@canonical.com \
-e JIRA_TOKEN=jiratoken \
-e JIRA_URL=https://example.atlassian.net \
-e JIRA_LABELS=somelabel \
-e JIRA_COPY_UPDATES_EPIC=WD-9999999 \
-e GOOGLE_DRIVE_FOLDER_ID=folderid \
-e COPYDOC_TEMPLATE_ID=templateid \
-e GOOGLE_PRIVATE_KEY="$GOOGLE_PRIVATE_KEY" \
-e GOOGLE_PRIVATE_KEY_ID="$GOOGLE_PRIVATE_KEY_ID" \
--network host \
websites-content-system & sleep 1
curl --head --fail --retry-delay 1 --retry 30 --retry-connrefused http://localhost
11 changes: 10 additions & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ jobs:
VALKEY_PORT: 6379
GH_TOKEN: token
REPO_ORG: https://github.com/canonical
SQLALCHEMY_DATABASE_URI: postgresql://postgres:postgres@localhost:5432/postgres
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
GOOGLE_PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
GOOGLE_PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }}
JIRA_EMAIL: example@canonical.com
JIRA_TOKEN: jiratoken
JIRA_URL: https://example.atlassian.net
JIRA_LABELS: somelabel
JIRA_COPY_UPDATES_EPIC: WD-9999999
GOOGLE_DRIVE_FOLDER_ID: folderid
COPYDOC_TEMPLATE_ID: templateid
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Backend service for the CMS template parser

Before starting, update the environment variables if needed. The default values will work for docker, save the `GH_TOKEN` which must be manually set. You can create a token [here](https://github.com/settings/tokens), by following [these](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) instructions. Make sure to select the `repo` scope for the token.

You will also require a credentials file for google drive. Please store it as credentials.json in the `credentials` directory.

```env
PORT=8104
FLASK_DEBUG=true
Expand All @@ -16,6 +18,19 @@ DEVEL=True
VALKEY_HOST=0.0.0.0
VALKEY_PORT=6379
GH_TOKEN=ghp_somepersonaltoken
REPO_ORG=https://github.com/canonical
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/content
TASK_DELAY=30
DIRECTORY_API_TOKEN=token
JIRA_EMAIL=example@canonical.com
JIRA_TOKEN=jiratoken
JIRA_URL=https://warthogs.atlassian.net
JIRA_LABELS=sites_BAU
JIRA_COPY_UPDATES_EPIC=WD-12643
GOOGLE_DRIVE_FOLDER_ID=1EIFOGJ8DIWpsYIfWk7Yos3YijZIkbJDk
COPYD0C_TEMPLATE_ID=125auRsLQukYH-tKN1oEKaksmpCXd_DTGiswvmbeS2iA
GOOGLE_PRIVATE_KEY=base64encodedprivatekey
GOOGLE_PRIVATE_KEY_ID=privatekeyid
```

### Using docker
Expand Down
101 changes: 94 additions & 7 deletions konf/site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ env:
key: github
name: webteam-valkey

- name: SECRET_KEY
secretKeyRef:
key: websites-content-system
name: secret-keys

- name: DIRECTORY_API_TOKEN
secretKeyRef:
key: token
Expand All @@ -31,12 +26,12 @@ env:
- name: JIRA_EMAIL
secretKeyRef:
key: jira-email
name: cms-jira
name: cs-canonical-com

- name: JIRA_TOKEN
secretKeyRef:
key: jira-token
name: cms-jira
name: cs-canonical-com

- name: JIRA_URL
value: "https://warthogs.atlassian.net"
Expand All @@ -47,16 +42,108 @@ env:
- name: JIRA_COPY_UPDATES_EPIC
value: "WD-12643"

- name: GOOGLE_DRIVE_FOLDER_ID
secretKeyRef:
key: google-drive-folder-id
name: cs-canonical-com

- name: COPYDOC_TEMPLATE_ID
secretKeyRef:
key: copydoc-template-id
name: cs-canonical-com

- name: GOOGLE_PRIVATE_KEY
secretKeyRef:
key: google-private-key
name: cs-canonical-com

- name: GOOGLE_PRIVATE_KEY_ID
secretKeyRef:
key: google-private-key-id
name: cs-canonical-com

# Overrides for production
production:
replicas: 1
nginxConfigurationSnippet: |
more_set_headers "X-Robots-Tag: noindex";
more_set_headers "Link: <https://assets.ubuntu.com>; rel=preconnect; crossorigin, <https://assets.ubuntu.com>; rel=preconnect";
env:
- name: DATABASE_URL
secretKeyRef:
key: websites-content-system
name: database-urls

# Overrides for staging
staging:
replicas: 1
nginxConfigurationSnippet: |
more_set_headers "X-Robots-Tag: noindex";
more_set_headers "Link: <https://assets.ubuntu.com>; rel=preconnect; crossorigin, <https://assets.ubuntu.com>; rel=preconnect";
env:
- name: DATABASE_URL
secretKeyRef:
key: websites-content-system
name: database-urls

# Overrides for demos
demo:
env:
- name: VALKEY_HOST
secretKeyRef:
key: host
name: webteam-valkey

- name: VALKEY_PORT
secretKeyRef:
key: port
name: webteam-valkey

- name: GH_TOKEN
secretKeyRef:
key: github
name: webteam-valkey

- name: DIRECTORY_API_TOKEN
secretKeyRef:
key: token
name: directory-api

- name: JIRA_EMAIL
secretKeyRef:
key: jira-email
name: cs-canonical-com

- name: JIRA_TOKEN
secretKeyRef:
key: jira-token
name: cs-canonical-com

- name: JIRA_URL
value: "https://warthogs.atlassian.net"

- name: JIRA_LABELS
value: "sites_BAU"

- name: JIRA_COPY_UPDATES_EPIC
value: "WD-12643"

- name: GOOGLE_DRIVE_FOLDER_ID
secretKeyRef:
key: google-drive-folder-id
name: cs-canonical-com

- name: COPYDOC_TEMPLATE_ID
secretKeyRef:
key: copydoc-template-id
name: cs-canonical-com

- name: GOOGLE_PRIVATE_KEY
secretKeyRef:
key: google-private-key
name: cs-canonical-com

- name: GOOGLE_PRIVATE_KEY_ID
secretKeyRef:
key: google-private-key-id
name: cs-canonical-com
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ click==8.1.7
django-openid-auth==0.17
Flask==2.3.3
Flask-OpenID==1.3.1
google-api-python-client==2.78.0
itsdangerous==2.2.0
Jinja2==3.1.4
MarkupSafe==2.1.5
Expand Down
4 changes: 4 additions & 0 deletions webapp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from webapp.cache import init_cache
from webapp.context import base_context
from webapp.gdrive import init_gdrive
from webapp.jira import init_jira
from webapp.models import init_db
from webapp.sso import init_sso
Expand Down Expand Up @@ -30,4 +31,7 @@ def create_app():
# Initialize JIRA
init_jira(app)

# Initialize gdrive
init_gdrive(app)

return app
5 changes: 3 additions & 2 deletions webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ def request_changes(body: ChangesRequestModel):

# Make a request to JIRA to create a task
try:
create_jira_task(app, body.model_dump())
task = create_jira_task(app, body.model_dump())
task_url = f"https://docs.google.com/document/d/{task['id']}"
except Exception as e:
return jsonify(str(e)), 500

return jsonify("Task created successfully"), 201
return jsonify({"message": f"Task created successfully\n{task_url}"}), 201


@app.route("/get-jira-tasks/<webpage_id>", methods=["GET"])
Expand Down
Loading
Loading