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

Create dagger pipeline #103

Open
wants to merge 4 commits into
base: main
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
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
branch="${GITHUB_REF##*/}"
fi
git checkout -b "$branch" || true
- name: Download latest earthly
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.7.23/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- name: Earthly version
run: earthly --version
- name: Run build
run: earthly --ci --allow-privileged +all
- name: Call Dagger Function
uses: dagger/dagger-for-github@v5
with:
version: "latest"
verb: call
args: test --source=.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
dist
src/shared
*.env
integration-test-output*
integration-test-output*
.idea
42 changes: 0 additions & 42 deletions Earthfile

This file was deleted.

6 changes: 6 additions & 0 deletions dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "remult-cli",
"sdk": "python",
"source": "dagger",
"engineVersion": "v0.11.5"
}
1 change: 1 addition & 0 deletions dagger/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/sdk/** linguist-generated
2 changes: 2 additions & 0 deletions dagger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/sdk
/.idea
18 changes: 18 additions & 0 deletions dagger/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[project]
name = "main"
version = "0.0.0"
dependencies = []

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.poetry]
name = "dagger-io"
description = "A client package for running Dagger pipelines in Python."
readme = "README.md"
license = "Apache-2.0"
authors = [
"hello"
]
version = "0.0.0"
446 changes: 446 additions & 0 deletions dagger/requirements.lock

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions dagger/src/main/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import dagger
from dagger import dag, function, object_type


@object_type
class RemultCli:
@function
def test_db_srv(self) -> dagger.Service:
"""Return a Postgres DB ready for running tests"""
return (
dag.container()
.from_("postgres:14-alpine")
.with_env_variable("POSTGRES_PASSWORD", "postgres")
.with_env_variable("POSTGRES_USER", "postgres")
.with_env_variable("POSTGRES_DB", "bookstore_db")
.with_exposed_port(5432)
.as_service()
)

@function
async def test(self, source: dagger.Directory) -> str:
"""Return the result of running unit tests"""
postgres_srv = self.test_db_srv()
return await (
self.build_env(source)
.with_service_binding("db", postgres_srv)
.with_exec(["bash", "-c",
"psql postgresql://postgres:postgres@db:5432/bookstore_db -a -f scripts/db/bookstore-schecma.sql"])
.with_exec(["pnpm", "test:ci"])
.stdout()
)

@function
def debug(self, source: dagger.Directory) -> dagger.Container:
"""Return container with db for debugging tests"""
postgres_srv = self.test_db_srv()
return (
self.build_env(source)
.with_service_binding("db", postgres_srv)
)

@function
def build_env(self, source: dagger.Directory) -> dagger.Container:
"""Build a ready-to-use development environment"""
node_cache = dag.cache_volume("node")
dist_cache = dag.cache_volume("dist")
return (
dag.container()
.from_("node:21-slim")
.with_directory("/src", source)
.with_mounted_cache("/src/node_modules", node_cache)
.with_workdir("/src")
.with_exec(["npm", "install", "-g", "pnpm"])
.with_exec(["pnpm", "install"])
.with_mounted_cache("/src/dist", dist_cache)
.with_exec(["pnpm", "build"])
.with_exec(["apt", "update"])
.with_exec(["apt", "install", "postgresql-client", "-y"])
)
2 changes: 1 addition & 1 deletion integration/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { exec as child_process_exec } from "child_process";
import { genId } from "../src/utils/genId";
const getOutput = genId("integration-test-output");
const exec = promisify(child_process_exec);
const connectionString = "postgres://postgres:postgres@localhost:5432";
const connectionString = "postgres://postgres:postgres@db:5432";
const lsOutputToArray = (stdout: string) => stdout.slice(0, -1).split("\n");

describe("postgres tests", () => {
Expand Down
Loading