Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • s28840/ss22-devops-project-app
1 result
Show changes
Commits on Source (11)
......@@ -15,7 +15,7 @@ variables:
CONTAINER_TAG: '${CI_REGISTRY_IMAGE}:${CI_PIPELINE_IID}-${CI_COMMIT_SHORT_SHA}'
stages:
# - test
- test
- build
- release
- deploy
......@@ -28,26 +28,34 @@ stages:
- gcloud config set compute/zone ${GCP_COMPUTE_REGION}
- gcloud container clusters get-credentials ${GCP_PROJECT_ID}-gke
# run-tests:
# stage: test
# tags:
# - docker-privileged
# image: docker:${DOCKER_VERSION}
# services:
# - name: docker:${DOCKER_VERSION}-dind
# alias: containerhost
# script:
# - docker run -p 27017:27017 -d --name mongo-container --rm mongo:${MONGO_VERSION}
# - docker build
# --tag "${CONTAINER_TAG}-test"
# --target=test
# --build-arg MONGODB_URL_TEST=mongodb://containerhost:27017/todo-app
# --build-arg JWT_SECRET_TEST=my-very-secret-jwt
# "./app"
# after_script:
# - docker stop mongo-container
# - docker images -a | grep "mongo" | awk '{print $3}' | xargs docker rmi --force
# - docker image rm --force "${CONTAINER_TAG}-test"
run-tests:
stage: test
tags:
- docker-privileged
image: docker:${DOCKER_VERSION}
services:
- name: docker:${DOCKER_VERSION}-dind
alias: localhost
script:
- docker run -p 27017:27017
--detach
--name mongo-container
--rm
--network=host
mongo:${MONGO_VERSION}
- docker build
--tag "${CONTAINER_TAG}-test"
--target=test
--network=host
--build-arg MONGODB_URL_TEST=mongodb://localhost:27017/todo-app
--build-arg JWT_SECRET_TEST=my-very-secret-jwt
--add-host=host.docker.internal:host-gateway
--file "./app/Dockerfile.test"
"./app"
after_script:
- docker stop mongo-container
- docker images -a | grep "mongo" | awk '{print $3}' | xargs docker rmi --force
- docker image rm --force "${CONTAINER_TAG}-test"
build-image:
stage: build
......@@ -120,10 +128,12 @@ deploy-image:
when: 'always'
variables:
ENVIRONMENT_NAME: 'staging'
STATIC_IP: 'staging-todoapp-ip'
- if: $CI_COMMIT_REF_NAME !~ /main/
when: 'always'
variables:
ENVIRONMENT_NAME: 'production'
STATIC_IP: 'todoapp-ip'
tags:
- docker
image: google/cloud-sdk:${GOOGLE_CLOUD_SDK_IMAGE_VERSION}
......@@ -137,7 +147,8 @@ deploy-image:
- 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}"
- kubectl apply -f ingress.yaml --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}"
- INGRESS_MANIFEST=$(sed -e "s,{{static-ip-name}},${STATIC_IP},g" ./ingress.yaml.tmpl)
- echo "${INGRESS_MANIFEST}" | kubectl apply --namespace "${ENVIRONMENT_NAME}-${K8S_NAMESPACE}" --filename -
......@@ -14,35 +14,6 @@ ENV \
MONGODB_URL=<dynamically-set-from-k8s> \
JWT_SECRET=<dynamically-set-from-k8s>
# ------------------------------------------------------------------
# # Test stage
# FROM base AS test
# # client tests
# WORKDIR /client
# COPY ./client .
# RUN npm ci --no-audit --no-fund
# RUN npm run test
# # server tests
# WORKDIR /server
# COPY ./server/src ./src/
# COPY ./server/package*.json ./
# RUN npm ci --no-audit --no-fund
# ARG MONGODB_URL_TEST
# ARG JWT_SECRET_TEST
# # MONGODB_URL and JWT_SECRET are available as env variables
# RUN MONGODB_URL=$MONGODB_URL_TEST JWT_SECRET=$JWT_SECRET_TEST npm run test
# ------------------------------------------------------------------
# Build stage
FROM base AS build
......
ARG NODEJS_VERSION='16.17.0'
# Test stage
FROM node:$NODEJS_VERSION-alpine
# client tests
WORKDIR /client
COPY ./client .
RUN npm ci --no-audit --no-fund
RUN npm run test
# server tests
WORKDIR /server
COPY ./server/src ./src/
COPY ./server/package*.json ./
RUN npm ci --no-audit --no-fund
ARG \
MONGODB_URL_TEST=mongodb://host.docker.internal:27017/todo-app \
JWT_SECRET_TEST=<my-very-secret-jwt>
# MONGODB_URL and JWT_SECRET are available as env variables
RUN MONGODB_URL=$MONGODB_URL_TEST JWT_SECRET=$JWT_SECRET_TEST npm run test
......@@ -4,4 +4,4 @@ metadata:
name: todo-app-config
data:
PORT: "3000"
MONGODB_URL: "mongodb-service"
MONGODB_URL: mongodb-service
......@@ -27,6 +27,6 @@ spec:
# env for mongodb username and pass?
envFrom:
- configMapRef:
name: todo-app-config
name: todo-app-config
- secretRef:
name: todo-app-secrets
name: todo-app-secrets
......@@ -5,7 +5,7 @@ metadata:
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
kubernetes.io/ingress.global-static-ip-name: {{static-ip-name}} # staging-todoapp-ip for staging
networking.gke.io/managed-certificates: todoapp-managed-cert # defined in the infrastructure repository
spec:
# rules:
......