Skip to content
Snippets Groups Projects
.gitlab-ci.yml 1.59 KiB
Newer Older
egon w. stemle's avatar
egon w. stemle committed
variables:
egon w. stemle's avatar
egon w. stemle committed
  CONTAINER_IMAGE: "gitlab.inf.unibz.it:4567/commul/merlin-platform/www"
egon w. stemle's avatar
egon w. stemle committed
  DOCKER_BUILDER_IMAGE: "docker:19.03.1"
  DOCKER_TLS_CERTDIR: "" # See https://gitlab.com/gitlab-org/gitlab-runner/issues/4501
  KUBECTL: "https://storage.googleapis.com/kubernetes-release/release/v1.8.10/bin/linux/amd64/kubectl"

stages:
  - build
  - tag
  - deploy

build:
  stage: build
  tags:
    - commul
  image: ${DOCKER_BUILDER_IMAGE}
  services:
    - docker:dind
  before_script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN https://gitlab.inf.unibz.it:4567
  script:
    - docker build --rm --no-cache --tag=${CONTAINER_IMAGE}:${CI_COMMIT_SHA} .
    - docker push ${CONTAINER_IMAGE}:${CI_COMMIT_SHA}
egon w. stemle's avatar
egon w. stemle committed
    - docker tag ${CONTAINER_IMAGE}:${CI_COMMIT_SHA} ${CONTAINER_IMAGE}:latest
    - docker push ${CONTAINER_IMAGE}:latest
egon w. stemle's avatar
egon w. stemle committed
  only:
egon w. stemle's avatar
egon w. stemle committed
    - branches
egon w. stemle's avatar
egon w. stemle committed
deploy_staging:
  stage: deploy
  tags:
    - commul
  image: ${DOCKER_BUILDER_IMAGE}
  services:
    - docker:dind
  before_script:
    - wget ${KUBECTL}
    - mv kubectl /usr/bin/
    - chmod +x /usr/bin/kubectl
egon w. stemle's avatar
egon w. stemle committed
    - kubectl config set-cluster "k8sproduction" --server="$KUBE_URL" --certificate-authority="$KUBE_CA_PEM_FILE"
    - kubectl config set-credentials "gitlab-deploy" --token=$K8S_PRODUCTION_TOKEN
    - kubectl config set-context "$CI_PROJECT_ID" --cluster="k8sproduction" --user="gitlab-deploy" --namespace="kommul-dev"
    - kubectl config use-context "$CI_PROJECT_ID"
    # - kubectl config view
    # - env
egon w. stemle's avatar
egon w. stemle committed
  script:
egon w. stemle's avatar
egon w. stemle committed
    - kubectl set image deployment/merlin-platform-deployment webserver=${CONTAINER_IMAGE}:${CI_COMMIT_SHA}
egon w. stemle's avatar
egon w. stemle committed
  only:
egon w. stemle's avatar
egon w. stemle committed
    - branches