diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ed08dec62450547e64f1a625c12263471b0dcbde..546bcba70e40972ce9fc45af97dc4ee5dded5eef 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,26 +1,39 @@ -docker-build: - # Use the official docker image. - image: docker:stable +stages: + - build + - test + - publish + +variables: + PACKAGE_NAME: "pak" + DOCKER_IMAGE: "$CI_REGISTRY_IMAGE/$PACKAGE_NAME" + +before_script: + - pip install setuptools + +build_package: stage: build - services: - - docker:26.0.1-dind - variables: - DOCKER_IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG - DOCKER_TLS_CERTDIR: "/certs" - before_script: - - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - # All branches are tagged with $DOCKER_IMAGE_NAME (defaults to commit ref slug) - # Default branch is also tagged with `latest` script: - - docker build --pull -t "$DOCKER_IMAGE_NAME" . - - docker push "$DOCKER_IMAGE_NAME" - - | - if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then - docker tag "$DOCKER_IMAGE_NAME" "$CI_REGISTRY_IMAGE:latest" - docker push "$CI_REGISTRY_IMAGE:latest" - fi - # Run this job in a branch where a Dockerfile exists - rules: - - if: $CI_COMMIT_BRANCH - exists: - - Dockerfile + - python setup.py sdist bdist_wheel + artifacts: + paths: + - dist/* + +test_package: + stage: test + script: + - pip install . # Install the package + - pytest # Run tests + +publish_package: + stage: publish + script: + - pip install twine # Install twine to publish the package + - twine upload dist/* # Publish the package to the GitLab package registry + +build_and_push_docker_image: + stage: publish + script: + - docker build -t $DOCKER_IMAGE:$CI_COMMIT_SHORT_SHA . + - docker push $DOCKER_IMAGE:$CI_COMMIT_SHORT_SHA + only: + - main # Only run on the main branch diff --git a/Dockerfile b/Dockerfile index 21ba29c3b0b4b57c6b952533f7792b596404a97a..87e038d462b2476bad0da0cbb89cd9ff1d9ce6f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,13 @@ -# Use a base image -FROM ubuntu:22.04 +FROM python:3.12-slim -RUN apt update && apt upgrade -y -RUN apt install -y python3.11 +# Set working directory +WORKDIR /app -# Print "Hello, World!" when the container starts -CMD echo "Hello, World!" && echo "Hello again!" \ No newline at end of file +# Copy the package files +COPY . . + +# Install the package +RUN pip install . + +# Command to run the package (adjust as needed) +CMD ["python", "-c", "from pak.hello import hello; print(hello())"] \ No newline at end of file diff --git a/pak/__init__.py b/pak/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/pak/hello.py b/pak/hello.py new file mode 100644 index 0000000000000000000000000000000000000000..b3219b6eb4c93f5bd864a1e0264443107339d517 --- /dev/null +++ b/pak/hello.py @@ -0,0 +1,2 @@ +def hello(): + return "Hello, World!" \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000000000000000000000000000000000..c132e8f6d8d5a7900f8d993c83af3e6e0be91e51 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,12 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "pak" +version = "0.1.0" +description = "A simple Python package." +authors = [{ name = "Your Name", email = "your.email@example.com" }] +dependencies = [ + "unittest" +] \ No newline at end of file diff --git a/tests/test_hello.py b/tests/test_hello.py new file mode 100644 index 0000000000000000000000000000000000000000..d78b64c04806d8c6ec93a5a6656d1e1a2962e2d9 --- /dev/null +++ b/tests/test_hello.py @@ -0,0 +1,9 @@ +import unittest +from mod.hello import hello + +class TestMyModule(unittest.TestCase): + def test_hello(self): + self.assertEqual(hello(), "Hello, World!") + +if __name__ == '__main__': + unittest.main() \ No newline at end of file