diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..2766ecf --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,23 @@ +name: Haldis linter and format +on: [push] +jobs: + dagger: + runs-on: ubuntu-latest + steps: + - name: Clone repository + uses: actions/checkout@v2 + - name: Initialize Dagger CI environment + uses: dagger/dagger-for-github@v2 + # See all options at https://github.com/dagger/dagger-for-github + with: + version: 0.2 + cmds: | + project init + project update + - name: Format and lint the codebase + uses: dagger/dagger-for-github@v2 + # See all options at https://github.com/dagger/dagger-for-github + with: + version: 0.2 + cmds: | + do lint diff --git a/.gitignore b/.gitignore index e35c022..7f8377a 100644 --- a/.gitignore +++ b/.gitignore @@ -78,3 +78,6 @@ tmp/ # Do not add scss cache .sass-cache *.sass-cache + +# Ignore dagger CI cue.mod folder +cue.mod diff --git a/Dockerfile-ci b/Dockerfile-ci new file mode 100644 index 0000000..cc2a1aa --- /dev/null +++ b/Dockerfile-ci @@ -0,0 +1,22 @@ +FROM python:3.9-bullseye + +ENV VIRTUAL_ENV=/opt/venv +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" + +WORKDIR /src +COPY requirements.in . +RUN pip install pip-tools && \ + pip-compile + +COPY ./ /src + +RUN adduser --system --group haldis && \ + chown -R haldis:haldis /opt/venv && \ + chown -R haldis:haldis /src + +USER haldis + +COPY pylint-requirements.txt . +RUN pip install pylint black isort && \ + pip install -r pylint-requirements.txt diff --git a/README.md b/README.md index 2ed7864..ab3e90e 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,20 @@ Run `pip-compile --upgrade` For more information about managing the dependencies see [jazzband/pip-tools: A set of tools to keep your pinned Python dependencies fresh.](https://github.com/jazzband/pip-tools) +### Github CI - WIP + +CI/CD is done with the help of [dagger.io](). The tooling can easily be installed +by running the following wherever you want to install the binary (I propose +creating a `~/.local/bin` and adding it to your `PATH`). The install scripts +fetches the latest version and installs the binaries in a `./bin` folder of the +current working directory. + +``` +curl -L https://dl.dagger.io/dagger/install.sh | sh +``` + +On every push the CI will run `isort`, `black` and `pylint` against the codebase. + ## Production To prepare the application in a production environment, follow the same steps as for *Local setup* up to and including `./populate-db.sh`. diff --git a/ci.cue b/ci.cue new file mode 100644 index 0000000..2871eb5 --- /dev/null +++ b/ci.cue @@ -0,0 +1,46 @@ +package main + +import ( + "dagger.io/dagger" + "universe.dagger.io/docker" +) + +dagger.#Plan & { + client: filesystem: { + ".": read: contents: dagger.#FS + } + actions: { + _image: docker.#Dockerfile & { + source: client.filesystem.".".read.contents + dockerfile: path: "Dockerfile-ci" + }, + + isort: docker.#Run & { + input: _image.output + workdir: "/src" + command: { + name: "isort" + args: ["."] + } + } + + format: docker.#Run & { + input: isort.output + workdir: "/src" + command: { + name: "black" + args: ["."] + } + } + + lint: docker.#Run & { + input: format.output + workdir: "/src" + command: { + name: "pylint" + args: ["./app"] + } + } + } +} + diff --git a/pylint-requirement.txt b/pylint-requirements.txt similarity index 100% rename from pylint-requirement.txt rename to pylint-requirements.txt diff --git a/requirements.in b/requirements.in index 36c6ea3..3f4e376 100644 --- a/requirements.in +++ b/requirements.in @@ -8,7 +8,6 @@ Flask-OAuthlib Flask-Admin<2 Flask-Migrate<3 Flask-Script<3 -black pymysql pyyaml tatsu<5.6 # >=5.6 needs Python >=3.8 diff --git a/requirements.txt b/requirements.txt index bbca76b..0a5483d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile +# This file is autogenerated by pip-compile with python 3.9 # To update, run: # # pip-compile @@ -8,6 +8,8 @@ alembic==1.6.5 # via flask-migrate appdirs==1.4.4 # via black +astroid==2.11.2 + # via pylint black==21.6b0 # via -r requirements.in blinker==1.4 @@ -22,8 +24,22 @@ click==7.1.2 # via # black # flask +dill==0.3.4 + # via pylint dominate==2.6.0 # via flask-bootstrap +flask==1.1.4 + # via + # -r requirements.in + # flask-admin + # flask-bootstrap + # flask-debugtoolbar + # flask-login + # flask-migrate + # flask-oauthlib + # flask-script + # flask-sqlalchemy + # flask-wtf flask-admin==1.5.8 # via -r requirements.in flask-bootstrap==3.3.7.1 @@ -44,22 +60,12 @@ flask-sqlalchemy==2.5.1 # flask-migrate flask-wtf==0.15.1 # via -r requirements.in -flask==1.1.4 - # via - # -r requirements.in - # flask-admin - # flask-bootstrap - # flask-debugtoolbar - # flask-login - # flask-migrate - # flask-oauthlib - # flask-script - # flask-sqlalchemy - # flask-wtf greenlet==1.1.0 # via sqlalchemy idna==2.10 # via requests +isort==5.10.1 + # via pylint itsdangerous==1.1.0 # via # flask @@ -67,6 +73,8 @@ itsdangerous==1.1.0 # flask-wtf jinja2==2.11.3 # via flask +lazy-object-proxy==1.7.1 + # via astroid mako==1.1.4 # via alembic markupsafe==2.0.1 @@ -74,6 +82,8 @@ markupsafe==2.0.1 # jinja2 # mako # wtforms +mccabe==0.7.0 + # via pylint mypy-extensions==0.4.3 # via black oauthlib==2.1.0 @@ -82,6 +92,10 @@ oauthlib==2.1.0 # requests-oauthlib pathspec==0.8.1 # via black +platformdirs==2.5.2 + # via pylint +pylint==2.13.5 + # via -r requirements.in pymysql==1.0.2 # via -r requirements.in python-dateutil==2.8.1 @@ -92,10 +106,10 @@ pyyaml==5.4.1 # via -r requirements.in regex==2021.4.4 # via black -requests-oauthlib==1.1.0 - # via flask-oauthlib requests==2.25.1 # via requests-oauthlib +requests-oauthlib==1.1.0 + # via flask-oauthlib six==1.16.0 # via python-dateutil sqlalchemy==1.4.18 @@ -106,6 +120,12 @@ tatsu==4.4.0 # via -r requirements.in toml==0.10.2 # via black +tomli==2.0.1 + # via pylint +typing-extensions==4.2.0 + # via + # astroid + # pylint urllib3==1.26.5 # via requests visitor==0.1.3 @@ -114,7 +134,12 @@ werkzeug==1.0.1 # via # flask # flask-debugtoolbar +wrapt==1.14.0 + # via astroid wtforms==2.3.3 # via # flask-admin # flask-wtf + +# The following packages are considered to be unsafe in a requirements file: +# setuptools