Skip to content
Snippets Groups Projects
Commit edd53340 authored by Klaas Kliffen's avatar Klaas Kliffen :satellite:
Browse files

Merge branch 'ci-base-image-cookiecutter' into 'main'

Use docker base image across CI steps

See merge request python-package!17
parents 4124c594 fd7961a6
No related branches found
No related tags found
No related merge requests found
include: include:
- local: "{{cookiecutter.project_slug}}/.gitlab-ci.yml" - local: "{{cookiecutter.project_slug}}/.gitlab-ci.yml"
trigger_prepare:
stage: prepare
trigger:
strategy: depend
include: "{{cookiecutter.project_slug}}/.prepare.gitlab-ci.yml"
default: default:
before_script: before_script:
- python --version # For debugging - python --version # For debugging
- python -m pip install --upgrade pip
- pip install --upgrade cookiecutter tox twine
- cookiecutter --no-input --overwrite-if-exists -output-dir . - cookiecutter --no-input --overwrite-if-exists -output-dir .
FROM python:3.11
RUN python -m pip install --upgrade pip
RUN pip install --upgrade cookiecutter tox twine
default: default:
image: python:3.10 # use latest for building/linting image: $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG
before_script: before_script:
- python --version # For debugging - python --version # For debugging
- python -m pip install --upgrade pip
- pip install --upgrade tox twine
cache: cache:
paths: paths:
- .cache/pip - .cache/pip
# Do not cache .tox, to recreate virtualenvs for every step # Do not cache .tox, to recreate virtualenvs for every step
stages: stages:
- prepare
- lint - lint
# check if this needs to be a separate step # check if this needs to be a separate step
# - build_extensions # - build_extensions
...@@ -22,6 +21,14 @@ stages: ...@@ -22,6 +21,14 @@ stages:
variables: variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
# Prepare image to run ci on
trigger_prepare:
stage: prepare
trigger:
strategy: depend
include: .prepare.gitlab-ci.yml
run_black: run_black:
stage: lint stage: lint
script: script:
...@@ -45,9 +52,27 @@ run_pylint: ...@@ -45,9 +52,27 @@ run_pylint:
# script: # script:
# - echo "build fortran/c/cpp extension source code" # - echo "build fortran/c/cpp extension source code"
# Basic setup for all Python versions for which we don't have a base image
.run_unit_test_version_base:
before_script:
- python --version # For debugging
- python -m pip install --upgrade pip
- pip install --upgrade tox twine
# Run all unit tests for Python versions except the base image
run_unit_tests:
extends: .run_unit_test_version_base
stage: test
image: python:3.${PY_VERSION}
script:
- tox -e py3${PY_VERSION}
parallel:
matrix: # use the matrix for testing
- PY_VERSION: [7, 8, 9, 10]
# Run code coverage on the base image thus also performing unit tests
run_unit_tests_coverage: run_unit_tests_coverage:
stage: test stage: test
image: python:3.7
script: script:
- tox -e coverage - tox -e coverage
artifacts: artifacts:
...@@ -58,15 +83,6 @@ run_unit_tests_coverage: ...@@ -58,15 +83,6 @@ run_unit_tests_coverage:
paths: paths:
- htmlcov/* - htmlcov/*
run_unit_tests:
stage: test
image: python:3.${PY_VERSION}
script:
- tox -e py3${PY_VERSION}
parallel:
matrix: # use the matrix for testing
- PY_VERSION: [7, 8, 9, 10]
package_files: package_files:
stage: package stage: package
artifacts: artifacts:
......
stages:
- build
build_ci_runner_image:
stage: build
image: docker:stable
services:
- docker:dind
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- |
if docker pull $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG; then
docker build --cache-from $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG --tag $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG docker/ci-runner
else
docker pull $CI_REGISTRY_IMAGE/ci-build-runner:latest || true
docker build --cache-from $CI_REGISTRY_IMAGE/ci-build-runner:latest --tag $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG docker/ci-runner
fi
- docker push $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG # push the image
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
docker image tag $CI_REGISTRY_IMAGE/ci-build-runner:$CI_COMMIT_REF_SLUG $CI_REGISTRY_IMAGE/ci-build-runner:latest
docker push $CI_REGISTRY_IMAGE/ci-build-runner:latest
fi
FROM python:3.11
RUN python -m pip install --upgrade pip
RUN pip install --upgrade tox twine
...@@ -19,6 +19,7 @@ classifiers = ...@@ -19,6 +19,7 @@ classifiers =
Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Topic :: Internet :: WWW/HTTP Topic :: Internet :: WWW/HTTP
Topic :: Internet :: WWW/HTTP :: Dynamic Content Topic :: Internet :: WWW/HTTP :: Dynamic Content
Topic :: Scientific/Engineering Topic :: Scientific/Engineering
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment