Skip to content
Snippets Groups Projects
Commit 9818072b authored by Matthew K Defenderfer's avatar Matthew K Defenderfer
Browse files

overhaul to create a test package, publish it, and containerize it

parent 3db5eac8
No related branches found
No related tags found
No related merge requests found
Pipeline #11494 failed with stages
in 12 seconds
docker-build: stages:
# Use the official docker image. - build
image: docker:stable - test
- publish
variables:
PACKAGE_NAME: "pak"
DOCKER_IMAGE: "$CI_REGISTRY_IMAGE/$PACKAGE_NAME"
before_script:
- pip install setuptools
build_package:
stage: build 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: script:
- docker build --pull -t "$DOCKER_IMAGE_NAME" . - python setup.py sdist bdist_wheel
- docker push "$DOCKER_IMAGE_NAME" artifacts:
- | paths:
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then - dist/*
docker tag "$DOCKER_IMAGE_NAME" "$CI_REGISTRY_IMAGE:latest"
docker push "$CI_REGISTRY_IMAGE:latest" test_package:
fi stage: test
# Run this job in a branch where a Dockerfile exists script:
rules: - pip install . # Install the package
- if: $CI_COMMIT_BRANCH - pytest # Run tests
exists:
- Dockerfile 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
# Use a base image FROM python:3.12-slim
FROM ubuntu:22.04
RUN apt update && apt upgrade -y # Set working directory
RUN apt install -y python3.11 WORKDIR /app
# Print "Hello, World!" when the container starts # Copy the package files
CMD echo "Hello, World!" && echo "Hello again!" COPY . .
\ No newline at end of file
# 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
def hello():
return "Hello, World!"
\ No newline at end of file
[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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment