Browse Source

Add Docker provider for Vagrant development environment

See merge request tildes-community/tildes-cf!1
develop
talklittle 1 month ago
committed by Andrew Shu
parent
commit
e0104773a5
  1. 33
      Vagrantfile
  2. 14
      ansible/playbook.yml
  3. 2
      ansible/requirements.yml
  4. 12
      ansible/roles/boussole/tasks/main.yml
  5. 2
      ansible/roles/consumers/tasks/main.yml
  6. 4
      ansible/roles/cronjobs/tasks/main.yml
  7. 15
      ansible/roles/gunicorn/tasks/main.yml
  8. 2
      ansible/roles/java/tasks/main.yml
  9. 2
      ansible/roles/nginx/handlers/main.yml
  10. 39
      ansible/roles/nginx/tasks/main.yml
  11. 15
      ansible/roles/nodejs/tasks/main.yml
  12. 2
      ansible/roles/pgbouncer/handlers/main.yml
  13. 13
      ansible/roles/pgbouncer/tasks/main.yml
  14. 2
      ansible/roles/postgresql/defaults/main.yml
  15. 8
      ansible/roles/postgresql/handlers/main.yml
  16. 29
      ansible/roles/postgresql/tasks/main.yml
  17. 10
      ansible/roles/postgresql/tasks/reload.yml
  18. 10
      ansible/roles/postgresql/tasks/restart.yml
  19. 2
      ansible/roles/postgresql_redis_bridge/tasks/main.yml
  20. 1
      ansible/roles/postgresql_tildes_dbs/tasks/main.yml
  21. 2
      ansible/roles/prometheus/handlers/main.yml
  22. 2
      ansible/roles/prometheus/tasks/main.yml
  23. 12
      ansible/roles/prometheus_node_exporter/tasks/main.yml
  24. 2
      ansible/roles/prometheus_postgres_exporter/tasks/main.yml
  25. 2
      ansible/roles/prometheus_redis_exporter/tasks/main.yml
  26. 2
      ansible/roles/python/tasks/main.yml
  27. 2
      ansible/roles/redis/handlers/main.yml
  28. 7
      ansible/roles/redis/tasks/main.yml
  29. 14
      ansible/roles/redis_module_cell/tasks/main.yml
  30. 3
      ansible/roles/self_signed_ssl_cert/meta/main.yml
  31. 3
      ansible/roles/self_signed_ssl_cert/tasks/main.yml
  32. 2
      ansible/roles/webassets/tasks/main.yml
  33. 4
      ansible/vars.yml
  34. 33
      docker/Dockerfile-for-vagrant
  35. 6851
      docker/systemctl3.py
  36. 12
      tildes/requirements-dev.txt
  37. 4
      tildes/requirements.txt
  38. 2
      tildes/scripts/initialize_db.py
  39. 2
      tildes/tests/test_ratelimit.py
  40. 2
      tildes/tildes/__init__.py
  41. 4
      tildes/tildes/models/database_model.py

33
Vagrantfile

@ -4,8 +4,7 @@
VAGRANT_CONFIG_VERSION = "2" VAGRANT_CONFIG_VERSION = "2"
Vagrant.configure(VAGRANT_CONFIG_VERSION) do |config| Vagrant.configure(VAGRANT_CONFIG_VERSION) do |config|
# Using the "contrib" version for vboxsf module for synced folders
config.vm.box = "debian/contrib-buster64"
config.vm.box = "debian/bookworm64"
# Main application folder # Main application folder
config.vm.synced_folder "tildes/", "/opt/tildes/" config.vm.synced_folder "tildes/", "/opt/tildes/"
@ -16,18 +15,11 @@ Vagrant.configure(VAGRANT_CONFIG_VERSION) do |config|
config.vm.network "forwarded_port", guest: 9090, host: 9090 config.vm.network "forwarded_port", guest: 9090, host: 9090
config.vm.provision "ansible_local" do |ansible| config.vm.provision "ansible_local" do |ansible|
ansible.install = true
ansible.install_mode = "pip" ansible.install_mode = "pip"
# Since Debian Buster still uses Python 2.7 by default and the pip bootstrap
# script is no longer compatible with 2.7, we need to specify the installation
# command manually. If we upgrade to a newer version of Debian that defaults to
# Python 3.6+, this should no longer be necessary.
ansible.pip_install_cmd = "sudo apt-get install -y python3-distutils && curl -s https://bootstrap.pypa.io/get-pip.py | sudo python3"
# Vagrant doesn't currently recognize the new format for Ansible versions
# (e.g. "ansible [core 2.11.1]"), so the compatibility mode is set incorrectly.
# A new version of Vagrant should resolve this soon.
ansible.compatibility_mode = "2.0"
ansible.version = "10.6.0"
ansible.pip_install_cmd = "sudo apt-get install -y python3-pip"
ansible.pip_args = "--break-system-packages"
# put the VM into the "dev" and "app_server" Ansible groups # put the VM into the "dev" and "app_server" Ansible groups
ansible.groups = { ansible.groups = {
@ -43,4 +35,19 @@ Vagrant.configure(VAGRANT_CONFIG_VERSION) do |config|
vb.memory = "4096" vb.memory = "4096"
vb.cpus = "4" vb.cpus = "4"
end end
config.vm.provider "docker" do |d, override|
# Docker does not require config.vm.box
override.vm.box = nil
# Instead, specify build_dir where Dockerfile is located.
d.build_dir = "./docker"
d.dockerfile = "Dockerfile-for-vagrant"
# Keep Docker container running indefinitely
d.remains_running = true
d.create_args = ["--detach", "--tty"]
# SSH configuration
d.has_ssh = true
end
end end

14
ansible/playbook.yml

@ -6,10 +6,23 @@
roles: roles:
- common - common
# Do some dev tasks before app_server,
# e.g. self_signed_ssl_cert should be done before nginx
- hosts: dev
become: true
vars_files:
- vars.yml
roles:
- self_signed_ssl_cert
- hosts: app_server - hosts: app_server
become: true become: true
vars_files: vars_files:
- vars.yml - vars.yml
module_defaults:
ansible.builtin.systemd_service:
# In Docker, systemctl3.py needs daemon_reload to detect new/updated service files
daemon_reload: "{{ is_docker }}"
roles: roles:
- cmark-gfm - cmark-gfm
- pts_lbsearch - pts_lbsearch
@ -39,7 +52,6 @@
vars_files: vars_files:
- vars.yml - vars.yml
roles: roles:
- self_signed_ssl_cert
- prometheus - prometheus
- java - java
- nodejs - nodejs

2
ansible/requirements.yml

@ -1,3 +1,5 @@
--- ---
collections: collections:
- community.general - community.general
- community.postgresql
- community.crypto

12
ansible/roles/boussole/tasks/main.yml

@ -13,12 +13,6 @@
group: root group: root
mode: 0644 mode: 0644
- name: Start and enable boussole service
service:
name: boussole
state: started
enabled: true
- name: Create directory for compiled CSS - name: Create directory for compiled CSS
file: file:
path: "{{ app_dir }}/static/css" path: "{{ app_dir }}/static/css"
@ -27,6 +21,12 @@
group: "{{ app_username }}" group: "{{ app_username }}"
mode: 0755 mode: 0755
- name: Start and enable boussole service
systemd_service:
name: boussole
state: started
enabled: true
- name: Check if any compiled CSS files exist - name: Check if any compiled CSS files exist
find: find:
path: "{{ app_dir }}/static/css" path: "{{ app_dir }}/static/css"

2
ansible/roles/consumers/tasks/main.yml

@ -9,7 +9,7 @@
loop: "{{ consumers }}" loop: "{{ consumers }}"
- name: Start and enable all consumer services - name: Start and enable all consumer services
service:
systemd_service:
name: consumer-{{ item }} name: consumer-{{ item }}
state: started state: started
enabled: true enabled: true

4
ansible/roles/cronjobs/tasks/main.yml

@ -1,4 +1,8 @@
--- ---
- name: Install cron
apt:
name: cron
- name: Add cronjob for lifting expired temporary bans - name: Add cronjob for lifting expired temporary bans
cron: cron:
name: lift_expired_temporary_bans name: lift_expired_temporary_bans

15
ansible/roles/gunicorn/tasks/main.yml

@ -24,7 +24,7 @@
mode: 0644 mode: 0644
- name: Start and enable gunicorn.socket service - name: Start and enable gunicorn.socket service
service:
systemd_service:
name: gunicorn.socket name: gunicorn.socket
state: started state: started
enabled: true enabled: true
@ -47,8 +47,17 @@
group: root group: root
mode: 0644 mode: 0644
- name: Start and enable gunicorn_reloader path-monitoring service
service:
- name: Start and enable gunicorn_reloader path-monitoring service, with fallback
block:
- name: Start and enable gunicorn_reloader path-monitoring service
systemd_service:
name: gunicorn_reloader.path name: gunicorn_reloader.path
state: started state: started
enabled: true enabled: true
rescue:
# Likely Docker; systemctl3.py doesn't support .path, so enable .service here
- name: Start and enable gunicorn.service (if .path service fails)
systemd_service:
name: gunicorn.service
state: started
enabled: true

2
ansible/roles/java/tasks/main.yml

@ -1,4 +1,4 @@
--- ---
- name: Install OpenJDK Java runtime - name: Install OpenJDK Java runtime
apt: apt:
name: openjdk-11-jre
name: openjdk-17-jre

2
ansible/roles/nginx/handlers/main.yml

@ -1,5 +1,5 @@
--- ---
- name: Reload nginx - name: Reload nginx
service:
systemd_service:
name: nginx name: nginx
state: reloaded state: reloaded

39
ansible/roles/nginx/tasks/main.yml

@ -1,21 +1,23 @@
--- ---
- name: Add APT key for nginx repository
apt_key:
url: https://nginx.org/keys/nginx_signing.key
- name: Add nginx APT repository
apt_repository:
repo: deb http://nginx.org/packages/debian/ buster nginx
- name: Install nginx - name: Install nginx
apt: apt:
name: nginx name: nginx
- name: Start and enable nginx service
service:
- name: Remove nginx from init.d (may conflict with systemd service)
file:
path: /etc/init.d/nginx
state: absent
when: is_docker
- name: Update rc.d to reflect init.d removal
command:
cmd: update-rc.d nginx remove
when: is_docker
- name: Create nginx user
user:
name: nginx name: nginx
state: started
enabled: true
create_home: false
- name: Create nginx.conf file - name: Create nginx.conf file
template: template:
@ -43,6 +45,19 @@
group: root group: root
mode: 0744 mode: 0744
- name: Disable nginx default site
file:
path: /etc/nginx/sites-enabled/default
state: absent
notify:
- Reload nginx
- name: Start and enable nginx service
systemd_service:
name: nginx
state: started
enabled: true
- name: Add logrotate config - name: Add logrotate config
copy: copy:
src: logrotate src: logrotate

15
ansible/roles/nodejs/tasks/main.yml

@ -1,15 +1,9 @@
--- ---
- name: Add APT key for NodeSource Node.js repository
apt_key:
url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
- name: Add NodeSource Node.js APT repository
apt_repository:
repo: deb https://deb.nodesource.com/node_14.x buster main
- name: Install Node.js - name: Install Node.js
apt: apt:
name: nodejs
name:
- nodejs
- npm
- name: Install npm packages defined in package.json - name: Install npm packages defined in package.json
become_user: "{{ app_username }}" become_user: "{{ app_username }}"
@ -18,6 +12,3 @@
# --no-bin-links option is needed to prevent npm from creating symlinks in the .bin # --no-bin-links option is needed to prevent npm from creating symlinks in the .bin
# directory, which doesn't work inside Vagrant on Windows # directory, which doesn't work inside Vagrant on Windows
no_bin_links: true no_bin_links: true
# npm ci needs to be run, for a clean install, instead of npm install.
# otherwise node_modules is never created/updated (Ansible bug?)
ci: true

2
ansible/roles/pgbouncer/handlers/main.yml

@ -1,5 +1,5 @@
--- ---
- name: Reload pgbouncer - name: Reload pgbouncer
service:
systemd_service:
name: pgbouncer name: pgbouncer
state: reloaded state: reloaded

13
ansible/roles/pgbouncer/tasks/main.yml

@ -3,6 +3,17 @@
apt: apt:
name: pgbouncer name: pgbouncer
- name: Remove pgbouncer from init.d (may conflict with systemd service)
file:
path: /etc/init.d/pgbouncer
state: absent
when: is_docker
- name: Update rc.d to reflect init.d removal
command:
cmd: update-rc.d pgbouncer remove
when: is_docker
- name: Add pgbouncer.ini - name: Add pgbouncer.ini
template: template:
src: pgbouncer.ini.jinja2 src: pgbouncer.ini.jinja2
@ -25,7 +36,7 @@
- Reload pgbouncer - Reload pgbouncer
- name: Start and enable pgbouncer service - name: Start and enable pgbouncer service
service:
systemd_service:
name: pgbouncer name: pgbouncer
state: started state: started
enabled: true enabled: true

2
ansible/roles/postgresql/defaults/main.yml

@ -1,5 +1,5 @@
--- ---
postgresql_version: 13
postgresql_version: 15
# Users of this role can define postgresql_settings, which will be merged with # Users of this role can define postgresql_settings, which will be merged with
# this base _postgresql_settings # this base _postgresql_settings

8
ansible/roles/postgresql/handlers/main.yml

@ -1,10 +1,6 @@
--- ---
- name: Restart postgresql - name: Restart postgresql
service:
name: postgresql
state: restarted
include_tasks: restart.yml
- name: Reload postgresql - name: Reload postgresql
service:
name: postgresql
state: reloaded
include_tasks: reload.yml

29
ansible/roles/postgresql/tasks/main.yml

@ -1,22 +1,31 @@
--- ---
- name: Add APT key for PostgreSQL repository
apt_key:
url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
- name: Add PostgreSQL APT repository
apt_repository:
repo: deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main
- name: Install PostgreSQL - name: Install PostgreSQL
apt: apt:
name: postgresql-{{ postgresql_version }} name: postgresql-{{ postgresql_version }}
- name: Start and enable PostgreSQL service
service:
- name: Remove postgresql from init.d (may conflict with systemd service)
file:
path: /etc/init.d/postgresql
state: absent
when: is_docker
- name: Update rc.d to reflect init.d removal
command:
cmd: update-rc.d postgresql remove
when: is_docker
- name: Start and enable PostgreSQL meta unit service
systemd_service:
name: postgresql name: postgresql
state: started state: started
enabled: true enabled: true
- name: Start and enable PostgreSQL cluster service
systemd_service:
name: postgresql@{{ postgresql_version }}-main
state: started
enabled: true
- name: Set configuration options in postgresql.conf - name: Set configuration options in postgresql.conf
lineinfile: lineinfile:
path: /etc/postgresql/{{ postgresql_version }}/main/postgresql.conf path: /etc/postgresql/{{ postgresql_version }}/main/postgresql.conf

10
ansible/roles/postgresql/tasks/reload.yml

@ -0,0 +1,10 @@
---
- name: Reload PostgreSQL meta unit service
systemd_service:
name: postgresql
state: reloaded
- name: Reload PostgreSQL cluster service
systemd_service:
name: postgresql@{{ postgresql_version }}-main
state: reloaded

10
ansible/roles/postgresql/tasks/restart.yml

@ -0,0 +1,10 @@
---
- name: Restart PostgreSQL meta unit service
systemd_service:
name: postgresql
state: restarted
- name: Restart PostgreSQL cluster service
systemd_service:
name: postgresql@{{ postgresql_version }}-main
state: restarted

2
ansible/roles/postgresql_redis_bridge/tasks/main.yml

@ -7,7 +7,7 @@
mode: 0644 mode: 0644
- name: Start and enable postgresql_redis_bridge service - name: Start and enable postgresql_redis_bridge service
service:
systemd_service:
name: postgresql_redis_bridge name: postgresql_redis_bridge
state: started state: started
enabled: true enabled: true

1
ansible/roles/postgresql_tildes_dbs/tasks/main.yml

@ -9,6 +9,7 @@
- name: Install packages needed by Ansible community plugins - name: Install packages needed by Ansible community plugins
pip: pip:
executable: pip3 executable: pip3
break_system_packages: true
name: name:
- ipaddress - ipaddress
- psycopg2 - psycopg2

2
ansible/roles/prometheus/handlers/main.yml

@ -1,5 +1,5 @@
--- ---
- name: Restart prometheus - name: Restart prometheus
service:
systemd_service:
name: prometheus name: prometheus
state: restarted state: restarted

2
ansible/roles/prometheus/tasks/main.yml

@ -53,7 +53,7 @@
- Restart prometheus - Restart prometheus
- name: Start and enable prometheus service - name: Start and enable prometheus service
service:
systemd_service:
name: prometheus name: prometheus
state: started state: started
enabled: true enabled: true

12
ansible/roles/prometheus_node_exporter/tasks/main.yml

@ -2,12 +2,20 @@
- name: Create prometheus user and group - name: Create prometheus user and group
import_tasks: prometheus_user.yml import_tasks: prometheus_user.yml
- name: Download node_exporter from GitHub
- name: Download node_exporter from GitHub (x86_64 / amd64)
when: ansible_facts['architecture'] == 'x86_64'
get_url: get_url:
dest: /tmp/prometheus_node_exporter.tar.gz dest: /tmp/prometheus_node_exporter.tar.gz
url: https://github.com/prometheus/node_exporter/releases/download/v0.13.0/node_exporter-0.13.0.linux-amd64.tar.gz url: https://github.com/prometheus/node_exporter/releases/download/v0.13.0/node_exporter-0.13.0.linux-amd64.tar.gz
checksum: sha256:2de5d1e51330c41588ed4c88bc531a3d2dccf6b4d7b99d5782d95cff27a3c049 checksum: sha256:2de5d1e51330c41588ed4c88bc531a3d2dccf6b4d7b99d5782d95cff27a3c049
- name: Download node_exporter from GitHub (aarch64 / arm64)
when: ansible_facts['architecture'] == 'aarch64'
get_url:
dest: /tmp/prometheus_node_exporter.tar.gz
url: https://github.com/prometheus/node_exporter/releases/download/v0.13.0/node_exporter-0.13.0.linux-arm64.tar.gz
checksum: sha256:a7f9db18b590e068ada68d3e1edd1bd0a9db43e3ee8f69517a49768ec8988a4c
- name: Create node_exporter directory - name: Create node_exporter directory
file: file:
path: /opt/prometheus_node_exporter path: /opt/prometheus_node_exporter
@ -36,7 +44,7 @@
mode: 0644 mode: 0644
- name: Start and enable node_exporter service - name: Start and enable node_exporter service
service:
systemd_service:
name: prometheus_node_exporter name: prometheus_node_exporter
state: started state: started
enabled: true enabled: true

2
ansible/roles/prometheus_postgres_exporter/tasks/main.yml

@ -41,7 +41,7 @@
mode: 0644 mode: 0644
- name: Start and enable postgres_exporter service - name: Start and enable postgres_exporter service
service:
systemd_service:
name: prometheus_postgres_exporter name: prometheus_postgres_exporter
state: started state: started
enabled: true enabled: true

2
ansible/roles/prometheus_redis_exporter/tasks/main.yml

@ -34,7 +34,7 @@
mode: 0644 mode: 0644
- name: Start and enable redis_exporter service - name: Start and enable redis_exporter service
service:
systemd_service:
name: prometheus_redis_exporter name: prometheus_redis_exporter
state: started state: started
enabled: true enabled: true

2
ansible/roles/python/tasks/main.yml

@ -11,7 +11,7 @@
get_url: get_url:
dest: /tmp/python.tar.gz dest: /tmp/python.tar.gz
url: https://www.python.org/ftp/python/{{ python_full_version }}/Python-{{ python_full_version }}.tgz url: https://www.python.org/ftp/python/{{ python_full_version }}/Python-{{ python_full_version }}.tgz
checksum: sha256:e0fbd5b6e1ee242524430dee3c91baf4cbbaba4a72dd1674b90fda87b713c7ab
checksum: sha256:1e71f006222666e0a39f5a47be8221415c22c4dd8f25334cc41aee260b3d379e
- name: Create temp directory to extract Python to - name: Create temp directory to extract Python to
file: file:

2
ansible/roles/redis/handlers/main.yml

@ -1,5 +1,5 @@
--- ---
- name: Restart redis - name: Restart redis
service:
systemd_service:
name: redis name: redis
state: restarted state: restarted

7
ansible/roles/redis/tasks/main.yml

@ -102,11 +102,12 @@
changed_when: false changed_when: false
- name: Start and enable "disable transparent hugepage" service - name: Start and enable "disable transparent hugepage" service
service:
systemd_service:
name: transparent_hugepage.service name: transparent_hugepage.service
state: started state: started
enabled: true enabled: true
when: "'[never]' not in transparent_hugepage.stdout" when: "'[never]' not in transparent_hugepage.stdout"
ignore_errors: "{{ is_docker }}"
- name: Check if kernel overcommit mode is already set - name: Check if kernel overcommit mode is already set
command: command:
@ -118,14 +119,16 @@
command: command:
cmd: sysctl vm.overcommit_memory=1 cmd: sysctl vm.overcommit_memory=1
when: overcommit_memory.stdout == "0" when: overcommit_memory.stdout == "0"
ignore_errors: "{{ is_docker }}"
- name: Make kernel overcommit mode permanent (recommended by Redis, requires restart) - name: Make kernel overcommit mode permanent (recommended by Redis, requires restart)
lineinfile: lineinfile:
path: /etc/sysctl.conf path: /etc/sysctl.conf
line: vm.overcommit_memory = 1 line: vm.overcommit_memory = 1
ignore_errors: "{{ is_docker }}"
- name: Start and enable redis service - name: Start and enable redis service
service:
systemd_service:
name: redis name: redis
state: started state: started
enabled: true enabled: true

14
ansible/roles/redis_module_cell/tasks/main.yml

@ -1,9 +1,17 @@
--- ---
- name: Download redis-cell Redis module from GitHub
- name: Download redis-cell Redis module (x86_64) from GitHub
when: ansible_facts['architecture'] == 'x86_64'
get_url: get_url:
dest: /tmp/redis-cell.tar.gz dest: /tmp/redis-cell.tar.gz
url: https://github.com/brandur/redis-cell/releases/download/v0.2.1/redis-cell-v0.2.1-x86_64-unknown-linux-gnu.tar.gz
checksum: sha256:9427fb100f4cada817f30f854ead7f233de32948a0ec644f15988c275a2ed1cb
url: https://github.com/brandur/redis-cell/releases/download/v0.4.0/redis-cell-v0.4.0-x86_64-unknown-linux-gnu.tar.gz
checksum: sha256:f86380f692c3852502e7c8924915a3424a4614ba01d7feec4cbc3c1faf22fb28
- name: Download redis-cell Redis module (aarch64) from GitHub
when: ansible_facts['architecture'] == 'aarch64'
get_url:
dest: /tmp/redis-cell.tar.gz
url: https://github.com/brandur/redis-cell/releases/download/v0.4.0/redis-cell-v0.4.0-aarch64-unknown-linux-gnu.tar.gz
checksum: sha256:bff45476b45c5e7da7e840076f35e91f83641960e5860620063da7b070f154bc
- name: Create /opt/redis-cell - name: Create /opt/redis-cell
file: file:

3
ansible/roles/self_signed_ssl_cert/meta/main.yml

@ -1,3 +0,0 @@
---
dependencies:
- role: nginx

3
ansible/roles/self_signed_ssl_cert/tasks/main.yml

@ -2,6 +2,7 @@
- name: Install packages needed by Ansible community plugins - name: Install packages needed by Ansible community plugins
pip: pip:
executable: pip3 executable: pip3
break_system_packages: true
name: cryptography name: cryptography
- name: Create directory for certificate - name: Create directory for certificate
@ -19,5 +20,3 @@
path: "{{ ssl_cert_path }}" path: "{{ ssl_cert_path }}"
privatekey_path: "{{ ssl_private_key_path }}" privatekey_path: "{{ ssl_private_key_path }}"
provider: selfsigned provider: selfsigned
notify:
- Reload nginx

2
ansible/roles/webassets/tasks/main.yml

@ -23,7 +23,7 @@
mode: 0644 mode: 0644
- name: Start and enable webassets service - name: Start and enable webassets service
service:
systemd_service:
name: webassets name: webassets
state: started state: started
enabled: true enabled: true

4
ansible/vars.yml

@ -5,5 +5,7 @@ bin_dir: "{{ venv_dir }}/bin"
static_sites_dir: /opt/tildes-static-sites static_sites_dir: /opt/tildes-static-sites
python_full_version: 3.9.5
python_full_version: 3.9.20
python_version: "{{ python_full_version.rpartition('.')[0] }}" python_version: "{{ python_full_version.rpartition('.')[0] }}"
is_docker: "{{ ansible_facts['virtualization_type'] == 'container' }}"

33
docker/Dockerfile-for-vagrant

@ -0,0 +1,33 @@
FROM debian:12
ENV container docker
RUN useradd --create-home vagrant \
&& echo "vagrant:vagrant" | chpasswd \
&& groupadd wheel \
&& usermod -a -G wheel vagrant
# allow vagrant to login
RUN cd ~vagrant \
&& mkdir .ssh \
&& echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > .ssh/authorized_keys \
&& chown -R vagrant:vagrant .ssh \
&& chmod 0700 .ssh \
&& chmod 0600 .ssh/authorized_keys
EXPOSE 22
# install sudo, sshd, git, python3
RUN apt-get update && apt-get install -y sudo openssh-server git python3
# Enable passwordless sudo for the "vagrant" user
RUN mkdir -p /etc/sudoers.d
RUN install -b -m 0440 /dev/null /etc/sudoers.d/vagrant
RUN echo 'vagrant ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/vagrant
# Use systemd replacement script to simulate systemd in Docker
# https://github.com/gdraheim/docker-systemctl-replacement
COPY systemctl3.py /usr/bin/systemctl
RUN test -e /bin/systemctl || ln -sf /usr/bin/systemctl /bin/systemctl
RUN chmod 0755 /usr/bin/systemctl
RUN systemctl enable ssh
CMD ["/usr/bin/systemctl"]

6851
docker/systemctl3.py
File diff suppressed because it is too large
View File

12
tildes/requirements-dev.txt

@ -37,9 +37,9 @@ markupsafe==2.0.1
marshmallow==3.13.0 marshmallow==3.13.0
matplotlib-inline==0.1.2 matplotlib-inline==0.1.2
mccabe==0.6.1 mccabe==0.6.1
mypy==0.910
mypy-extensions==0.4.3
packaging==21.0
mypy==1.13.0
mypy-extensions==1.0.0
packaging==23.2
parso==0.8.2 parso==0.8.2
pastedeploy==2.1.1 pastedeploy==2.1.1
pathspec==0.9.0 pathspec==0.9.0
@ -89,7 +89,7 @@ repoze.lru==0.7
requests==2.26.0 requests==2.26.0
requirements-detector==0.7 requirements-detector==0.7
sentry-sdk==1.3.0 sentry-sdk==1.3.0
setoptconf==0.2.0
setoptconf==0.3.0
six==1.16.0 six==1.16.0
snowballstemmer==2.1.0 snowballstemmer==2.1.0
soupsieve==2.2.1 soupsieve==2.2.1
@ -100,7 +100,7 @@ testing.common.database==2.0.3
testing.redis==1.1.1 testing.redis==1.1.1
titlecase==2.3 titlecase==2.3
toml==0.10.2 toml==0.10.2
tomli==1.0.4
tomli==1.2.3
traitlets==5.0.5 traitlets==5.0.5
transaction==3.0.1 transaction==3.0.1
translationstring==1.4 translationstring==1.4
@ -108,7 +108,7 @@ types-bleach==3.3.3
types-python-dateutil==0.1.4 types-python-dateutil==0.1.4
types-redis==3.5.4 types-redis==3.5.4
types-requests==2.25.0 types-requests==2.25.0
typing-extensions==3.10.0.0
typing-extensions==4.12.2
urllib3==1.26.6 urllib3==1.26.6
venusian==3.0.0 venusian==3.0.0
waitress==2.0.0 waitress==2.0.0

4
tildes/requirements.txt

@ -24,7 +24,7 @@ mako==1.1.4
markupsafe==2.0.1 markupsafe==2.0.1
marshmallow==3.13.0 marshmallow==3.13.0
matplotlib-inline==0.1.2 matplotlib-inline==0.1.2
packaging==21.0
packaging==23.2
parso==0.8.2 parso==0.8.2
pastedeploy==2.1.1 pastedeploy==2.1.1
pep517==0.11.0 pep517==0.11.0
@ -63,7 +63,7 @@ sqlalchemy==1.3.24
sqlalchemy-utils==0.37.8 sqlalchemy-utils==0.37.8
stripe==2.60.0 stripe==2.60.0
titlecase==2.3 titlecase==2.3
tomli==1.0.4
tomli==1.2.3
traitlets==5.0.5 traitlets==5.0.5
transaction==3.0.1 transaction==3.0.1
translationstring==1.4 translationstring==1.4

2
tildes/scripts/initialize_db.py

@ -8,7 +8,7 @@ import os
import subprocess import subprocess
from typing import Optional from typing import Optional
from alembic import command
from alembic import command # type: ignore[attr-defined]
from alembic.config import Config from alembic.config import Config
from sqlalchemy.engine import Connectable, Engine from sqlalchemy.engine import Connectable, Engine

2
tildes/tests/test_ratelimit.py

@ -4,6 +4,7 @@
from datetime import timedelta from datetime import timedelta
from itertools import permutations from itertools import permutations
from random import randint from random import randint
from time import sleep
from pytest import raises from pytest import raises
@ -153,6 +154,7 @@ def test_time_until_retry(redis):
# first usage should be fine # first usage should be fine
result = action.check_for_user_id(user_id) result = action.check_for_user_id(user_id)
assert result.is_allowed assert result.is_allowed
sleep(1.0)
# second should fail, and require a wait of (period / limit) - 1 sec # second should fail, and require a wait of (period / limit) - 1 sec
result = action.check_for_user_id(user_id) result = action.check_for_user_id(user_id)

2
tildes/tildes/__init__.py

@ -40,7 +40,7 @@ def main(global_config: dict[str, str], **settings: str) -> PrefixMiddleware:
if settings.get("sentry_dsn"): if settings.get("sentry_dsn"):
# pylint: disable=abstract-class-instantiated # pylint: disable=abstract-class-instantiated
sentry_sdk.init(
sentry_sdk.init( # type: ignore[abstract]
dsn=settings["sentry_dsn"], dsn=settings["sentry_dsn"],
integrations=[PyramidIntegration()], integrations=[PyramidIntegration()],
ignore_errors=[ValidationError], ignore_errors=[ValidationError],

4
tildes/tildes/models/database_model.py

@ -92,10 +92,10 @@ class DatabaseModelBase:
raise AttributeError("'age' attribute requires 'created_time' column.") raise AttributeError("'age' attribute requires 'created_time' column.")
# created_time should only be None during __init__, age of 0 is reasonable # created_time should only be None during __init__, age of 0 is reasonable
if self.created_time is None: # type: ignore
if self.created_time is None:
return timedelta(0) return timedelta(0)
return utc_now() - self.created_time # type: ignore
return utc_now() - self.created_time
def _update_creation_metric(self) -> None: def _update_creation_metric(self) -> None:
"""Update the metric tracking creations of this model type. """Update the metric tracking creations of this model type.

Loading…
Cancel
Save