Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lay dagger CI/CD foundations #184

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@ tmp/
# Do not add scss cache
.sass-cache
*.sass-cache

# Ignore dagger CI cue.mod folder
cue.mod
22 changes: 22 additions & 0 deletions Dockerfile-ci
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
46 changes: 46 additions & 0 deletions ci.cue
Original file line number Diff line number Diff line change
@@ -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"]
}
}
}
}

File renamed without changes.
1 change: 0 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
55 changes: 40 additions & 15 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -44,36 +60,30 @@ 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
# flask-debugtoolbar
# 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
# via
# jinja2
# mako
# wtforms
mccabe==0.7.0
# via pylint
mypy-extensions==0.4.3
# via black
oauthlib==2.1.0
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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