From dddad315021934463bc3a6fd904eca30fbb81d96 Mon Sep 17 00:00:00 2001 From: Matteo Bunino Date: Wed, 6 Nov 2024 08:57:32 +0100 Subject: [PATCH] Update CI --- .github/workflows/ci.yml | 25 +++++++++++++++++++++++++ ci/run.sh | 8 ++++++-- ci/src/main/__init__.py | 32 ++++++++++++++++++++++++-------- 3 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..240c2911 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: integration-tests + +on: + push: + #branches: [main,next,next2next] + pull_request: + +jobs: + build: + name: build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Get Repo Owner + id: get_repo_owner + run: echo ::set-output name=repo_owner::$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]') + - name: Integration Test + uses: dagger/dagger-for-github@v6 + with: + workdir: ci + verb: call + args: build-container --context=.. --dockerfile=../env-files/torch/Dockerfile publish + cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }} + version: "latest" \ No newline at end of file diff --git a/ci/run.sh b/ci/run.sh index 38f117e3..7e77eb72 100644 --- a/ci/run.sh +++ b/ci/run.sh @@ -1,4 +1,8 @@ # Example of running dagger pipeline of build and local test for torch container dagger call \ - build-torch --context=.. --dockerfile=../env-files/torch/Dockerfile \ - test-torch \ No newline at end of file + build-container --context=.. --dockerfile=../env-files/torch/Dockerfile \ + test-local + +dagger call \ + build-container --context=.. --dockerfile=../env-files/torch/Dockerfile \ + publish \ No newline at end of file diff --git a/ci/src/main/__init__.py b/ci/src/main/__init__.py index 2e3e04cb..e65e28ec 100644 --- a/ci/src/main/__init__.py +++ b/ci/src/main/__init__.py @@ -23,6 +23,7 @@ from typing import Annotated, Optional, Self import dataclasses +import random import dagger from dagger import dag, function, object_type, Doc @@ -31,10 +32,10 @@ @object_type class Itwinai: - torch_container: Optional[dagger.Container] = dataclasses.field(default=None, init=False) + container: Optional[dagger.Container] = dataclasses.field(default=None, init=False) @function - def build_torch( + def build_container( self, context: Annotated[ dagger.Directory, @@ -45,25 +46,40 @@ def build_torch( Doc("location of Dockerfile"), ], ) -> Self: - """Build itwinai torch container image from existing Dockerfile""" - self.torch_container = ( + """Build itwinai container image from existing Dockerfile""" + self.container = ( dag.container() .build(context=context, dockerfile=dockerfile) ) return self @function - async def test_torch(self) -> str: - """Test itwinai torch container image with pytest on non-HPC environments.""" + async def test_local(self) -> str: + """Test itwinai container image with pytest on non-HPC environments.""" test_cmd = [ "pytest", "-v", "-m", - "not hpc", + "not hpc and not functional", "tests" ] return await ( - self.torch_container + self.container .with_exec(test_cmd) .stdout() ) + + @function + async def publish( + self, + registry: str = "ghcr.io/intertwin-eu", + name: str = "itwinai-dev", + tag: Optional[str] = None + ) -> str: + """Push container to registry""" + tag = tag if tag else random.randrange(10 ** 8) + + # Test locally + await self.test_local() + + return await self.container.publish(f"{registry}/{name}:{tag}")