Skip to content

Commit 4e6b925

Browse files
Merge pull request #346 from micahflee/containerize
Containerize Hush Line
2 parents 4ed2bce + d1bbbc9 commit 4e6b925

27 files changed

+151
-340
lines changed

.github/workflows/merge-to-main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ jobs:
3737
run: poetry install --all-extras
3838

3939
- name: Lint
40-
run: poetry -v run make lint
40+
run: poetry run isort --check . && poetry run black --check . && poetry run flake8 --config setup.cfg . && poetry run mypy --config-file pyproject.toml .
4141

4242
- name: Test
43-
run: poetry -v run make test
43+
run: source test.env && poetry run pytest -vv tests -p no:warnings
4444
env:
4545
CI: true

.github/workflows/pull-request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ jobs:
3737
run: poetry install --all-extras
3838

3939
- name: Lint
40-
run: poetry -v run make lint
40+
run: poetry run isort --check . && poetry run black --check . && poetry run flake8 --config setup.cfg . && poetry run mypy --config-file pyproject.toml .
4141

4242
- name: Test
43-
run: poetry -v run make test
43+
run: source test.env && poetry run pytest -vv tests -p no:warnings
4444
continue-on-error: true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ _DEV.md
99
hushline.db
1010
/tests/__pycache__
1111
hushline/static/data/users_directory.json
12+
volumes/app
13+
volumes/redis

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM python:3.12-bookworm
2+
WORKDIR /app
3+
4+
# Install system dependencies
5+
RUN apt-get update && \
6+
apt-get upgrade -y && \
7+
apt-get install -y --no-install-recommends \
8+
build-essential curl libpcsclite-dev clang llvm pkg-config nettle-dev \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
# Install Poetry
12+
RUN pip install poetry
13+
14+
# Install Rust (for SequoiaPGP)
15+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
16+
ENV PATH="/root/.cargo/bin:${PATH}"
17+
18+
# Install Poetry dependencies
19+
COPY poetry.lock pyproject.toml /app/
20+
RUN poetry install
21+
22+
# Copy the rest of the application
23+
COPY . /app
24+
25+
# Run!
26+
ENV FLASK_APP="hushline/__init__.py"
27+
CMD ["poetry", "run", "flask", "run", "-p", "5000", "--host", "0.0.0.0"]

Makefile

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,22 @@ help: ## Print the help message
66
sort | \
77
column -s ':' -t
88

9-
.PHONY: run
10-
run: ## Run the app
11-
@source ./files/dev/env.sh && \
12-
flask run --debug -h localhost -p 5000
9+
.PHONY: dev
10+
dev: ## Run the app in development mode
11+
docker-compose up --build
12+
13+
.PHONY: test
14+
test: ## Run the test suite
15+
docker-compose exec app bash -c "poetry run pytest -vv tests -p no:warnings"
1316

1417
.PHONY: lint
1518
lint: ## Lint the code
16-
isort --check . && \
17-
black --check . && \
18-
flake8 --config setup.cfg . && \
19-
mypy --config-file pyproject.toml .
19+
docker-compose exec app poetry run bash -c "isort --check . && black --check . && flake8 --config setup.cfg . && mypy --config-file pyproject.toml ."
2020

2121
.PHONY: fmt
2222
fmt: ## Format the code
23-
isort . && \
24-
black .
23+
docker-compose exec app poetry run bash -c "isort . && black ."
2524

26-
.PHONY: init-db
27-
init-db: ## Initialize the dev database
28-
flask db-extras init-db
29-
30-
.PHONY: test
31-
test: ## Run the test suite
32-
@if [ -n "$$BASH_VERSION" ]; then \
33-
source ./files/dev/env.sh && pytest -vv tests -p no:warnings; \
34-
else \
35-
. ./files/dev/env.sh; pytest -vv tests -p no:warnings; \
36-
fi
25+
.PHONY: shell
26+
shell: ## Get a shell in the container
27+
docker-compose exec app bash

docker-compose.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
app:
3+
build: .
4+
ports:
5+
- "5000:5000"
6+
environment:
7+
- SQLALCHEMY_DATABASE_URI=sqlite:////data/hushline.db
8+
- FLASK_ENV=development
9+
- SECRET_KEY="cb3f4afde364bfb3956b97ca22ef4d2b593d9d980a4330686267cabcd2c0befd"
10+
- ENCRYPTION_KEY="bi5FDwhZGKfc4urLJ_ChGtIAaOPgxd3RDOhnvct10mw="
11+
- REDIS_URI=redis://redis:6379
12+
volumes:
13+
- ./volumes/app:/data
14+
- ./:/app
15+
depends_on:
16+
- redis
17+
18+
redis:
19+
image: "redis:alpine"
20+
ports:
21+
- "6379:6379"

docs/DEV.md

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,33 @@
22

33
👋 Welcome to the Hush Line Development setup guide. This document provides detailed instructions for configuring your local development environment across Mac, Windows, and Linux systems. It includes specific steps for installing dependencies, cloning the repository, and initiating a local server using the included `Makefile`. The guide also covers utilizing tests, linters, and formatters to ensure code integrity and consistency. Follow these instructions to prepare your machine for Hush Line development 👇.
44

5-
<img src="https://github.com/scidsg/hushline/assets/28545431/3108811e-226e-4451-9793-c893da96184c" width="66%">
5+
<img src="https://github.com/scidsg/hushline/assets/28545431/3108811e-226e-4451-9793-c893da96184c" width="80%">
66

77
<h2>Local Development</h2>
88

9-
## Mac
9+
Install [Docker Desktop](https://www.docker.com/products/docker-desktop/) for your platform.
1010

11-
| Tested Platform | OS Version | Browser | Status | Date | Notes |
12-
|-|-|-|-|-|-|
13-
| Macbook M2 | OSX 13.2.1 | Firefox 124.0.2 || Apr. 2024 | |
14-
| Macbook M1 | OSX 14.4.1 | Firefox 124.0.2 || Apr. 2024 | |
15-
| Macbook M1 | OSX 14.4.1 | Safari 17.4.1 | ☑️ | Apr. 2024 | App starts but a CSRF token mismatch blocks registration. |
11+
Clone the repo:
1612

17-
### Install Packages
18-
1. `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
19-
2. `eval "$(/opt/homebrew/bin/brew shellenv)"`
20-
3. `brew install python git git-lfs redis rust poetry`
13+
```sh
14+
git clone https://github.com/scidsg/hushline.git
15+
cd hushline
16+
```
2117

22-
### Clone the Repo
23-
4. `git clone https://github.com/scidsg/hushline.git`
24-
5. `cd hushline`
25-
6. `/opt/homebrew/bin/python3 -m venv venv`
26-
7. `source venv/bin/activate`
27-
8. `poetry install`
28-
9. `source files/dev/env.sh`
29-
10. `sudo lsof -ti:5000 | xargs kill -9` _Optional_
30-
11. `poetry run flask db upgrade` _Optional_
31-
12. `poetry run make init-db run`
18+
Start Hush Line for development:
3219

33-
## Windows
20+
```sh
21+
make dev
22+
```
3423

35-
| Tested Platform | Date |
36-
|-|-|
37-
| | |
24+
Test changes:
3825

39-
### Linux
26+
```sh
27+
make test
28+
```
4029

41-
| Tested Platform | Date |
42-
|-|-|
43-
| | |
30+
If you need to get a shell in the container to manually run commands:
4431

45-
<h2>Tests, Linters, and Formatters</h2>
46-
47-
## Testing Changes
48-
49-
1. `poetry run pre-commit run --all-files --verbose`.
50-
51-
2. `poetry run make test`.
32+
```sh
33+
make shell
34+
```

files/dev/env.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

files/docker/Dockerfile

Lines changed: 0 additions & 29 deletions
This file was deleted.

files/docker/docker-compose.yml

Lines changed: 0 additions & 81 deletions
This file was deleted.

files/docker/entrypoint.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

files/docker/env.list

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)