今天繼續研究 Gitlab 的CI/CD 設定,找了一些 python 的 .gitlab-ci.yml 範例,並且嘗試在 gitlab 上面跑.
Using Gitlab CI Feature To Build and Test Python Flask Application and MongoDB
image: "python:3.5"
services:
- mongo:latest
variables:
MONGO_DB: test
before_script:
- python --version
- pip install virtualenv
stages:
- build
- test
build:
stage: build
script: cd schema && make && cd ../server && make
test:
stage: test
script: ./ci-test.sh
Using Gitlab pipelines to deploy Python packages in production and staging environments
image: python:3.6-alpine
stages:
- deploy
before_script:
- pip install twine
- python setup.py sdist
deploy_staging:
stage: deploy
variables:
TWINE_USERNAME: $STAGING_USERNAME
TWINE_PASSWORD: $STAGING_PASSWORD
script:
- twine upload --repository-url $PYPRI_REPOSITORY_URL dist/*
except:
- tags
deploy_production:
stage: deploy
variables:
TWINE_USERNAME: $PRODUCTION_USERNAME
TWINE_PASSWORD: $PRODUCTION_PASSWORD
script:
- twine upload dist/*
only:
- tags
中級篇』docker之CI/CD持續集成—真實Python項目的CI演示(72)
stages:
- style
- test
pep8:
stage: style
script:
- pip install tox
- tox -e pep8
tags:
- python2.7
unittest-py27:
stage: test
script:
- pip install tox
- tox -e py27
tags:
- python2.7
unittest-py34:
stage: test
script:
- pip install tox
- tox -e py34
tags:
- python3/4
---
###
# Ithome_pellok_2018 GitLab CI/CD config
###
image: python:3.5-alpine
stages:
- test
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache"
# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/reference/pip_install/#caching
# To cache them, install in a virtualenv and cache it, too
cache:
paths:
- .cache/pip
- venv/
before_script:
- apk update && apk upgrade
- apk add build-base
- python -m pip install --quiet --upgrade pip
- python --version
- pip --version
- pip install --quiet virtualenv
- virtualenv venv
- source venv/bin/activate
- pip install --quiet -r requirement.txt
pytest_test_job:
stage: test
script:
- pytest --cov
Gitlab 測試都是靠設定 .gitlab-ci.yml 檔案,目前只研究到 Test 的部分.
Gitlab 官網
Using Gitlab CI Feature To Build and Test Python Flask Application and MongoDB
Using Gitlab pipelines to deploy Python packages in production and staging environments