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 1 commit
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
15 changes: 15 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Haldis linter and format
on: [push]
jobs:
dagger:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
- 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
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 .
mcbloch marked this conversation as resolved.
Show resolved Hide resolved
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"]
}
}
}
}

1 change: 1 addition & 0 deletions cue.mod/module.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module: ""
2 changes: 2 additions & 0 deletions cue.mod/pkg/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# generated by dagger
** linguist-generated=true
1 change: 1 addition & 0 deletions cue.mod/pkg/dagger.io/cue.mod/module.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module: "dagger.io"
4 changes: 4 additions & 0 deletions cue.mod/pkg/dagger.io/dagger/compat.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package dagger

// DEPRECATED: Use #Socket instead
#Service: #Socket
83 changes: 83 additions & 0 deletions cue.mod/pkg/dagger.io/dagger/core/exec.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package core

import "dagger.io/dagger"

// Execute a command in a container
#Exec: {
$dagger: task: _name: "Exec"

// Container filesystem
input: dagger.#FS

// Transient filesystem mounts
// Key is an arbitrary name, for example "app source code"
// Value is mount configuration
mounts: [name=string]: #Mount

// Command to execute
// Example: ["echo", "hello, world!"]
args: [...string]

// Environment variables
env: [key=string]: string | dagger.#Secret

// Working directory
workdir: string | *"/"

// User ID or name
user: string | *"root"

// If set, always execute even if the operation could be cached
always: true | *false

// Inject hostname resolution into the container
// key is hostname, value is IP
hosts: [hostname=string]: string

// Modified filesystem
output: dagger.#FS

// Command exit code
// Currently this field can only ever be zero.
// If the command fails, DAG execution is immediately terminated.
// FIXME: expand API to allow custom handling of failed commands
exit: int & 0
}

// A transient filesystem mount.
#Mount: {
dest: string
type: string
{
type: "cache"
contents: #CacheDir
} | {
type: "tmp"
contents: #TempDir
} | {
type: "socket"
contents: dagger.#Socket
} | {
type: "fs"
contents: dagger.#FS
source?: string
ro?: true | *false
} | {
type: "secret"
contents: dagger.#Secret
uid: int | *0
gid: int | *0
mask: int | *0o400
}
}

// A (best effort) persistent cache dir
#CacheDir: {
id: string
concurrency: *"shared" | "private" | "locked"
}

// A temporary directory for command execution
#TempDir: {
size: int64 | *0
}
129 changes: 129 additions & 0 deletions cue.mod/pkg/dagger.io/dagger/core/fs.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package core

import "dagger.io/dagger"

// Access the source directory for the current CUE package
// This may safely be called from any package
#Source: {
$dagger: task: _name: "Source"

// Relative path to source.
path: string
// Optionally include certain files
include: [...string]
// Optionally exclude certain files
exclude: [...string]

output: dagger.#FS
}

// Create one or multiple directory in a container
#Mkdir: {
$dagger: task: _name: "Mkdir"

// Container filesystem
input: dagger.#FS

// Path of the directory to create
// It can be nested (e.g : "/foo" or "/foo/bar")
path: string

// Permissions of the directory
permissions: *0o755 | int

// If set, it creates parents' directory if they do not exist
parents: *true | false

// Modified filesystem
output: dagger.#FS
}

#ReadFile: {
$dagger: task: _name: "ReadFile"

// Filesystem tree holding the file
input: dagger.#FS
// Path of the file to read
path: string
// Contents of the file
contents: string
}

// Write a file to a filesystem tree, creating it if needed
#WriteFile: {
$dagger: task: _name: "WriteFile"

// Input filesystem tree
input: dagger.#FS
// Path of the file to write
path: string
// Contents to write
contents: string
// Permissions of the file
permissions: *0o644 | int
// Output filesystem tree
output: dagger.#FS
}

// Copy files from one FS tree to another
#Copy: {
$dagger: task: _name: "Copy"
// Input of the operation
input: dagger.#FS
// Contents to copy
contents: dagger.#FS
// Source path (optional)
source: string | *"/"
// Destination path (optional)
dest: string | *"/"
// Optionally include certain files
include: [...string]
// Optionally exclude certain files
exclude: [...string]
// Output of the operation
output: dagger.#FS
}

#CopyInfo: {
source: {
root: dagger.#FS
path: string | *"/"
}
dest: string
}

// Merge multiple FS trees into one
#Merge: {
$dagger: task: _name: "Merge"
inputs: [...dagger.#FS]
output: dagger.#FS
}

// Extract the difference from lower FS to upper FS as its own FS
#Diff: {
$dagger: task: _name: "Diff"
lower: dagger.#FS
upper: dagger.#FS
output: dagger.#FS
}

// Select a subdirectory from a filesystem tree
#Subdir: {
// Input tree
input: dagger.#FS

// Path of the subdirectory
// Example: "/build"
path: string

// Copy action
_copy: #Copy & {
"input": dagger.#Scratch
contents: input
source: path
dest: "/"
}

// Subdirectory tree
output: dagger.#FS & _copy.output
}
32 changes: 32 additions & 0 deletions cue.mod/pkg/dagger.io/dagger/core/git.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package core

import "dagger.io/dagger"

// Push a directory to a git remote
#GitPush: {
@dagger(notimplemented)
$dagger: task: _name: "GitPush"

input: dagger.#FS
remote: string
ref: string
}

// Pull a directory from a git remote
// Warning: do NOT embed credentials in the remote url as this will expose them in logs.
// By using username and password Dagger will handle this for you in a secure manner.
#GitPull: {
$dagger: task: _name: "GitPull"
remote: string
ref: string
keepGitDir: true | *false
auth?: {
username: string
password: dagger.#Secret // can be password or personal access token
} | {
authToken: dagger.#Secret
} | {
authHeader: dagger.#Secret
}
output: dagger.#FS
}
Loading