Commit c64b2d0a authored by Lucas Mota's avatar Lucas Mota
Browse files

Initial commit

parents
No related merge requests found
Pipeline #8704 failed with stages
Showing with 341 additions and 0 deletions
+341 -0
stages:
- build
- deploy
build:
stage: build
image: docker:latest
services:
- docker:dind
script:
- echo "Realizando Login no Docker Hub"
- echo "$DOCKER_HUB_TOKEN" | docker login -u "$DOCKER_HUB_USER" --password-stdin
- echo "Construindo a imagem Docker"
- |
if [[ "$CI_COMMIT_REF_NAME" == "main" && -f "$ENV_PRODUCTION" ]]; then
echo "Usando as variáveis de ambiente de produção"
cp $ENV_PRODUCTION .env
elif [[ "$CI_COMMIT_REF_NAME" == "dev" && -f "$ENV_DEV" ]]; then
echo "Usando as variáveis de ambiente de desenvolvimento"
cp $ENV_DEV .env
else
echo "Arquivo de ambiente não encontrado para o branch $CI_COMMIT_REF_NAME!"
exit 1
fi
- docker build -t grupocometa/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME .
- echo "Enviando a imagem para o Docker Hub"
- docker push grupocometa/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME
only:
- main
- dev
deploy:
stage: deploy
image: grupocometa/helm:latest
before_script:
- echo "Configurando Helm"
- helm repo add stable https://charts.helm.sh/stable
- helm repo update
script:
- echo "Realizando Deploy com Helm"
- |
if [[ "$CI_COMMIT_REF_NAME" == "main" ]]; then
echo "Deploy em produção"
helm upgrade --install $CI_PROJECT_NAME ./helm/$CI_PROJECT_NAME --namespace $K8S_NAMESPACE_PRD --values $VALUES_DEV
elif [[ "$CI_COMMIT_REF_NAME" == "dev" ]]; then
echo "Deploy em desenvolvimento"
helm upgrade --install $CI_PROJECT_NAME ./helm/$CI_PROJECT_NAME --namespace $K8S_NAMESPACE_DEV --values $VALUES_PRD
else
echo "Branch não reconhecido para deploy"
exit 1
fi
- kubectl rollout status deployment/$CI_PROJECT_NAME -n $K8S_NAMESPACE
only:
- main
- dev
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
apiVersion: v2
name: helm-api
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "helm-api.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "helm-api.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "helm-api.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "helm-api.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
{{/*
Expand the name of the chart.
*/}}
{{- define "helm-api.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "helm-api.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "helm-api.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "helm-api.labels" -}}
helm.sh/chart: {{ include "helm-api.chart" . }}
{{ include "helm-api.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "helm-api.selectorLabels" -}}
app.kubernetes.io/name: {{ include "helm-api.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "helm-api.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "helm-api.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ .Release.Name }}
spec:
imagePullSecrets:
{{- toYaml .Values.imagePullSecrets | nindent 8 }}
containers:
- name: {{ .Release.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.targetPort }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- if .Values.pvc.enabled }}
volumeMounts:
{{- range .Values.pvc.volumeMounts }}
- name: {{ .name }}
mountPath: {{ .mountPath }}
{{- end }}
{{- end }}
{{- if .Values.pvc.enabled }}
volumes:
{{- range .Values.pvc.volumeMounts }}
- name: {{ .name }}
persistentVolumeClaim:
claimName: {{ .Release.Name }}
{{- end }}
{{- end }}
{{- if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Release.Name }}
annotations:
{{- toYaml .Values.ingress.annotations | nindent 4 }}
spec:
ingressClassName: {{ .Values.ingress.className }}
rules:
- host: {{ .Values.ingress.host }}
http:
paths:
- path: {{ .Values.path }}
pathType: {{ .Values.pathType }}
backend:
service:
name: {{ .Release.Name }}
port:
number: {{ .Values.service.port }}
{{- if .Values.ingress.tls.enabled }}
tls:
- hosts:
- {{ .Values.ingress.host }}
secretName: {{ .Release.Name }}
{{- end }}
{{- end }}
{{- if .Values.pvc.enabled }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .Release.Name }}
spec:
accessModes:
{{- toYaml .Values.pvc.accessModes | nindent 4 }}
resources:
requests:
storage: {{ .Values.pvc.storage }}
storageClassName: {{ .Values.pvc.storageClassName }}
{{- end }}
{{- if .Values.service.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}
spec:
type: {{ .Values.service.type }}
selector:
app: {{ .Release.Name }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.targetPort }}
{{- end }}
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "helm-api.fullname" . }}-test-connection"
labels:
{{- include "helm-api.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "helm-api.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
replicaCount: 1
image:
repository: grupocometa/api-gc-v2
tag: latest
pullPolicy: Always
ingress:
enabled: true
className: nginx
host: apigc.viacometa.com.br
path: "/api/?(.*)"
pathType: ImplementationSpecific
annotations:
cert-manager.io/issuer: letsencrypt
nginx.ingress.kubernetes.io/proxy-body-size: "100m"
nginx.ingress.kubernetes.io/rewrite-target: /$1
tls:
enabled: true
service:
enabled: true
type: ClusterIP
port: 80
targetPort: 8080
pvc:
enabled: false
accessModes:
- ReadWriteOnce
storage: 1Gi
storageClassName: nfs-client
volumeMounts:
- name: storage1
mountPath: /storage
- name: storage2
mountPath: /storage
resources:
requests:
memory: "250Mi"
cpu: "50m"
limits:
memory: "1000Mi"
cpu: "150m"
imagePullSecrets:
- name: dockerkey
Markdown is supported
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