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

Merge branch 'just-a-test' into 'staging'

pipeline multiple updates

See merge request !2
parents d229b591 dc594d04
No related branches found
No related tags found
21 merge requests!72Production update,!70Production update,!67Workflow updates,!66Css test change,!64Pipeline fix,!62Main update,!60Getting staging's latest state,!58Updating Main,!56Main updates,!52Staging->Main,!50Production updates,!47Deployment on main,!45Deployment from main,!41updated logic of the test-job,!39updated logic of the test-job,!37Updating main to reflect staging,!34updated logic of the test-job,!31updated logic of the test-job,!29updated logic of the test-job,!13updated logic of the test-job,!2pipeline multiple updates
Pipeline #19102 failed
workflow: workflow:
rules: rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: always
- if: >- - if: >-
$CI_PIPELINE_SOURCE == "push" $CI_COMMIT_BRANCH == "staging" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
&& ($CI_COMMIT_BRANCH == "staging" || $CI_COMMIT_BRANCH == "master")
when: always when: always
- when: never - when: never
variables: variables:
DOCKER_VERSION: '20.10.12' DOCKER_VERSION: '20.10.17'
K8S_NAMESPACE: 'devops-s22-deployable' K8S_VERSION: '1.24'
GOOGLE_CLOUD_SDK_IMAGE_VERSION: '400.0.0'
K8S_NAMESPACE: 'todoapp-devops'
CONTAINER_TAG: '${CI_REGISTRY_IMAGE}:${CI_PIPELINE_IID}-${CI_COMMIT_SHORT_SHA}' CONTAINER_TAG: '${CI_REGISTRY_IMAGE}:${CI_PIPELINE_IID}-${CI_COMMIT_SHORT_SHA}'
stages: stages:
- test - test
- build - build
- release
- deploy - deploy
job_test-image: .gke-initialization:
before_script:
- 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
test-image:
stage: test stage: test
tags: tags:
- docker-priviliged - docker-priviliged
image: docker:$DOCKER_VERSION image: docker:${DOCKER_VERSION}
services: services:
- name: docker:$DOCKER_VERSION-dind - name: docker:${DOCKER_VERSION}-dind
script: script:
- docker build - docker build
--tag "${CONTAINER_TAG}-test" --tag "${CONTAINER_TAG}-test"
--target=test --target=test
"./" "./"
after_script: after_script:
- docker image rm --force "${CI_REGISTRY_IMAGE}:${CI_PIPELINE_IID}-${CI_COMMIT_SHORT_SHA}" - docker image rm --force "${CONTAINER_TAG}-test"
job_build-image: build-image:
stage: build stage: build
needs: needs:
- 'job_test-image' - 'test-image'
rules:
- if: $CI_COMMIT_BRANCH != "staging" && $CI_COMMIT_BRANCH != "master"
when: 'never'
tags: tags:
- docker-priviliged - docker-priviliged
image: docker:$DOCKER_VERSION image: docker:${DOCKER_VERSION}
services: services:
- name: docker:$DOCKER_VERSION-dind - name: docker:${DOCKER_VERSION}-dind
before_script:
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
script: script:
- SERVER_PUBLIC_URL="" - docker image build
- DB_HOST=""
- docker build
--tag "${CONTAINER_TAG}" --tag "${CONTAINER_TAG}"
--build-arg JWT_SECRET=${JWT_SECRET} "./app"
--build-arg SERVER_PUBLIC_URL=${SERVER_PUBLIC_URL} # - docker image build
--build-arg DB_HOST=${DB_HOST} # --tag "${CONTAINER_TAG}-google-sdk"
"./" # "./gcloud-image"
- docker push "${CONTAINER_TAG}"
# - docker push "${CONTAINER_TAG}-google-sdk"
after_script:
- docker image rm --force "${CONTAINER_TAG}"
# - docker image rm --force "${CONTAINER_TAG}-google-sdk"
create-release_image:
stage: release
rules:
- if: $CI_COMMIT_REF_NAME =~ /main/
when: 'always'
tags:
- docker-privileged
image: docker:${DOCKER_VERSION}
services:
- name: docker:${DOCKER_VERSION}-dind
before_script:
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY} - docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
- docker push "${CI_REGISTRY_IMAGE}:${CI_PIPELINE_IID}-${CI_COMMIT_SHORT_SHA}" - docker pull "${CONTAINER_TAG}"
script:
- VERSION=$(cat ./app/client/package.json | docker run --interactive stedolan/jq --raw-output '.version')
- docker tag "${CONTAINER_TAG}" "${CI_REGISTRY_IMAGE}:${VERSION}"
- docker push "${CI_REGISTRY_IMAGE}:${VERSION}"
after_script: after_script:
- docker image rm --force "${CI_REGISTRY_IMAGE}:${CI_PIPELINE_IID}-${CI_COMMIT_SHORT_SHA}" - docker image rm --force
$(docker images --format '{{.Repository}}{{.Tag}}' | grep '${CI_REGISTRY_IMAGE}')
# create-release_tag:
# stage: release
# needs:
# - 'create-release_image'
# rules:
# - if: $CI_COMMIT_REF_NAME =~ /main/
# when: 'always'
# tags:
# - docker-privileged
# image: docker:${DOCKER_VERSION}-git
# services:
# - name: docker:${DOCKER_VERSION}-dind
# script:
# - VERSION=$(cat ./src/package.json | docker run --interactive stedolan/jq --raw-output '.version')
# - echo ${VERSION}
# #- git tag "v${VERSION}" && git push origin "v${VERSION}"
job_deploy-image: deploy-image:
extends: .gke-initialization
stage: deploy stage: deploy
needs: needs:
- 'job_build-image' - 'build-image'
rules: rules:
- if: $CI_COMMIT_REF_NAME =~ /staging/ - if: $CI_COMMIT_REF_NAME =~ /staging/
when: 'always' when: 'always'
variables: variables:
ENVIRONMENT_NAME: 'staging' ENVIRONMENT_NAME: 'staging'
- if: $CI_COMMIT_REF_NAME !~ /staging/ - if: $CI_COMMIT_REF_NAME !~ /main/
when: 'always' when: 'always'
variables: variables:
ENVIRONMENT_NAME: 'prod' ENVIRONMENT_NAME: 'production'
tags: tags:
- docker - docker
image: image: google/cloud-sdk:${GOOGLE_CLOUD_SDK_IMAGE_VERSION}
name: k8s-image
entrypoint: ['']
script: script:
# - IMAGE="${CI_REGISTRY_IMAGE}:${VERSION}" - VERSION="${CI_PIPELINE_IID}-${CI_COMMIT_SHORT_SHA}"
- kubectl apply - IMAGE="${CI_REGISTRY_IMAGE}:${VERSION}"
--kubeconfig ${SECRET_KUBECONFIG_PATH} - cd "app/k8s-manifests"
--namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}" - kubectl apply secrets.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
--kustomize - - kubectl apply gitlab-registry-credentials.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
- kubectl apply configmap.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
- kubectl apply deployment.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
- kubectl apply service.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
- kubectl apply ingress.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
...@@ -2,3 +2,5 @@ client/node_modules ...@@ -2,3 +2,5 @@ client/node_modules
server/node_modules server/node_modules
.dockerignore .dockerignore
Dockerfile Dockerfile
README.md
npm-debug.log
...@@ -6,7 +6,7 @@ ARG NODEJS_VERSION='16.17.0' ...@@ -6,7 +6,7 @@ ARG NODEJS_VERSION='16.17.0'
FROM node:$NODEJS_VERSION-alpine AS base FROM node:$NODEJS_VERSION-alpine AS base
ENV \ ENV \
PORT=3002 \ PORT=3000 \
# For local dev - mongodb://host.docker.internal:27017/todo-app # For local dev - mongodb://host.docker.internal:27017/todo-app
MONGODB_URL=<should-be-dynamically-set> \ MONGODB_URL=<should-be-dynamically-set> \
JWT_SECRET=<should-be-dynamically-set> JWT_SECRET=<should-be-dynamically-set>
......
Todo-App Todo-App
======== ========
d
This application represents the *deployable workload* for the This application represents the *deployable workload* for the
[lecture assignment](https://github.com/lucendio/lecture-devops-material/blob/master/assignments/exercise.md). [lecture assignment](https://github.com/lucendio/lecture-devops-material/blob/master/assignments/exercise.md).
......
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
PORT: 3000
# MONGODB_URL: mongo-service.namespace (from infra repo. Does this work? Or do I have to dynamically set it?)
MONGODB_URL: mongodb://<mongo-service>:27017/todo-app
apiVersion: v1
kind: ConfigMap
metadata:
name: todo-app-config
data:
PORT: 3000
# MONGODB_URL: mongodb://<mongo-service>:27017/todo-app
# mongodb-service.<namespace>?
MONGODB_URL: mongodb-service
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: app-deployment name: todo-app-deployment
labels: labels:
app: todo-app app: todo-app
spec: spec:
...@@ -24,8 +24,9 @@ spec: ...@@ -24,8 +24,9 @@ spec:
ports: ports:
- containerPort: 3000 - containerPort: 3000
# imagePullPolicy: IfNotPresent # imagePullPolicy: IfNotPresent
# env for mongodb username and pass?
envFrom: envFrom:
- configMapRef: - configMapRef:
name: app-config name: todo-app-config
- secretRef: - secretRef:
name: app-secrets name: todo-app-secrets
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: todo-app-ingress
annotations:
kubernetes.io/ingress.class: "gce" # an external load-balancer
kubernetes.io/ingress.allow-http: "false" # disabling HTTP
kubernetes.io/ingress.global-static-ip-name: todoapp-ip # staging-todoapp-ip for staging
networking.gke.io/managed-certificates: todoapp-managed-cert # defined in the infrastructure repository
spec:
# rules:
# - http:
# paths:
# - path: /*
# pathType: ImplementationSpecific
# backend:
# serviceName: todo-app-service
# servicePort: 80
defaultBackend:
service:
name: todo-app-service
port:
number: 8080
apiVersion: v1 apiVersion: v1
kind: Secret kind: Secret
metadata: metadata:
name: app-secrets name: todo-app-secrets
type: Opaque type: Opaque
data: data:
JWT_SECRET: <jwt-secret in base64> JWT_SECRET: <jwt-secret in base64>
...@@ -2,12 +2,16 @@ apiVersion: v1 ...@@ -2,12 +2,16 @@ apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: todo-app-service name: todo-app-service
annotations:
cloud.google.com/app-protocols: '{"https-port":"HTTPS","http-port":"HTTP"}'
spec: spec:
type: NodePort
selector: selector:
app: todo-app app: todo-app
ports: ports:
- port: 8080 - name: https-port
port: 443
targetPort: 3000
- name: http-port
port: 8080
targetPort: 3000 targetPort: 3000
# port for external IP address (that you need to put in your browser)
# nodePort: 30000
# type: LoadBalancer
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