scidsg / hushline

Hush Line connects whistleblowers with organizations and people who can help.
https://hushline.app
GNU Affero General Public License v3.0
77 stars 21 forks source link

support for hushline on Ubuntu 24.04 LTS + podman containers #632

Open rmlibre opened 1 month ago

rmlibre commented 1 month ago

These are the steps I took to get hushline working on Ubuntu 24.04 LTS with podman containers. Though, this isn't a clean guide, since it also includes the setup instructions used to run hushline without containerization. There are likely redundancies that can be pruned and still get it running.

Setup Machine

~$ sudo apt-get --fix-missing --install-recommends update
~$ sudo apt-get --fix-missing --fix-broken --install-recommends dist-upgrade
~$ sudo apt-get --fix-missing --fix-broken --install-recommends install npm pipx podman podman-compose

NOTE: I initially installed npm to run hushline before I got podman working. I'm not positive if it's actually necessary now.

Custom File Edits

'scripts/local-postgres.sh'

#!/usr/bin/env bash

podman run --rm -t -p 127.0.0.1:5432:5432 \
    -e POSTGRES_USER=hushline \
    -e POSTGRES_PASSWORD=hushline \
    -e POSTGRES_DB=hushline \
    postgres:16.4-alpine3.20

'Makefile'

.PHONY: lint
lint: ## Lint the code
    poetry run ruff format --check && \
    poetry run ruff check && \
    poetry run mypy . && \
    podman compose run --rm app npx prettier --check ./*.md ./docs ./.github/workflows/* ./hushline

.PHONY: fix
fix: ## Format the code
    poetry run ruff format && \
    poetry run ruff check --fix && \
    podman compose run --rm app npx prettier --write ./*.md ./docs ./.github/workflows/* ./hushline

...

.PHONY: test
test: ## Run the test suite
    podman compose run --rm app \
        poetry run pytest --cov hushline --cov-report term --cov-report html -vv $(PYTEST_ADDOPTS) tests/$(test)

Setup hushline

~$ cd /path/to/local/hushline/repo
~$ pipx ensurepath
~$ pipx install poetry
~$ npm install --save-dev prettier-plugin-jinja-template
~$ podman pull docker.io/postgres:16.4-alpine3.20
~$ make install
~$ podman build . -f Dockerfile.dev -t hushline

Run hushline

terminal # 1

~$ podman-compose down
~$ podman-compose up --build

terminal # 2

~$ podman-compose run --rm app bash
root@xxxxxxxxxxxx:/app# poetry shell
(hushline-py3.12) root@xxxxxxxxxxxx:/app# make migrate-dev
(hushline-py3.12) root@xxxxxxxxxxxx:/app# ./scripts/dev_data.py

browser # 1

open http://localhost:8080/

Cleanup hushline

close down session

~$ podman-compose down

view all containers

~$ podman ps -a

shutdown container by ID

~$ podman kill <container-ID>

clear all shutdown containers

~$ podman container prune

shutdown & clear all containers & data volumes

~$ podman stop -a && podman rm -afv

TODO: