From 6d77d01e76119a97c1c29141b9a4439225383abd Mon Sep 17 00:00:00 2001
From: nguyed99 <nguyed99@zedat.fu-berlin.de>
Date: Thu, 18 Jan 2024 00:08:01 +0100
Subject: [PATCH] Implement CI/CD pipeline

---
 .gitlab-ci.yml                                | 26 +++++++++++++++++++
 README.md                                     |  4 +--
 build/build-image-CI.sh                       | 21 +++++++++++++++
 .../{build-image.sh => build-image-local.sh}  |  5 +---
 build/pyproject.toml                          |  1 +
 poetry.lock                                   | 13 +---------
 pyproject.toml                                |  1 -
 7 files changed, 52 insertions(+), 19 deletions(-)
 create mode 100644 .gitlab-ci.yml
 create mode 100644 build/build-image-CI.sh
 rename build/{build-image.sh => build-image-local.sh} (78%)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..ac65c8c
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,26 @@
+stages:
+- build
+- test-jobs
+- test-tasks
+
+variables:
+  REGISTRY: git.imp.fu-berlin.de:5000/nguyed99/comp-sci-project
+  CONTAINER_IMAGE: $REGISTRY:$CI_COMMIT_REF_SLUG
+
+before_script:
+  - echo "$CI_JOB_TOKEN" | docker login -u "$CI_REGISTRY_USER" --password-stdin $REGISTRY
+
+build-image:
+  stage: build
+  script:
+    - ./build/build-image-local.sh
+  
+test-jobs:
+  stage: test-jobs
+  script:
+    - docker run $CONTAINER_IMAGE /bin/sh -c "pytest /root/jobs/tests"
+
+test_tasks:
+  stage: test_tasks
+  script:
+    - docker run $CONTAINER_IMAGE /bin/sh -c "pytest /root/tasks/tests"
\ No newline at end of file
diff --git a/README.md b/README.md
index 1e1ef70..eb7f191 100644
--- a/README.md
+++ b/README.md
@@ -35,7 +35,7 @@ All folders are isolated projects. `cd` into the folder to run/build them.
 
 Jobs and tasks are run inside of docker containers. There is a docker build script (`Dockerfile`) and can be run in `dev` mode via `docker run`. Please be aware it can take a while to build the initial image. At root directory, to build the image run:
 
-    bash build/build_image.sh
+    bash build/build_image_local.sh
 
 The image is built now and ready to be used! The tests in the Docker container built from the image can be sanity-checked via :
 
@@ -49,6 +49,6 @@ For live experience (meaning you enter the container), run:
 
     docker run -it --rm git.imp.fu-berlin.de:5000/comp-sci-project/jobs-n-tasks:local /bin/bash
 
-If you change code in `src`, you need to rebuild the image with `bash build/build_image.sh`. The `src` folder can also be mounted in the image, but the assumption is that life is already difficult as it is...
+If you change code in `src`, you need to rebuild the image with `bash build/build_image_local.sh`. The `src` folder can also be mounted in the image, but the assumption is that life is already difficult as it is...
 
 *Free and open-source software for all souls! Technical support is, unfortunately, only for group members.*
\ No newline at end of file
diff --git a/build/build-image-CI.sh b/build/build-image-CI.sh
new file mode 100644
index 0000000..b109109
--- /dev/null
+++ b/build/build-image-CI.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+set -e
+
+CWD=$(cd $(dirname $0); pwd)
+
+REGISTRY=git.imp.fu-berlin.de:5000/nguyed99/comp-sci-project
+
+IMAGE=${REGISTRY}/jobs-n-tasks:${RELEASE:-CI}
+BASE_VERSION="3.11.5-slim"
+
+echo Building $IMAGE
+docker build \
+    --force-rm \
+    --rm=true \
+    -f "$CWD/Dockerfile" \
+    --platform linux/amd64 \
+    --build-arg BASE_VERSION=$BASE_VERSION \
+    -t $IMAGE \
+    "$CWD/.."
+
+docker push $IMAGE
\ No newline at end of file
diff --git a/build/build-image.sh b/build/build-image-local.sh
similarity index 78%
rename from build/build-image.sh
rename to build/build-image-local.sh
index db8fbbb..1e2f3c0 100644
--- a/build/build-image.sh
+++ b/build/build-image-local.sh
@@ -4,7 +4,6 @@ set -e
 CWD=$(cd $(dirname $0); pwd)
 
 REGISTRY=git.imp.fu-berlin.de:5000/comp-sci-project
-# REGISTRY=git.imp.fu-berlin.de:5000/nguyed99/comp-sci-project
 
 IMAGE=${REGISTRY}/jobs-n-tasks:${RELEASE:-local}
 BASE_VERSION="3.11.5-slim"
@@ -17,6 +16,4 @@ docker build \
     --platform linux/amd64 \
     --build-arg BASE_VERSION=$BASE_VERSION \
     -t $IMAGE \
-    "$CWD/.."
-
-# docker push $IMAGE
\ No newline at end of file
+    "$CWD/.."
\ No newline at end of file
diff --git a/build/pyproject.toml b/build/pyproject.toml
index b720e3f..1404e08 100644
--- a/build/pyproject.toml
+++ b/build/pyproject.toml
@@ -8,6 +8,7 @@ readme = "README.md"
 [tool.poetry.dependencies]
 python = ">=3.10"
 numpy = "~1.24"
+pytest = "^7.4.4"
 
 [build-system]
 requires = ["poetry-core"]
diff --git a/poetry.lock b/poetry.lock
index f60a2bb..b5d4ff7 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -200,17 +200,6 @@ docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments
 testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"]
 testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.1)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"]
 
-[[package]]
-name = "toml"
-version = "0.10.2"
-description = "Python Library for Tom's Obvious, Minimal Language"
-optional = false
-python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
-files = [
-    {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"},
-    {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"},
-]
-
 [[package]]
 name = "virtualenv"
 version = "20.25.0"
@@ -245,4 +234,4 @@ files = [
 [metadata]
 lock-version = "2.0"
 python-versions = "~3.11"
-content-hash = "5fb55aa2f5c5160e3650939ca59c21d342f2bee64420bd35a7c8309184ed7a7c"
+content-hash = "79e1810a3524adfaaf1d9aa0a659f9dc3c9f35f46f7daa71963d06e011323054"
diff --git a/pyproject.toml b/pyproject.toml
index 23d9dab..5ec364b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -12,7 +12,6 @@ python = "~3.11"
 ruff = "^0.0.267"
 pre-commit = "^3.3.1"
 yapf = "^0.32.0"
-toml = "^0.10.2"
 
 [build-system]
 requires = ["poetry-core"]
-- 
GitLab