Commit dcd21043 authored by Carlos Juliano Viana's avatar Carlos Juliano Viana
Browse files

Refatorando o CICD para adicionar os jobs de Helm, mover os jobs de docker do...

Refatorando o CICD para adicionar os jobs de Helm, mover os jobs de docker do arquivo específico para o arquivo global de CICD.
 - Remoção do arquivo temporário de template.

[SOMA-6617]
[SOMA-4534]
parent 6aa45c9a
Pipeline #66989 failed with stages
in 1 minute and 31 seconds
include:
local: 'docker.gitlab-ci.yml'
#-------------------------
# Global Templates
#-------------------------
.docker_image_template: &docker_image_template
image: $CI_REGISTRY_PROXY_URL/docker:18-git
.docker_login: &docker_login
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY_URL
.docker_login_proxy: &docker_login_proxy
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY_PROXY_URL
.helm_kubectl_image_template: &helm_kubectl_image_template
image: repo.tecgraf.puc-rio.br:18089/soma/helm-kubectl:0.0.1
.services_docker_dind_template: &services_docker_dind_template
services:
- name: $CI_REGISTRY_PROXY_URL/docker:18-dind
#-------------------------
# Global Variables
#-------------------------
variables:
DOCKER_HOST: tcp://localhost:2375
DOCKER_DRIVER: overlay2
#-------------------------
# Job Stages
#-------------------------
stages:
- version
- build
- test
- release
- deploy
#-------------------------
# Versioning Jobs
#-------------------------
.versioning_template:
stage: version
image: docker:19.03.4
artifacts:
paths:
- shared-vars.sh
expire_in: 1 week
script:
- echo $SGA_VERSION
- echo "export VERSION=$SGA_VERSION" >> shared-vars.sh
stage: version
<<: *docker_image_template
artifacts:
paths:
- shared-vars.sh
expire_in: 1 week
script:
- echo $SGA_VERSION
- echo "export VERSION=$SGA_VERSION" >> shared-vars.sh
versioning_master:
extends: .versioning_template
before_script:
- export SGA_VERSION="latest"
- export SGA_VERSION="snapshot"
only:
- master
......@@ -35,8 +61,11 @@ versioning_tag:
only:
- tags
#-------------------------
# Test Job
#-------------------------
static_check:
stage: build
stage: test
image: repo.tecgraf.puc-rio.br:18089/soma/ubuntu:16.04-sga-posix
script:
- mkdir sgarest-daemon
......@@ -47,3 +76,163 @@ static_check:
only:
- master
- tags
#-------------------------
# Docker Jobs
#-------------------------
.docker_deploy:
stage: release
<<: *docker_image_template
<<: *services_docker_dind_template
script:
- *docker_login_proxy
- export DOCKER_BUILDKIT=1
- source shared-vars.sh
- export DOCKER_REGISTRY=${CI_REGISTRY_URL:+$CI_REGISTRY_URL/}
- export DOCKER_REGISTRY_IMAGE_DIND="${CI_REGISTRY_IMAGE}-dind"
- *docker_login
- docker pull $DOCKER_REGISTRY$CI_REGISTRY_IMAGE:$LAST || true
- docker pull $DOCKER_REGISTRY$DOCKER_REGISTRY_IMAGE_DIND:$LAST || true
- cd Docker/posix/
- |
docker build $BUILD_ARGS --cache-from $DOCKER_REGISTRY$CI_REGISTRY_IMAGE:$LAST \
--tag $DOCKER_REGISTRY$CI_REGISTRY_IMAGE:$VERSION \
--tag $DOCKER_REGISTRY$CI_REGISTRY_IMAGE:$LAST .
- sed -r "s%^FROM .*%FROM $DOCKER_REGISTRY$CI_REGISTRY_IMAGE:$VERSION%" Dockerfile_sgadocker > /tmp/sgadind
- |
docker build --cache-from $DOCKER_REGISTRY$DOCKER_REGISTRY_IMAGE_DIND:$LAST \
--tag $DOCKER_REGISTRY$DOCKER_REGISTRY_IMAGE_DIND:$VERSION \
--tag $DOCKER_REGISTRY$DOCKER_REGISTRY_IMAGE_DIND:$LAST -f /tmp/sgadind .
- rm -f /tmp/sgadind
- docker push $DOCKER_REGISTRY$CI_REGISTRY_IMAGE:$VERSION
- docker push $DOCKER_REGISTRY$CI_REGISTRY_IMAGE:$LAST
- docker push $DOCKER_REGISTRY$DOCKER_REGISTRY_IMAGE_DIND:$VERSION
- docker push $DOCKER_REGISTRY$DOCKER_REGISTRY_IMAGE_DIND:$LAST
docker_snapshot:
extends: .docker_deploy
before_script:
- export LAST="snapshot"
only:
- master
docker_release:
extends: .docker_deploy
before_script:
- export LAST="latest"
- export BUILD_ARGS="--build-arg TAG=${CI_COMMIT_TAG}"
only:
- tags
#-------------------------
# Helm Jobs
#-------------------------
.lint_helm:
stage: test
<<: *docker_image_template
<<: *services_docker_dind_template
script:
- *docker_login_proxy
- source shared-vars.sh
- cat ${CI_KUBE_CONFIG_FILE} > .kube/kube-config.yaml
- sed -i.bak "s/__VERSION__/${VERSION}/" kubernetes/posix/helm/Chart.yaml
- cat kubernetes/posix/helm/Chart.yaml
- (docker run --rm -e KUBECONFIG=".kube/kube-config.yaml" -v $(pwd):/apps -v ~/.kube:/root/.kube -v ~/.helm:/root/.helm $CI_REGISTRY_PROXY_URL/alpine/helm:3.2.1 lint kubernetes/posix/helm/ --strict -f kubernetes/posix/helm/demo/${LINT_VALUES_FILE}) | tee /tmp/helm-lint.log
- ([ $(grep -c ERROR /tmp/helm-lint.log) -gt 0 ] && exit 1 || exit 0)
artifacts:
paths:
- kubernetes/posix/helm/Chart.yaml
expire_in: 1 day
lint_helm_snapshot:
extends: .lint_helm
before_script:
- export LINT_VALUES_FILE=dev-values.yaml
only:
- master
lint_helm_latest:
extends: .lint_helm
before_script:
- export LINT_VALUES_FILE=hml-values.yaml
only:
- tags
#---------------------------------
# Helm Package
#---------------------------------
package_helm:
stage: release
<<: *helm_kubectl_image_template
script: |
source shared-vars.sh
export CHART_NAME="$(grep -E "^name:" kubernetes/posix/helm/Chart.yaml | cut -d":" -f2 | sed -e 's/^[ \t]*//')"
export CHART_VERSION="$(grep -E "^version:" kubernetes/posix/helm/Chart.yaml | cut -d":" -f2 | sed -e 's/^[ \t]*//')"
export APP_VERSION="$(grep -E "^appVersion:" kubernetes/posix/helm/Chart.yaml | cut -d":" -f2 | sed -e 's/^[ \t]*//')"
export PACKAGE_NAME="${CHART_NAME}-${CHART_VERSION}"
printf "\n#--------------------------------------------------------------"
printf "\n# Helm packaging..."
printf "\n#--------------------------------------------------------------\n"
helm package kubernetes/posix/helm/ -d /tmp/
printf "\n#--------------------------------------------------------------"
printf "\n# Cleaning old Chart package $PACKAGE_NAME.tgz"
printf "\n#--------------------------------------------------------------\n"
curl -I -X DELETE -u ${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD} ${CI_HELM_REGISTRY_URL}/$PACKAGE_NAME.tgz || true
printf "\n#--------------------------------------------------------------"
printf "\n# Uploading Chart package $PACKAGE_NAME.tgz"
printf "\n#--------------------------------------------------------------\n"
curl -I -u ${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD} ${CI_HELM_REGISTRY_URL}/ --upload-file /tmp/$PACKAGE_NAME.tgz
only:
- master
- tags
# -----------------------
# Deploy Stage
# -----------------------
.helm_upgrade:
stage: deploy
<<: *helm_kubectl_image_template
script:
- cat ${CI_KUBE_CONFIG_FILE} > .kube/kube-config.yaml
- export KUBERNETES_CONTEXT="K8S-CONTEXT-PACKAGE-${CI_COMMIT_SHORT_SHA}"
- kubectl config set-cluster "$CI_KUBERNETES_CLUSTER" --insecure-skip-tls-verify=true --server="$CI_KUBERNETES_URL"
- kubectl config set-context "$KUBERNETES_CONTEXT" --cluster="$CI_KUBERNETES_CLUSTER" --user="$CI_KUBERNETES_USER_NAME"
- kubectl config set-credentials "$CI_KUBERNETES_USER_NAME" --token="$CI_KUBERNETES_USER_TOKEN"
- kubectl config use-context "$KUBERNETES_CONTEXT"
- export CHART_NAME="$(grep -E "^name:" kubernetes/posix/helm/Chart.yaml | cut -d":" -f2 | sed -e 's/^[ \t]*//')"
- export CHART_VERSION="$(grep -E "^version:" kubernetes/posix/helm/Chart.yaml | cut -d":" -f2 | sed -e 's/^[ \t]*//')"
- export RELEASE_NAME="${CHART_NAME}-${RELEASE_NAME_SUFFIX}"
- helm repo add soma-charts-nexus ${CI_HELM_REGISTRY_URL} --username ${CI_REGISTRY_USER} --password ${CI_REGISTRY_PASSWORD}
- helm repo list | grep soma-charts-nexus
- helm upgrade --install --namespace ${NAMESPACE} ${RELEASE_NAME} soma-charts-nexus/${CHART_NAME} --version=${CHART_VERSION} --values kubernetes/posix/helm/demo/${FILES_NAME} --set-string podAnnotations.commit=${CI_COMMIT_SHA} --dry-run >> ${ARTIFACT_NAME}
- helm upgrade --install --namespace ${NAMESPACE} ${RELEASE_NAME} soma-charts-nexus/${CHART_NAME} --version=${CHART_VERSION} --values kubernetes/posix/helm/demo/${FILES_NAME} --set-string podAnnotations.commit=${CI_COMMIT_SHA}
deploy_snapshot:
extends: .helm_upgrade
before_script:
- export NAMESPACE=soma-dev
- export RELEASE_NAME_SUFFIX=snapshot
- export FILES_NAME="dev-values.yaml"
- export ARTIFACT_NAME="helm-dev.log"
artifacts:
paths:
- helm-dev.log
expire_in: 1 month
only:
- master
deploy_latest:
extends: .helm_upgrade
before_script:
- export NAMESPACE=soma-hml
- export RELEASE_NAME_SUFFIX=latest
- export FILES_NAME="hml-values.yaml"
- export ARTIFACT_NAME="helm-hml.log"
artifacts:
paths:
- helm-hml.log
expire_in: 1 month
only:
- tags
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "sgarest-daemon.fullname" . }}
labels:
{{- include "sgarest-daemon.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "sgarest-daemon.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "sgarest-daemon.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
# initContainers:
# - name: init-create-file-healthy
# image: alpine:latest
# command: ["/bin/sh", "-c"]
# args:
# - touch /sgad/logs/healthy
# volumeMounts:
# - name: sgarest-daemon-data-storage
# mountPath: /sgad/logs
# subPath: logs
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
command: ["sh"]
#args: ["/sgad/config/sgad.cfg"]
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 40100
protocol: TCP
{{- if and .Values.env (not .Values.configurationFiles) }}
envFrom:
- configMapRef:
name: {{ include "sgarest-daemon.fullname" . }}-configmap-config
{{- end }}
volumeMounts:
{{- if .Values.configurationFiles }}
- name: sgarest-daemon-data-storage-config-files
mountPath: /mnt
# mountPath: /sgad/config
# subPath: config
{{- end }}
# {{- if not .Values.configurationFiles.transferMechanism }}
# - name: sgarest-daemon-data-storage
# mountPath: /sgad/projects
# subPath: projects
# - name: sgarest-daemon-data-storage
# mountPath: /sgad/algorithms
# subPath: algorithms
# {{- end }}
# - name: sgarest-daemon-data-storage
# mountPath: /sgad/logs
# subPath: logs
# livenessProbe:
# tcpSocket:
# port: http
# {{- with .Values.livenessProbe }}
# {{- toYaml . | nindent 12 }}
# {{- end }}
# readinessProbe:
# exec:
# command:
# - cat
# - /sgad/logs/healthy
# {{- with .Values.readinessProbe }}
# {{- toYaml . | nindent 12 }}
# {{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
{{- if .Values.configurationFiles }}
- name: sgarest-daemon-data-storage-config-files
configMap:
name: {{ include "sgarest-daemon.config-files.name" . }}
{{- end }}
# - name: sgarest-daemon-data-storage
# persistentVolumeClaim:
# claimName: {{ include "sgarest-daemon.pvc.name" . }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment