Skip to content

Local gender-decoder running in a container #17

@desrod

Description

@desrod

I've created a simple cloud-init that clones this repo, configures PostgreSQL + Flask, and spins up the gender-decoder in a local container.

We use this heavily to analyze our public-facing job postings, but those aren't always made public straight away, so we needed a way to analyze the posts in draft before publishing. This is also being used to analyze local collateral.

There are a few hard-coded values that point back to the public gender-decoder, I'll PR those and patch those out in the jinja2 templates to make those tunables (specifically, the referral link to the analyzed content).

The cloud-init YAML below will..

  • Clone this repository's 'main' branch
  • Create and configure a simple PostgreSQL user
  • Install and configure the necessary Python dependencies of Flask
  • Launch Flask with the application listening on port :5000

To create and run this:

  1. Create a local container (username is ubuntu, password is ubuntu)

    uvt-kvm create gdecoder release=focal arch=amd64 --memory 4096 --cpu 2 --disk 20 --host-passthrough --user-data gender-decoder.yaml
    
  2. Give the container a few minutes to spin up and configure the various pieces

  3. Find the container's IP, so you can reach the gender-decoder on :5000, using:

    uvt-kvm ip gender-decoder
    

YAML included below:

#cloud-config
no-log-init: true
preserve_hostname: false
package_update: false
package_upgrade: false
manage_etc_hosts: true
apt_pipelining: true
fqdn: gender-decoder.lab
ssh_pwauth: True
password: ubuntu
chpasswd: { expire: False }
users:
  - default
  - name: ubuntu
    gecos: Ubuntu User
    primary_group: ubuntu
    groups: users
    sudo: ALL=(ALL) NOPASSWD:ALL
    lock_passwd: false
    ssh_redirect_user: false
packages:
  - python3-venv
  - gcc
  - libpython3-dev
  - openssh-server
  - python3-pip
  - postgresql-12
  - libpython3.8-dev
  - postgresql-client-12
  - postgresql-server-dev-all
  - python3-flask
  - python3-flask-sqlalchemy
  - python3-wtforms
  - python3-flaskext.wtf
  - python3-psycopg2
  - python3-migrate
runcmd: 
  - [git, clone, https://github.com/lovedaybrooke/gender-decoder, /opt/gender-decoder]
  - [sudo, -u, postgres, createuser, '--superuser', gender-decoder]
  - [sudo, -u, postgres, createdb, gender-decoder]
  - [sudo, -u, postgres, psql, -U, postgres, -d, postgres, -c, "ALTER USER \"gender-decoder\" with password 'g3nderD3c0der';"]
  - "SECRET_KEY=$(dbus-uuidgen) DATABASE_URL='postgresql://gender-decoder:g3nderD3c0der@127.0.0.1/gender-decoder' python3 /opt/gender-decoder/db_create.py"
  - "SECRET_KEY=$(dbus-uuidgen) DATABASE_URL='postgresql://gender-decoder:g3nderD3c0der@127.0.0.1/gender-decoder' FLASK_APP=/opt/gender-decoder/runsite.py flask run --host=$(hostname -I)"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions