summaryrefslogtreecommitdiffstats
path: root/gitlab-templates
diff options
context:
space:
mode:
Diffstat (limited to 'gitlab-templates')
-rw-r--r--gitlab-templates/Docker.gitlab-ci.yml70
-rw-r--r--gitlab-templates/GoogleStorage.gitlab-ci.yml35
-rw-r--r--gitlab-templates/RTD.gitlab-ci.yml104
3 files changed, 209 insertions, 0 deletions
diff --git a/gitlab-templates/Docker.gitlab-ci.yml b/gitlab-templates/Docker.gitlab-ci.yml
new file mode 100644
index 000000000..8acb5a00e
--- /dev/null
+++ b/gitlab-templates/Docker.gitlab-ci.yml
@@ -0,0 +1,70 @@
+# Build and push a Docker image with CI/CD.
+# Docker-in-Docker documentation: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
+#
+# By default builds are tagged with their branch name and pushed to the
+# Gitlab Docker Registry. If DOCKER_TAG_LATEST is set to true, builds on
+# the $DOCKER_LATEST_BRANCH are also tagged and pushed as ":latest"
+#
+# Scheduled builds can be enabled on a Gitlab schedule by specifying
+# DOCKER_SCHEDULE = "true" in variables
+---
+variables:
+ # Docker registry where images will be pushed
+ DOCKER_REGISTRY: "$CI_REGISTRY"
+ DOCKER_USERNAME: "$CI_REGISTRY_USER"
+ DOCKER_TOKEN: "$CI_REGISTRY_PASSWORD"
+ # Whether or to push images after they're built
+ DOCKER_PUSH: "true"
+ # TODO: Conditionally include '--file' to docker build to reduce need
+ # to always define FILEPATH when BUILDCONTEXT is set
+ DOCKER_FILEPATH: "Dockerfile"
+ DOCKER_BUILDCONTEXT: "."
+ DOCKER_IMAGE: "$CI_REGISTRY_IMAGE"
+ # If LATEST_TAG is set to true, builds on the $DOCKER_LATEST_BRANCH
+ # will be tagged and pushed with ":latest"
+ DOCKER_LATEST_TAG: "true"
+ DOCKER_LATEST_BRANCH: "$CI_DEFAULT_BRANCH"
+
+.docker-build-and-push: &docker-build-and-push
+ image: docker:latest
+ stage: deploy
+ interruptible: true
+ services:
+ - docker:dind
+ before_script:
+ - docker login -u "$DOCKER_USERNAME" -p "$DOCKER_TOKEN" $DOCKER_REGISTRY
+ script:
+ # Warm the cache by fetching the latest image. There's no guarantee
+ # the image will already exist on the runner.
+ - docker pull "$DOCKER_IMAGE:${CI_COMMIT_REF_SLUG}" || true
+ - >
+ docker build
+ --pull
+ --cache-from "$DOCKER_IMAGE:${CI_COMMIT_REF_SLUG}"
+ --file "$DOCKER_FILEPATH"
+ --tag "$DOCKER_IMAGE:${CI_COMMIT_REF_SLUG}"
+ $DOCKER_BUILDCONTEXT
+ - |
+ if [[ "$CI_COMMIT_BRANCH" == "$DOCKER_LATEST_BRANCH" && "$DOCKER_LATEST_TAG" == "true" ]]; then
+ docker tag "$DOCKER_IMAGE:${CI_COMMIT_REF_SLUG}" "$DOCKER_IMAGE"
+ fi
+ - |
+ # Push docker images if DOCKER_PUSH is set
+ if [[ "$DOCKER_PUSH" == "true" ]]; then
+ docker push "$DOCKER_IMAGE:${CI_COMMIT_REF_SLUG}"
+ # Push ':latest' if LATEST_TAG is true
+ if [[ "$CI_COMMIT_BRANCH" == "$DOCKER_LATEST_BRANCH" && "$DOCKER_LATEST_TAG" == "true" ]]; then
+ docker push "$DOCKER_IMAGE"
+ fi
+ fi
+ rules:
+ - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
+ when: never
+ # Gitlab does not have a way of specifying which jobs are scheduled,
+ # so an extra variable is needed in order to signify docker build
+ # should be picked up by the schedule run.
+ - if: $CI_PIPELINE_SOURCE == "schedule" && $DOCKER_SCHEDULE != "true"
+ when: never
+ - if: '$CI_COMMIT_BRANCH == $DOCKER_LATEST_BRANCH'
+ - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
+ - if: $CI_COMMIT_TAG
diff --git a/gitlab-templates/GoogleStorage.gitlab-ci.yml b/gitlab-templates/GoogleStorage.gitlab-ci.yml
new file mode 100644
index 000000000..4ddf313d6
--- /dev/null
+++ b/gitlab-templates/GoogleStorage.gitlab-ci.yml
@@ -0,0 +1,35 @@
+# Template for uploading artifacts to Google Storage
+#
+# To upload artifacts to Google Storage, include this file in your
+# .gitlab-ci.yml file with the following stanza:
+#
+# include:
+# - project: anuket/releng
+# file: '/gitlab-templates/GoogleStorage.gitlab-ci.yml'
+#
+# And append the following "- !reference.." line to the script portion
+# of a job where artifacts should be uploaded:
+#
+# script:
+# ...
+# - !reference [.gsutil-install, script]
+# ...
+#
+# After the script has been included `gsutil` will have access to the
+# necessary Google Storage bucket.
+---
+variables:
+ GS_URL: "artifacts.opnfv.org/$CI_PROJECT_NAME"
+ WORKSPACE: $CI_PROJECT_DIR
+
+.gsutil-install: &gsutil-install
+ script:
+ - |
+ if command -v dnf &> /dev/null; then
+ dnf -y install python3-pip
+ else
+ yum -y install python3-pip
+ fi
+ - python3 -m pip install -U pip
+ - python3 -m pip install gsutil
+ - echo "$GSUTIL_CONFIG" > ~/.boto
diff --git a/gitlab-templates/RTD.gitlab-ci.yml b/gitlab-templates/RTD.gitlab-ci.yml
new file mode 100644
index 000000000..59b455d69
--- /dev/null
+++ b/gitlab-templates/RTD.gitlab-ci.yml
@@ -0,0 +1,104 @@
+# ReadTheDocs Workflow
+#
+# This workflow adds these builds to projects:
+#
+# docs-build:
+# Generate a html sphinx-build from the $DOCS_DIRECTORY
+#
+# docs-link-check:
+# Run a non-blocking sphinx-build linkcheck against
+# the $DOCS_DIRECTORY
+#
+# pages:
+# Serve the built documentation as the Gitlab Pages site for
+# the project
+#
+# Both docs-build and docs-link-check run on merge requests and merges
+# to the default branch that modify files under the $DOCS_DIRECTORY,
+# while pages only run on merges.
+#
+# Scheduled builds can be enabled when creating a schedule job and
+# specifying DOCS_SCHEDULE = "true" in build variables
+#
+# If extra dependencies are needed for builds they will be installed
+# from the $DOCS_REQUIREMENTS location.
+---
+variables:
+ PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
+ DOCS_DIRECTORY: "docs"
+ DOCS_REQUIREMENTS: "$DOCS_DIRECTORY/requirements.txt"
+ STABLE_BRANCH: "stable/*"
+
+.docs-cache: &docs-cache
+ paths:
+ - .cache/pip
+ - venv/
+
+.docs-before-script: &docs-before-script
+ - python -V
+ - pip install virtualenv
+ - virtualenv venv
+ - source venv/bin/activate
+ - pip install Sphinx
+ - |
+ if [ -f "$DOCS_REQUIREMENTS" ]; then
+ pip install -r "$DOCS_REQUIREMENTS"
+ fi
+
+docs-build:
+ stage: build
+ image: python:3
+ before_script:
+ - *docs-before-script
+ script: |
+ sphinx-build -T -b html -D language=en $DOCS_DIRECTORY _build/html
+ cache: *docs-cache
+ artifacts:
+ paths:
+ - _build/html
+ rules:
+ - if: $CI_PIPELINE_SOURCE == "schedule" && $DOCS_SCHEDULE != "true"
+ when: never
+ - if: $CI_PIPELINE_SOURCE == "merge_request_event"
+ changes:
+ - $DOCS_DIRECTORY/**/*
+ - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
+ - if: $CI_COMMIT_BRANCH == $STABLE_BRANCH
+
+docs-link-check:
+ stage: test
+ allow_failure: true
+ needs: []
+ image: python:3
+ before_script:
+ - *docs-before-script
+ script: |
+ sphinx-build -T -b linkcheck $DOCS_DIRECTORY _build/linkcheck
+ cache: *docs-cache
+ artifacts:
+ paths:
+ - _build/linkcheck
+ rules:
+ - if: $CI_PIPELINE_SOURCE == "schedule" && $DOCS_SCHEDULE != "true"
+ when: never
+ - if: $CI_PIPELINE_SOURCE == "merge_request_event"
+ changes:
+ - $DOCS_DIRECTORY/**/*
+ - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
+ - if: $CI_COMMIT_BRANCH == $STABLE_BRANCH
+
+pages:
+ stage: deploy
+ image: python:3
+ script: |
+ mkdir public
+ mv _build/html/* public/
+ artifacts:
+ paths:
+ - public
+ rules:
+ - if: $CI_PIPELINE_SOURCE == "schedule"
+ when: never
+ - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
+ changes:
+ - $DOCS_DIRECTORY/**/*