Testing Docker Builds via Python

I have a python script that builds several of my docker containers and publishes them. What is the recommended way to add such a configuration to GitLab CI/CD?

Requirements:
Python 3.x.x
pip install -r requirements.txt
docker build
docker push - optional

My .gitlab-ci.yml:

image: python:3.8.2

stages:
  - build
  - test

build:
  stage: build
  script:
    - echo "Building"
    - apt-get -qy update
    - apt-get install -qy docker
    - pip install -r requirements.txt
    - python build-and-upload.py