Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Em fix interactive book #40

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ RUN npm ci --only=production
COPY . .
RUN npm run copy-h5p-standalone
EXPOSE 80
CMD [ "npm", "start" ]
CMD [ "npm", "start" ]
97 changes: 97 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
void setBuildStatus(String message, String state, String repo ) {
step([
$class: "GitHubCommitStatusSetter",
reposSource: [$class: "ManuallyEnteredRepositorySource", url: "https://github.com/$repo"],
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "ci/jenkins/build-status"],
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ]
]);
}

pipeline {

parameters {
gitParameter(name: "BRANCH_NAME", type: "PT_BRANCH", defaultValue: "master", branchFilter: "origin/(master|staging)")
booleanParam(name: 'DEPLOY', defaultValue: false, description: "Deploy To Kubernetes")
}

agent {
kubernetes {
inheritFrom 'jenkins-agent'
yamlFile 'KubernetesPod.yaml'
}
}

environment {
IMAGE_NAME = "scorm-h5p-wrapper"
REPO_NAME = "fioru-software/$IMAGE_NAME"
GITHUB_API_URL = "https://api.github.com/repos/$REPO_NAME"
GITHUB_TOKEN = credentials('jenkins-github-personal-access-token')
COMMIT_SHA = sh(script: "git log -1 --format=%H", returnStdout:true).trim()
GCLOUD_KEYFILE = credentials('jenkins-gcloud-keyfile');
}

stages {

stage('Build') {

when {
beforeAgent true;
allOf {
expression {return params.DEPLOY}
anyOf {
branch 'master';
}
}
}
steps {
container('cloud-sdk') {
script {
sh 'gcloud auth activate-service-account [email protected] --key-file=${GCLOUD_KEYFILE}'
env.GCLOUD_TOKEN = sh(script: "gcloud auth print-access-token", returnStdout: true).trim()
}
}
container('docker') {
script {
sh 'docker login -u oauth2accesstoken -p $GCLOUD_TOKEN https://eu.gcr.io'
sh 'docker build --tag ${IMAGE_NAME}:${COMMIT_SHA} .'
sh 'docker tag ${IMAGE_NAME}:${COMMIT_SHA} eu.gcr.io/veri-cluster/${IMAGE_NAME}:${COMMIT_SHA}'
sh 'docker tag ${IMAGE_NAME}:${COMMIT_SHA} eu.gcr.io/veri-cluster/${IMAGE_NAME}:latest'
sh 'docker push eu.gcr.io/veri-cluster/${IMAGE_NAME}:${COMMIT_SHA}'
sh 'docker push eu.gcr.io/veri-cluster/${IMAGE_NAME}:latest'
}
}
}
}

stage ('Deploy') {
when {
beforeAgent true;
allOf {
expression {return params.DEPLOY}
anyOf {
branch 'master';
}
}
}
steps {
container('cloud-sdk') {
script {
sh "kubectl --token=$GCLOUD_TOKEN apply -k deployment/k8s/overlays/staging"
sh "kubectl --token=$GCLOUD_TOKEN rollout restart deployment ${IMAGE_NAME}"
sh "kubectl --token=$GCLOUD_TOKEN rollout status deployment ${IMAGE_NAME}"
}
}
}
}

}
post {
success {
setBuildStatus("Success", "SUCCESS", REPO_NAME)
}
failure {
setBuildStatus("Failure", "FAILURE", REPO_NAME)
}
}
}
34 changes: 34 additions & 0 deletions KubernetesPod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: v1
kind: Pod
metadata:
labels:
component: ci
spec:
# Use service account that can deploy to all namespaces
containers:
- name: cloud-sdk
image: gcr.io/google.com/cloudsdktool/cloud-sdk
imagePullPolicy: Always
env:
- name: CLOUDSDK_CONTAINER_CLUSTER
value: belgium-01
- name: CLOUDSDK_COMPUTE_ZONE
value: europe-west1-d
command:
- sleep
args:
- infinity
- name: docker
image: docker:20.10.12-alpine3.15
imagePullPolicy: IfNotPresent
command:
- sleep
args:
- infinity
volumeMounts:
- name: docker
mountPath: /var/run/docker.sock # We use the k8s host docker engine
volumes:
- name: docker
hostPath:
path: /var/run/docker.sock
69 changes: 69 additions & 0 deletions deployment/k8s/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: scorm-h5p-wrapper
labels:
app: scorm-h5p-wrapper
spec:
replicas: 1
revisionHistoryLimit: 3
strategy:
type: Recreate
selector:
matchLabels:
app: scorm-h5p-wrapper
template:
metadata:
labels:
app: scorm-h5p-wrapper
spec:
securityContext:
fsGroup: 1000
#runAsGroup: 33
#fsGroupChangePolicy: "OnRootMismatch"
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: cloud.google.com/gke-preemptible
operator: DoesNotExist
- key: cloud.google.com/gke-nodepool
operator: In
values:
- spot-pool
containers:
- name: scorm-h5p-wrapper
image: eu.gcr.io/veri-cluster/scorm-h5p-wrapper
imagePullPolicy: Always
securityContext:
allowPrivilegeEscalation: false
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /
port: 80
periodSeconds: 60
timeoutSeconds: 30
livenessProbe:
httpGet:
path: /
port: 80
periodSeconds: 60
timeoutSeconds: 30
startupProbe:
initialDelaySeconds: 60
httpGet:
path: /
port: 80
periodSeconds: 60
timeoutSeconds: 30
resources:
limits:
cpu: 500m
memory: 512M
requests:
cpu: 250m
memory: 256M

28 changes: 28 additions & 0 deletions deployment/k8s/base/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: scorm-h5p-wrapper-ingress
annotations:
nginx.ingress.kubernetes.io/auth-url: https://basic-auth.veri.ie/
nginx.ingress.kubernetes.io/proxy-body-size: "20m"
nginx.ingress.kubernetes.io/client-max-body-size: "20m"
nginx.ingress.kubernetes.io/proxy-buffer-size: "16k"
nginx.ingress.kubernetes.io/proxy-connect-timeout: "60"
nginx.ingress.kubernetes.io/proxy-read-timeout: "60"
nginx.ingress.kubernetes.io/proxy-send-timeout: "60"
spec:
ingressClassName: nginx
rules:
- host: scorm-h5p-wrapper.veri.ie
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: scorm-h5p-wrapper-service
port:
number: 8080
tls:
- hosts:
- scorm-h5p-wrapper.veri.ie
21 changes: 21 additions & 0 deletions deployment/k8s/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ingress.yaml
- deployment.yaml
- service.yaml














15 changes: 15 additions & 0 deletions deployment/k8s/base/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: v1
kind: Service
metadata:
name: scorm-h5p-wrapper-service
labels:
app: scorm-h5p-wrapper-service
spec:
selector:
app: scorm-h5p-wrapper
ports:
- name: http
protocol: TCP
port: 8080
targetPort: 80
8 changes: 8 additions & 0 deletions deployment/k8s/overlays/staging/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namePrefix: staging-

generatorOptions:
disableNameSuffixHash: true

bases:
- ../../base

14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3.7"

services:

node:
build:
context: .
environment:
- PORT=80
volumes:
- ./static:/usr/src/app/static
ports:
- "8080:80"

Loading