Commit 87c9f32e authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Update GitLab-CI config to use templates

parent 20f8aba9
Loading
Loading
Loading
Loading
Loading
+43 −68
Original line number Diff line number Diff line
@@ -10,81 +10,56 @@ variables:
    description: Nginx release for the frontend image


.changes: &change-files
  changes:
  - .gitlab-ci.yml
  - Dockerfile
  - data/*
  - plugins/*
  - scripts/*

.build:
  stage: build
  image: docker.kodo.org.uk/ci-images/buildkit/buildctl:latest
  tags: [buildkit]
workflow:
  rules:
  - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    variables: {BUILD_RELEASE: "true"}
  - if: $CI_PIPELINE_SOURCE == "schedule"
  - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  - << : *change-files
  script:
  - BUILD_TAG=${CI_REGISTRY_IMAGE}/${TARGET}:build-${CI_PIPELINE_IID}
  - buildctl build
    --frontend=dockerfile.v0
    --local context=.
    --local dockerfile=.
    --opt target=${TARGET}
    --opt build-arg:nginx_version=${NGINX_VERSION}
    --opt build-arg:php_version=${PHP_VERSION}
    --opt build-arg:wp_version=${WORDPRESS_VERSION}
    --opt label:nginx.version=${NGINX_VERSION}
    --opt label:php.version=${PHP_VERSION}
    --opt label:wordpress.version=${WORDPRESS_VERSION}
    --output type=image,name=${BUILD_TAG},push=true
    variables: {BUILD_RELEASE: "true"}
  - when: always


.tag:
  stage: deploy
  image: docker.kodo.org.uk/ci-images/docker-reg:latest
  rules:
  - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "schedule"
    variables:
      TAG: latest
  - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    << : *change-files
    variables:
      TAG: latest
  - if: $CI_COMMIT_BRANCH == "develop"
    << : *change-files
    variables:
      TAG: unstable
  script: |
    BUILD_TAG=${CI_REGISTRY_IMAGE}/${TARGET}:build-${CI_PIPELINE_IID}
    docker-reg $BUILD_TAG retag $TAG
    if [ $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH ]; then
      docker-reg $BUILD_TAG retag $VERSION
    fi

include:
- project: dom/project-templates
  file: /pipeline-templates/pre-commit.yml

Build Wordpress:
  extends: [.build]
  variables:
    TARGET: fastcgi

Build Nginx:
  extends: [.build]
Build Images:
  stage: build
  rules:
  - if: $BUILD_RELEASE
    when: never
  - if: $CI_PIPELINE_SOURCE == "web"
  - changes:
    - .gitlab-ci.yml
    - Dockerfile
    - data/*
    - plugins/*
    - scripts/*
  variables:
    TARGET: nginx

    PLATFORMS: ""
    BUILD_ARGS: >-
      wp_version=$WORDPRESS_VERSION
      php_version=$PHP_VERSION
      nginx_version=$NGINX_VERSION
  parallel:
    matrix:
    - TARGET: [nginx, fastcgi]
  trigger:
    include:
    - project: dom/project-templates
      file: pipeline-templates/build-image.yml
    strategy: depend

Tag Wordpress Image:
  extends: [.tag]
  variables:
    TARGET: fastcgi
    VERSION: $WORDPRESS_VERSION

Tag Nginx Image:
  extends: [.tag]
  variables:
    TARGET: nginx
    VERSION: $NGINX_VERSION
Build Releases:
  stage: build
  extends: [Build Images]
  rules:
  - if: $BUILD_RELEASE
  parallel:
    matrix:
    - TARGET: [nginx]
      RELEASE: [$NGINX_VERSION]
    - TARGET: [fastcgi]
      RELEASE: [$WORDPRESS_VERSION]