Skip to content
Snippets Groups Projects
Commit d5dcf74e authored by Dobromir Palushev's avatar Dobromir Palushev
Browse files

Workflow updates

parent abec3338
No related branches found
No related tags found
3 merge requests!72Production update,!70Production update,!68Workflow updates
......@@ -23,29 +23,13 @@ stages:
.gke-initialization:
image: google/cloud-sdk:${GOOGLE_CLOUD_SDK_IMAGE_VERSION}
before_script:
# BASE64_GOOGLE_CREDENTIALS is a masked CI/CD GitLab variable
- echo $BASE64_GOOGLE_CREDENTIALS | base64 -d > ~/service_account.json
- gcloud auth activate-service-account --key-file ~/service_account.json
- gcloud config set project ${GCP_PROJECT_ID}
- gcloud config set compute/zone ${GCP_COMPUTE_REGION}
- gcloud container clusters get-credentials ${GCP_PROJECT_ID}-gke
.gke-deployment:
extends: .gke-initialization
tags:
- docker
script:
- IMAGE="${CI_REGISTRY_IMAGE}:$VERSION"
- cd "./k8s-manifests"
- kubectl apply -f gitlab-registry-credentials.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
- SECRETS_MANIFEST=$(sed -e "s,{{jwtSecret}},${JWT_SECRET},g" ./secrets.yaml.tmpl)
- echo "${SECRETS_MANIFEST}" | kubectl apply --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}" --filename -
- kubectl apply -f configmap.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
- DEPLOYMENT_MANIFEST=$(sed -e "s,{{image}},${IMAGE},g" ./deployment.yaml.tmpl)
- echo "${DEPLOYMENT_MANIFEST}" | kubectl apply --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}" --filename -
- kubectl apply -f service.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
- INGRESS_MANIFEST=$(sed -e "s,{{static-ip-name}},${STATIC_IP},g" -e "s,{{allowHttpFlag}},true,g" -e "s,{{portNumber}},80,g" ./ingress.yaml.tmpl)
- echo "${INGRESS_MANIFEST}" | kubectl apply --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}" --filename -
run-tests:
stage: test
tags:
......@@ -108,7 +92,7 @@ create-release-image:
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
- docker pull "${CONTAINER_TAG}"
script:
- VERSION=$(grep '"version"' ./app/client/package.json | cut -d '"' -f 4 | head -n 1)
- VERSION=$(grep '"version"' ./app/app-version.json | cut -d '"' -f 4 | head -n 1)
- docker tag "${CONTAINER_TAG}" "${CI_REGISTRY_IMAGE}:${VERSION}"
- docker push "${CI_REGISTRY_IMAGE}:${VERSION}"
after_script:
......@@ -132,17 +116,18 @@ create-release-tag:
- PROJECT_URL=$(echo $CI_PROJECT_URL | sed 's/https:\/\///')
- git remote set-url origin https://oauth2:${APP_CI_ACCESS_TOKEN}@${PROJECT_URL}
script:
- VERSION=$(grep '"version"' ./app/client/package.json | cut -d '"' -f 4 | head -n 1)
- VERSION=$(grep '"version"' ./app/app-version.json | cut -d '"' -f 4 | head -n 1)
- echo ${VERSION}
- TAG=v${VERSION}
- git tag $TAG && git push origin $TAG
allow_failure: true
deploy-new-staging-version:
extends: .gke-deployment
stage: deploy
needs:
- 'build-image'
tags:
- docker
rules:
- if: $CI_COMMIT_REF_NAME =~ /staging/
when: 'always'
......@@ -151,6 +136,19 @@ deploy-new-staging-version:
STATIC_IP: staging-todoapp-ip
VERSION: ${CI_PIPELINE_IID}-${CI_COMMIT_SHORT_SHA}
- when: never
script:
- IMAGE="${CI_REGISTRY_IMAGE}:$VERSION"
- cd "./k8s-manifests"
- kubectl apply -f gitlab-registry-credentials.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
# JWT_SECRET is a masked CI/CD GitLab variable
- SECRETS_MANIFEST=$(sed -e "s,{{jwtSecret}},${JWT_SECRET},g" ./secrets.yaml.tmpl)
- echo "${SECRETS_MANIFEST}" | kubectl apply --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}" --filename -
- kubectl apply -f configmap.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
- DEPLOYMENT_MANIFEST=$(sed -e "s,{{image}},${IMAGE},g" ./deployment.yaml.tmpl)
- echo "${DEPLOYMENT_MANIFEST}" | kubectl apply --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}" --filename -
- kubectl apply -f service.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
- INGRESS_MANIFEST=$(sed -e "s,{{static-ip-name}},${STATIC_IP},g" -e "s,{{allowHttpFlag}},true,g" -e "s,{{portNumber}},80,g" -e "s,{{suffix}},${ENVIRONMENT_NAME},g" ./ingress.yaml.tmpl)
- echo "${INGRESS_MANIFEST}" | kubectl apply --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}" --filename -
deploy-new-release:
extends: .gke-initialization
......@@ -167,17 +165,18 @@ deploy-new-release:
tags:
- docker
script:
- VERSION=$(grep '"version"' ./app/client/package.json | cut -d '"' -f 4 | head -n 1)
- VERSION=$(grep '"version"' ./app/app-version.json | cut -d '"' -f 4 | head -n 1)
- IMAGE="${CI_REGISTRY_IMAGE}:$VERSION"
- cd "./k8s-manifests"
- kubectl apply -f gitlab-registry-credentials.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
# JWT_SECRET is a masked CI/CD GitLab variable
- SECRETS_MANIFEST=$(sed -e "s,{{jwtSecret}},${JWT_SECRET},g" ./secrets.yaml.tmpl)
- echo "${SECRETS_MANIFEST}" | kubectl apply --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}" --filename -
- kubectl apply -f configmap.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
- DEPLOYMENT_MANIFEST=$(sed -e "s,{{image}},${IMAGE},g" ./deployment.yaml.tmpl)
- echo "${DEPLOYMENT_MANIFEST}" | kubectl apply --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}" --filename -
- kubectl apply -f service.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
- INGRESS_MANIFEST=$(sed -e "s,{{static-ip-name}},${STATIC_IP},g" -e "s,{{allowHttpFlag}},true,g" -e "s,{{portNumber}},80,g" -e "s,{{suffix}},production,g" ./ingress.yaml.tmpl)
- INGRESS_MANIFEST=$(sed -e "s,{{static-ip-name}},${STATIC_IP},g" -e "s,{{allowHttpFlag}},true,g" -e "s,{{portNumber}},80,g" -e "s,{{suffix}},${ENVIRONMENT_NAME},g" ./ingress.yaml.tmpl)
- echo "${INGRESS_MANIFEST}" | kubectl apply --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}" --filename -
switch-to-https:
......@@ -197,6 +196,6 @@ switch-to-https:
tags:
- docker
script:
- INGRESS_MANIFEST=$(sed -e "s,{{static-ip-name}},${STATIC_IP},g" -e "s,{{allowHttpFlag}},false,g" -e "s,{{portNumber}},443,g" ./k8s-manifests/ingress.yaml.tmpl)
- INGRESS_MANIFEST=$(sed -e "s,{{static-ip-name}},${STATIC_IP},g" -e "s,{{allowHttpFlag}},false,g" -e "s,{{portNumber}},443,g" -e "s,{{suffix}},${ENVIRONMENT_NAME},g" ./k8s-manifests/ingress.yaml.tmpl)
- echo "${INGRESS_MANIFEST}" | kubectl apply --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}" --filename -
when: manual
{
"version": "2.0.1"
}
......@@ -3,4 +3,4 @@ kind: ConfigMap
metadata:
name: todo-app-config
data:
MONGODB_URL: mongodb://mongodb-service:27017/todo-app
MONGODB_URL: mongodb://mongodb-service:27017/todo-app # the "mongodb-service" is defined in the app's infrastructure repository (https://gitlab.bht-berlin.de/s28840/ss22-devops-project)
# Used to establish a connection to the GitLab Container Registry so an image can be pulled from there.
apiVersion: v1
kind: Secret
metadata:
......
......@@ -4,9 +4,9 @@ metadata:
name: todo-app-ingress
annotations:
kubernetes.io/ingress.class: "gce" # Google's external load-balancer
kubernetes.io/ingress.allow-http: "{{allowHttpFlag}}" # disabling HTTP
kubernetes.io/ingress.allow-http: "{{allowHttpFlag}}" # disabling HTTP, "true" by default, set to "false" from a manually triggered job
kubernetes.io/ingress.global-static-ip-name: {{static-ip-name}}
networking.gke.io/managed-certificates: todoapp-managed-cert-{{suffix}} # defined in the infrastructure repository
networking.gke.io/managed-certificates: todoapp-managed-cert-{{suffix}} # defined in the infrastructure repository (https://gitlab.bht-berlin.de/s28840/ss22-devops-project)
spec:
defaultBackend:
service:
......
......@@ -4,4 +4,4 @@ metadata:
name: todo-app-secrets
type: Opaque
data:
JWT_SECRET: {{jwtSecret}}
JWT_SECRET: {{jwtSecret}} # set from the pipeline in .gitlab-ci.yml
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment