Skip to content

Commit

Permalink
Merge pull request #14 from uptick/nopbi-01/splat-dev-setup
Browse files Browse the repository at this point in the history
nopbi-01/splat dev setup
  • Loading branch information
uptickmetachu authored Apr 18, 2024
2 parents 1fbff78 + 5396853 commit f9ffaaf
Show file tree
Hide file tree
Showing 18 changed files with 636 additions and 141 deletions.
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.git
var
node_modules
**/.git
**/node_modules
**/*.pyc
**/*.jsx
**/*.js
**/*.sass
**/*.css
**/*.scss
**/*.snap
**/__pycache__
**/*.storyshot
./abas/apps/customerportal/packages
**/test_fixtures
./.venv/
35 changes: 35 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Python
on:
push:
branches:
- release/*
- develop
- master
- main
pull_request: {}

permissions:
id-token: write # Required for federated aws oidc
contents: read
actions: read
pull-requests: write

env:
CLUSTER_KEY: ${{secrets.CLUSTER_KEY}}

jobs:
ci:
uses: uptick/actions/.github/workflows/ci.yaml@main
secrets: inherit
with:
python: true
python-version: 3.11
praise-on-fix: false
poetry: true
poetry-install-command: "poetry install"
command: |
curl https://mise.jdx.dev/install.sh | sh
echo "$HOME/.local/bin" >> $GITHUB_PATH
echo "$HOME/.local/share/mise/shims" >> $GITHUB_PATH
mise settings set experimental true
mise run ci
24 changes: 0 additions & 24 deletions .github/workflows/publish.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ python/
fonts
fonts/*
fonts/
minio/
48 changes: 48 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[tools]
poetry = { version = 'latest', pyproject = 'pyproject.toml' }
python = { version= '3.11.*'}
awscli = '*'

[tasks.format]
description = "Run all formatters"
run = "poetry run ruff format ."

[tasks.ruff-check]
description = "Run ruff checker"
run = "poetry run ruff check --fix ."

[tasks.lint]
description = "Run all linters"
depends = ['format', 'ruff-check']

[tasks.test]
description = "Run all tests"
run = "docker compose run --rm -it dev pytest ."

[tasks."ci:test"]
description = "Run all tests"
run = "docker compose run --rm dev pytest ."
depends = ["build"]

[tasks.ci]
description = "Runs everything for CI"
depends = ['lint', 'ci:test']

[tasks.install]
description = "Sets up dev dependencies"
run = [
"mise install",
"poetry install",
"pre-commit install",
]
depends = ["build"]

[tasks.start]
description = "Run a local server"
run = [
"docker compose up --watch "
]

[tasks.build]
description = "Build the docker image"
run = "docker compose build"
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.3.7
hooks:
- id: ruff
args:
- --select
- F401
- --fix
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.3.7
hooks:
- id: ruff
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.3.7
hooks:
- id: ruff-format
# -
# repo: local
# hooks:
# - id: mypy
# args:
# - --show-error-codes
# name: mypy
# entry: poetry run mypy
# require_serial: true
# language: system
# exclude: ^tests/|^migrations/|^api_client/
# types:
# - python
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.13.0
hooks:
- id: commitizen
stages:
- commit-msg
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# docker build --platform linux/amd64 -t ${IMAGE} --target=base .
FROM public.ecr.aws/lambda/python:3.11-x86_64
# Target: base
FROM public.ecr.aws/lambda/python:3.11-x86_64 as base
ENV PRINCE_FILENAME=prince-14.1-linux-generic-x86_64
RUN yum clean all \
&& yum install -y unzip giflib \
Expand All @@ -12,7 +13,7 @@ COPY lambda_requirements.txt fonts.zip* ./
RUN pip3 install -r lambda_requirements.txt
# Fonts zip may not exist, so || true it.
CMD rm -rf /var/task/fonts || true
COPY fonts /var/task/fonts
COPY font[s] /var/task/fonts
COPY license.dat ./prince-engine/license/license.dat
COPY lambda_function.py ./
CMD ["lambda_function.lambda_handler"]
CMD ["lambda_function.lambda_handler"]
22 changes: 22 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.11-slim-bullseye

# Set the working directory in the container
WORKDIR /app


# Install Poetry
ENV POETRY_VERSION=1.8.1
RUN pip install "poetry==$POETRY_VERSION"

# Copy the Poetry configuration files
COPY pyproject.toml poetry.lock ./
# Install project dependencies
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi --no-root


# Copy the rest of the application code
COPY . .

# Set the entrypoint script
CMD ["bash"]
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,16 @@ pdf_with_splat(some_html, bucket_name="test_bucket")
# or
pdf_with_splat(some_html)
```

# Development

Install [mise](https://mise.jdx.dev/getting-started.html) task runner.


```
mise run install # booststrap the project and install requirements
mise run test # run tests
mise run format # format
```
51 changes: 51 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: '3.9'

services:
dev:
image: dev:latest
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- './:/app'
depends_on:
- lambda

lambda:
image: splat:dev
build:
context: .
dockerfile: Dockerfile
develop:
watch:
- action: sync+restart
path: lambda_function.py
target: /var/task/lambda_function.py
- action: rebuild
path: lambda_requirements.txt
environment:
- AWS_ACCESS_KEY_ID=root
- AWS_SECRET_ACCESS_KEY=password
- AWS_DEFAULT_REGION=us-east-1
- AWS_ENDPOINT_URL=http://minio:9000
- AWS_USE_PATH_STYLE_ENDPOINT=true
volumes:
- './tests:/var/task/tests'
ports:
- 8080:8080
depends_on:
- minio

minio:
image: 'minio/minio:latest'
ports:
- '${FORWARD_MINIO_PORT:-9000}:9000'
- '${FORWARD_MINIO_CONSOLE_PORT:-9090}:9090'
environment:
MINIO_ROOT_USER: 'root'
MINIO_ROOT_PASSWORD: 'password'
entrypoint: sh
volumes:
- './minio:/data/minio'
# Buckets are just mapped to the `minio` directory. We default create a test bucket
command: -c 'mkdir -p /data/minio/test && /usr/bin/minio server --console-address ":9090" /data/minio'
Loading

0 comments on commit f9ffaaf

Please sign in to comment.