Skip to content
Snippets Groups Projects
Commit 8514d4f5 authored by George Falileev's avatar George Falileev
Browse files

Merge branch 'master' into 'feature/MRM-2415'

ci

See merge request mashroom/backend/offer!149
parents c6484f9c f65201e6
Branches feature/MRM-2415
Tags
No related merge requests found
stages:
- test
- build
- deploy
#cache:
# key: "${CI_PROJECT_NAME}"
# paths:
# - .go-cicd/
services:
- name: docker:dind
alias: docker-dind
variables:
IMAGE_REGISTRY: "registry.gitlab.okta-solutions.com"
IMAGE_PATH: "${CI_PROJECT_PATH}"
IMAGE_TAG: "${CI_PIPELINE_ID}"
DOCKER_HOST: "tcp://127.0.0.1:2375"
GO111MODULE: "on"
CGO_ENABLED: "0"
GOOS: "linux"
GOARCH: "amd64"
GOPATH: "${CI_PROJECT_DIR}/.go-cicd"
GOBIN: "${CI_PROJECT_DIR}"
GOPRIVATE: "gitlab.okta-solutions.com/*"
before_script:
- export PATH="$GOBIN:$PATH"
test:
stage: test
only:
- merge_request
- master
- staging
- testing
- beta
- /^b[0-9]+\.[0-9]+\.[0-9]+/
image: registry.gitlab.okta-solutions.com/mashroom/backend/common/gobuild:1.14.3
script:
- go mod download
- go mod vendor
- go generate -v tools.go
- go generate -v
- grep -q -r 'ProtoReflect()' api/ || { echo "ProtoReflect() functions are missing in API, check your protoc and protoc-gen-go version"; exit 1; }
- CHECK_EXCLUDE="^.*\/vendor\/" gocheck.sh
- RUN_TESTS=1 go test -v ./...
build:
stage: build
only:
- merge_request
- master
- staging
- testing
- beta
- /^b[0-9]+\.[0-9]+\.[0-9]+/
image: registry.gitlab.okta-solutions.com/mashroom/backend/common/gobuild:1.14.3
script:
- go mod download
- go mod vendor
- go generate -v tools.go
- go generate -v
- go install -tags netgo -ldflags '-w -extldflags "-static"' -v ./cmd/...
- cp /etc/ssl/certs/ca-certificates.crt .
- echo "Logging to Container Registry..."
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
- echo "Building Dockerfile application..."
- docker build -f Dockerfile.cicd -t ${IMAGE_REGISTRY}/${IMAGE_PATH}:${IMAGE_TAG} .
- echo "Pushing to the Container Registry..."
- docker push ${IMAGE_REGISTRY}/${IMAGE_PATH}:${IMAGE_TAG}
- |
ENV_TYPE="staging"
if [ "$CI_COMMIT_REF_NAME" = "testing" ]; then
ENV_TYPE="testing"
elif [ "$CI_COMMIT_REF_NAME" = "beta" ]; then
ENV_TYPE="beta"
else
case "$CI_COMMIT_REF_NAME" in
b*.*.*) ENV_TYPE="beta-${CI_COMMIT_TAG}"
esac
fi
docker tag ${IMAGE_REGISTRY}/${IMAGE_PATH}:${IMAGE_TAG} ${IMAGE_REGISTRY}/${IMAGE_PATH}:${ENV_TYPE}
echo "Pushing ${ENV_TYPE} to Container Registry..."
docker push ${IMAGE_REGISTRY}/${IMAGE_PATH}:${ENV_TYPE}
deploy_beta_manual:
stage: deploy
image: dtzar/helm-kubectl:latest
cache: {}
when: manual
only:
- /^b[0-9]+\.[0-9]+\.[0-9]+/
script:
- export ENV_TYPE="beta"
- echo "Clonning charts"
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.okta-solutions.com/mashroom/devops/charts
- helm repo remove stable || true
- helm repo remove local || true
- find charts -name requirements.yaml -exec sh -c 'cd "$(dirname "{}")" && helm dependencies update' \;
- echo "Setting credentials"
- kubectl config set-cluster prod --server "${CLUSTER_PRODUCTION_URL}"
- kubectl config set clusters.prod.certificate-authority-data "${CLUSTER_PRODUCTION_CA}"
- kubectl config set-credentials cicd --token "${CLUSTER_PRODUCTION_TOKEN}"
- kubectl config set-context prod-cicd --cluster prod --user cicd
- kubectl config use-context prod-cicd
- echo "Deploy to ${ENV_TYPE} cluster"
- helm upgrade --namespace ${ENV_TYPE}-mashroom --install ${ENV_TYPE}-mashroom-${CI_PROJECT_NAME} charts/mashroom/${CI_PROJECT_NAME} -f charts/mashroom/${CI_PROJECT_NAME}/values-base.yaml -f charts/mashroom/${CI_PROJECT_NAME}/values-${ENV_TYPE}.yaml --set "mashroom.services.${CI_PROJECT_NAME}.image.tag=${IMAGE_TAG}"
deploy_staging:
stage: deploy
image: dtzar/helm-kubectl:latest
cache: {}
only:
- master
script:
- export ENV_TYPE="staging"
- echo "Clonning charts"
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.okta-solutions.com/mashroom/devops/charts
- helm repo remove stable || true
- helm repo remove local || true
- find charts -name requirements.yaml -exec sh -c 'cd "$(dirname "{}")" && helm dependencies update' \;
- echo "Setting credentials"
- kubectl config set-cluster "${ENV_TYPE}" --server "${CLUSTER_STAGING_URL}"
- kubectl config set "clusters.${ENV_TYPE}.certificate-authority-data" "${CLUSTER_STAGING_CA}"
- kubectl config set-credentials cicd --token "${CLUSTER_STAGING_TOKEN}"
- kubectl config set-context "${ENV_TYPE}-cicd" --cluster ${ENV_TYPE} --user cicd
- kubectl config use-context "${ENV_TYPE}-cicd"
- echo "Deploy to ${ENV_TYPE} cluster"
- helm upgrade --namespace ${ENV_TYPE}-mashroom --install ${ENV_TYPE}-mashroom-${CI_PROJECT_NAME} charts/mashroom/${CI_PROJECT_NAME} -f charts/mashroom/${CI_PROJECT_NAME}/values-base.yaml -f charts/mashroom/${CI_PROJECT_NAME}/values-${ENV_TYPE}.yaml --set "mashroom.services.${CI_PROJECT_NAME}.image.tag=${IMAGE_TAG}"
deploy_testing:
stage: deploy
image: dtzar/helm-kubectl:latest
cache: {}
only:
- testing
script:
- export ENV_TYPE="testing"
- echo "Clonning charts"
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.okta-solutions.com/mashroom/devops/charts
- helm repo remove stable || true
- helm repo remove local || true
- find charts -name requirements.yaml -exec sh -c 'cd "$(dirname "{}")" && helm dependencies update' \;
- echo "Setting credentials"
- kubectl config set-cluster "${ENV_TYPE}" --server "${CLUSTER_STAGING_URL}"
- kubectl config set "clusters.${ENV_TYPE}.certificate-authority-data" "${CLUSTER_STAGING_CA}"
- kubectl config set-credentials cicd --token "${CLUSTER_STAGING_TOKEN}"
- kubectl config set-context "${ENV_TYPE}-cicd" --cluster ${ENV_TYPE} --user cicd
- kubectl config use-context "${ENV_TYPE}-cicd"
- echo "Deploy to ${ENV_TYPE} cluster"
- helm upgrade --namespace ${ENV_TYPE}-mashroom --install ${ENV_TYPE}-mashroom-${CI_PROJECT_NAME} charts/mashroom/${CI_PROJECT_NAME} -f charts/mashroom/${CI_PROJECT_NAME}/values-base.yaml -f charts/mashroom/${CI_PROJECT_NAME}/values-${ENV_TYPE}.yaml --set "mashroom.services.${CI_PROJECT_NAME}.image.tag=${IMAGE_TAG}"
include:
- project: mashroom/devops/gitlab
file: /entrypoint/go/backend-generic.yaml
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