Skip to content
cd-deploy-ocf.gitlab-ci.yml 5.29 KiB
Newer Older
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
stages:
  - deploy_ocf_staging
  - delete_ocf_staging
  - deploy_ocf_dev
  - delete_ocf_dev

variables:
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
  NAMESPACE_DEV: "ocf-dev-$CI_PROJECT_PATH_SLUG"
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
  NAMESPACE_STAGING: "ocf-staging"
  DOMAIN_STAGING: staging.int
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
  DOMAIN_DEV: developer.int
  DOMAIN_PROD: prod.int
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
  CI_JOB_TOKEN: $CI_JOB_TOKEN
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
  IMAGE_TAG_DEV: $CI_COMMIT_REF_SLUG
  IMAGE_TAG_STAGING: $CI_COMMIT_REF_SLUG
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
  VAULT_HOSTNAME: $VAULT_HOSTNAME
  VAULT_PORT: $VAULT_PORT
  VAULT_ACCESS_TOKEN: $VAULT_ACCESS_TOKEN
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed

.main_common: &main_common
  only:
    - merge_requests
  except:
    variables:
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#      - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "main"
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
      - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "staging"
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
.staging_common: &staging_common
  only:
    - merge_requests
  except:
    variables:
      - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "staging"
  tags:
    - shell

.dev_common: &dev_common
  tags:
    - shell

deploy_ocf_staging:
  stage: deploy_ocf_staging
  needs:
    - staging_build_and_push
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
  <<: *staging_common
  environment:
    name: review/staging
    url: https://$NAMESPACE_STAGING.$DOMAIN_STAGING
    on_stop: delete_ocf_staging
    auto_stop_in: 3 day
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#  rules:
#    - if: $CI_COMMIT_BRANCH == "main"
#      when: never
#    - if: $CI_COMMIT_BRANCH == "staging"
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
  script:
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#    - echo "### git clone OCF repo ###" 
#    - git clone https://oauth2:${CI_JOB_TOKEN}@labs.etsi.org/rep/ocf/capif.git
#    - echo "### install helm###"
#    - curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
#    - chmod 700 get_helm.sh
#    - sudo ./get_helm.sh
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - whoami
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - helm version
    - kubectl version --output=yaml
    - echo "### setting kubeconfig###"
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - whoami
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - kubectl cluster-info
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - yq --version
    - ls -rtt helm/capif
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - cat helm/capif/Chart.yaml
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - yq e -i ".appVersion = \"$IMAGE_TAG_STAGING\"" helm/capif/Chart.yaml
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - cat helm/capif/Chart.yaml
    - echo "### download dependencies###"
    - helm dependency build helm/capif
    - echo "### updating capif###"
#    - helm uninstall -n $NAMESPACE_STAGING ocf-staging --kubeconfig ~/cluster.kubeconfig || true
#    - helm upgrade --install -n $NAMESPACE_STAGING ocf helm/capif/ \
#      --set nginx.nginx.env.capifHostname=capif.$DOMAIN_STAGING \
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#      --set nginx.nginx.env.registerHostname=register.$DOMAIN_STAGING \
#      --set monitoring.prometheus.ingress.hosts[0].host=prometheus.$DOMAIN_PROD \
#      --set monitoring.prometheus.ingress.hosts[0].paths[0].path=/ \
#      --set monitoring.prometheus.ingress.hosts[0].paths[0].pathType=Prefix  \
#      --set monitoring.prometheus.enable="" \
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#      --set monitoring.grafana.ingress.hosts[0].host="grafana.$DOMAIN_PROD" \
#      --set monitoring.grafana.ingress.hosts[0].paths[0].path="/" \
#      --set monitoring.grafana.ingress.hosts[0].paths[0].pathType="Prefix" \
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#      --set backOffice.frontend.env.grafanaUrl=http://grafana.$DOMAIN_PROD \
#      --set parametersVault.env.vaultHostname=$VAULT_HOSTNAME \
#      --set parametersVault.env.vaultPort=$VAULT_PORT \
#      --set parametersVault.env.vaultAccessToken=$VAULT_ACCESS_TOKEN \
#      --wait --timeout=10m --atomic \
#      --create-namespace
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed


delete_ocf_staging:
  stage: delete_ocf_staging
  <<: *staging_common
  script:
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - echo "### deleting environment $NAMESPACE_STAGING###"
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#    - helm uninstall -n $NAMESPACE_STAGING ocf-staging
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
  when: manual
  environment:
    name: review/staging
    action: stop

## dev ###
deploy_ocf_dev:
  stage: deploy_ocf_dev
  needs:
    - dev_build_and_push
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
  <<: *dev_common
  environment:
    name: review/$CI_COMMIT_REF_SLUG
    url: https://$NAMESPACE_DEV.$DOMAIN_DEV
    on_stop: delete_ocf_dev
    auto_stop_in: 3 day
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#  rules:
#    - if: $CI_COMMIT_BRANCH == "main"
#      when: never
#    - if: $CI_COMMIT_BRANCH == "staging"
#      when: never      
#    - if: $CI_COMMIT_BRANCH
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
  script:
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - helm version
    - kubectl version --output=yaml
    - echo "### setting kubeconfig###"
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - kubectl cluster-info
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - yq --version
    - cat helm/capif/Chart.yaml
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - yq e -i ".appVersion = \"$IMAGE_TAG_DEV\"" helm/capif/Chart.yaml
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
    - cat helm/capif/Chart.yaml
    - echo "### download dependencies###"
    - helm dependency build helm/capif
#    - echo "### updating capif###"
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#    - helm uninstall -n $NAMESPACE_DEV ocf-dev --kubeconfig ~/cluster.kubeconfig || true
#    - helm upgrade --install -n $NAMESPACE_DEV ocf-developer helm/capif/ \
#      --set nginx.nginx.env.capifHostname=capif-CI_PROJECT_PATH_SLUG.$DOMAIN_DEV \
#      --set nginx.nginx.env.registerHostname=register-CI_PROJECT_PATH_SLUG.$DOMAIN_DEV
#      --set monitoring.prometheus.enable="" \
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#      --set monitoring.grafana.ingress.hosts[0].host="grafana.$DOMAIN_PROD" \
#      --set monitoring.grafana.ingress.hosts[0].paths[0].path="/" \
#      --set monitoring.grafana.ingress.hosts[0].paths[0].pathType="Prefix" \
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#      --set parametersVault.env.vaultHostname=$VAULT_HOSTNAME \
#      --set parametersVault.env.vaultPort=$VAULT_PORT \
#      --set parametersVault.env.vaultAccessToken=$VAULT_ACCESS_TOKEN \
#      --wait --timeout=10m \
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#      --create-NAMESPACE_STAGING --atomic
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed

delete_ocf_dev:
  stage: delete_ocf_dev
  <<: *staging_common
  script:
    - echo "### deleting environment $NAMESPACE_DEV###"
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
#    - helm uninstall -n $NAMESPACE_DEV ocf-dev
Andres Anaya Amariels's avatar
Andres Anaya Amariels committed
  when: manual
  environment:
    name: review/$CI_COMMIT_REF_SLUG
    action: stop