Skip to content

Commit

Permalink
Port to Flask
Browse files Browse the repository at this point in the history
Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard committed Jun 13, 2024
1 parent 5303064 commit 6a7e0b5
Show file tree
Hide file tree
Showing 90 changed files with 3,876 additions and 4,212 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tahrir/templates
15 changes: 3 additions & 12 deletions .s2i/bin/assemble
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@
# places them into appropriate directories inside the image.

# Execute the default S2I script
/usr/libexec/s2i/assemble
. /usr/libexec/s2i/assemble

echo "---> Upgrade pip to the latest version ..."
pip install --upgrade pip

echo "---> Installing poetry ..."
pip install poetry

# Don't create virtual environments
poetry config virtualenvs.create false

echo "---> Installing application and dependencies ..."
poetry install --no-dev
# Now install the root project too, micropipenv does not do that
pip install . --no-deps

# set permissions for any installed artifacts
fix-permissions /opt/app-root -P
Expand Down
3 changes: 3 additions & 0 deletions .s2i/environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APP_MODULE=tahrir.app:create_app()
UPGRADE_PIP_TO_LATEST=true
ENABLE_MICROPIPENV=true
3 changes: 3 additions & 0 deletions babel.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[python: **.py]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.i18n,jinja2.ext.autoescape,jinja2.ext.with_
101 changes: 0 additions & 101 deletions devel/ansible/roles/dev/files/development.ini

This file was deleted.

3 changes: 0 additions & 3 deletions devel/ansible/roles/dev/files/secret.ini

This file was deleted.

25 changes: 25 additions & 0 deletions devel/ansible/roles/dev/files/tahrir.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file configuration values for development

SECRET_KEY = "development"
TEMPLATES_AUTO_RELOAD = True
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SECURE = False

SQLALCHEMY_DATABASE_URI = "sqlite:////home/vagrant/tahrir.db"
OIDC_CLIENT_SECRETS = "/home/vagrant/client_secrets.json"

TAHRIR_ADMIN_GROUPS = ["admins"]
TAHRIR_PNGS_PATH = "/home/vagrant/fedora-badges/pngs"
TAHRIR_USE_FEDMSG = False

TAHRIR_EMAIL_DOMAIN = "tinystage.test"
TAHRIR_FAS_URL = "https://auth.tinystage.test/noggin"

# Cache
CACHE = {
"backend": "dogpile.cache.dbm",
"expiration_time": 10000,
"arguments": {
"filename": "/home/vagrant/cachefile.dbm",
},
}
6 changes: 5 additions & 1 deletion devel/ansible/roles/dev/files/tahrir.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ Wants=network-online.target
[Service]
AmbientCapabilities = CAP_NET_BIND_SERVICE
Environment=REQUESTS_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt
Environment=FLASK_CONFIG=/home/vagrant/tahrir.cfg
Environment=PYTHONUNBUFFERED=1
Environment=FLASK_DEBUG=1
Environment=FLASK_APP=/home/vagrant/tahrir/tahrir/app.py
User=vagrant
WorkingDirectory=/home/vagrant/tahrir
ExecStart=poetry run pserve --reload /home/vagrant/development.ini
ExecStart=poetry run flask run --reload -p 443 -h "0.0.0.0" --cert=/etc/pki/tls/certs/server.pem --key=/etc/pki/tls/private/server.key

[Install]
WantedBy=multi-user.target
58 changes: 18 additions & 40 deletions devel/ansible/roles/dev/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,75 +11,53 @@
- name: configure fedora-messaging to point at tinystage rabbitmq
lineinfile:
path: /etc/fedora-messaging/config.toml
regexp: "amqp_url = \"amqp://\""
line: "amqp_url = \"amqp://fedoramessages:[email protected]\"" # gitleaks:allow
regexp: 'amqp_url = "amqp://"'
line: 'amqp_url = "amqp://fedoramessages:[email protected]"' # gitleaks:allow

- name: Setup development instance of tahrir
command: poetry install
become: yes
become_user: vagrant
args:
chdir: /home/vagrant/tahrir

- name: copy the developemnt.ini file
copy:
src: development.ini
dest: /home/vagrant/development.ini
mode: 0644
owner: vagrant
group: vagrant


- name: read client_secrets.json
register: client_secrets_json
ansible.builtin.slurp:
path: /home/vagrant/client_secrets.json

- name: extract stuff from client_secrets.json
set_fact:
client_secrets: "{{ client_secrets_json.content |b64decode | from_json }}"

- name: Update development.ini
lineinfile:
dest: /home/vagrant/development.ini
line: "oidc.fedora.client_id = {{client_secrets.web.client_id}}"
owner: vagrant

- name: Update development.ini
lineinfile:
dest: /home/vagrant/development.ini
line: "oidc.fedora.client_secret = {{client_secrets.web.client_secret}}"
owner: vagrant

chdir: /home/vagrant/tahrir

- name: copy the secret.ini and alembic.ini files
- name: copy the config files
copy:
src: "{{ item }}"
dest: /home/vagrant/{{ item }}
mode: 0644
owner: vagrant
group: vagrant
loop:
- secret.ini
- tahrir.cfg
- alembic.ini

- name: get the fedora badges
git:
repo: https://pagure.io/fedora-badges.git
dest: /home/vagrant/fedora-badges

- name: load the fedora badges in the DB
command: poetry run python ./devel/load-badges.py /home/vagrant/development.ini
- name: Create or update the database
command: poetry run flask tahrir sync-db
environment:
FLASK_CONFIG: /home/vagrant/tahrir.cfg
FLASK_APP: /home/vagrant/tahrir/tahrir/app.py
FLASK_DEBUG: 1
become: yes
become_user: vagrant
args:
chdir: /home/vagrant/tahrir

- command: poetry run sync_tahrir_db /home/vagrant/development.ini
- name: load the fedora badges in the DB
command: poetry run flask tahrir load-badges
environment:
FLASK_CONFIG: /home/vagrant/tahrir.cfg
FLASK_APP: /home/vagrant/tahrir/tahrir/app.py
FLASK_DEBUG: 1
become: yes
become_user: vagrant
args:
chdir: /home/vagrant/tahrir
chdir: /home/vagrant/tahrir

- name: Install the systemd unit files for tahrir service
copy:
Expand Down
86 changes: 0 additions & 86 deletions devel/load-badges.py

This file was deleted.

2 changes: 1 addition & 1 deletion fedora-sitedocs/about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Fedora Badges
How does Badges work?
---------------------

It's really easy! Just `sign in to Badges <https://badges.fedoraproject.org/login>`_ with your `Fedora account <https://admin.fedoraproject.org/accounts/>`_, and you'll see you have at least one badge right away. Congratulations - you're a Badger! If you participate in Fedora in any way, you'll probably notice Badges popping up on your profile as you go about your business, though sadly we don't cover every area of Fedora yet - we're doing our best to make sure we reward as many forms of participation as we can!
It's really easy! Just `sign in to Badges <https://badges.fedoraproject.org/oidc/login>`_ with your `Fedora account <https://admin.fedoraproject.org/accounts/>`_, and you'll see you have at least one badge right away. Congratulations - you're a Badger! If you participate in Fedora in any way, you'll probably notice Badges popping up on your profile as you go about your business, though sadly we don't cover every area of Fedora yet - we're doing our best to make sure we reward as many forms of participation as we can!

Want to see how your badge collection compares with others? Check the `Leaderboard <https://badges.fedoraproject.org/leaderboard>`_. Jonesing for more badges? You can check the `Badge index <https://badges.fedoraproject.org/explore/badges>`_ to see all the badges and get to work on your collection! Click on a badge to see how to get it - but
we intentionally didn't spell it all out exactly. Part of the fun is figuring it out!
Expand Down
Loading

0 comments on commit 6a7e0b5

Please sign in to comment.