Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop' into feature/SC-3505/add-attachment-service
Browse files Browse the repository at this point in the history
  • Loading branch information
CeEv authored Mar 16, 2020
2 parents 60d1b8c + b38e925 commit 78d7467
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 57 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_style = space
indent_size = 2
6 changes: 5 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
config/secrets.json filter=git-crypt diff=git-crypt
backup/setup/*.secrets.json filter=git-crypt diff=git-crypt
backup/setup/*.secrets.json filter=git-crypt diff=git-crypt

# Fix end-of-lines in Git versions older than 2.10
# https://github.com/git/git/blob/master/Documentation/RelNotes/2.10.0.txt#L248
* text=auto eol=lf
38 changes: 31 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,44 @@ node_js:
- '10.16'
branches:
only:
- development
- develop
- master
- /^greenkeeper/.*$/
- /^(?i:release|hotfix).*$/
services:
- mongodb
- redis-server

stages:
- test
- name: build
if: type = push && (branch = master || branch = develop || branch ~= /^(?i:release|hotfix).*$/)
- name: deploy
if: type = push && (branch = master || branch = develop || branch ~= /^(?i:release|hotfix).*$/)

env:
- REDIS_URI=redis://localhost:6379
global:
- TZ=Europe/Berlin
- GIT_SHA=$( git rev-parse HEAD )
- DOCKERTAG="$( echo $TRAVIS_BRANCH | tr -s '[:punct:]' '-' | tr -s '[:upper:]' '[:lower:]' )_v$( jq -r '.version' package.json )_$TRAVIS_COMMIT"

jobs:
include:
- stage: test
name: test:mocha
script: npm run test
cache: npm
services:
- mongodb
- redis-server
env:
- REDIS_URI=redis://localhost:6379

# Build Docker Images
- stage: build
name: build
language: generic
script: bash ./deploy/build.sh

# Deploy
- stage: deploy
name: deploy
language: generic
script: bash ./deploy/deploy.sh

cache: npm
35 changes: 18 additions & 17 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"host": "localhost",
"port": 4001,
"protocol": "http",
"mongodb": "mongodb://localhost:27017/schulcloud-editor",
"routes": {
"server": {
"baseURL": "http://localhost:3030",
"coursePermissionsUri": "/courses/:courseId/userPermissions",
"meUri": "/me",
"courseMembersUri": "/courses/:courseId/members"
},
"timeout": "30000"
},
"testsecret": "secret",
"redis": "REDIS_URI"
}
{
"host": "localhost",
"port": 4001,
"protocol": "http",
"mongodb": "mongodb://localhost:27017/schulcloud-editor",
"routes": {
"server": {
"baseURL": "http://localhost:3030",
"coursePermissionsUri": "/courses/:courseId/userPermissions",
"meUri": "/me",
"courseMembersUri": "/courses/:courseId/members"
},
"timeout": "30000"
},
"testsecret": "secret",
"redis": "REDIS_URI",
"redis_key": "REDIS_KEY"
}
26 changes: 13 additions & 13 deletions config/production.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"host": "localhost",
"port": "PORT",
"protocol": "http",
"mongodb": "MONGO_URI",
"routes": {
"server": {
"baseURL": "SERVER_API_URL"
},
"timeout": "TIMEOUT"
},
"testsecret": "TESTSECRET"
}
{
"host": "localhost",
"port": "PORT",
"protocol": "http",
"mongodb": "MONGO_URI",
"routes": {
"server": {
"baseURL": "SERVER_API_URL"
},
"timeout": "TIMEOUT"
},
"testsecret": "TESTSECRET"
}
10 changes: 10 additions & 0 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:lts as builder
RUN mkdir /app && chown -R node:node /app
WORKDIR '/app'
COPY ./package.json ./
COPY ./package-lock.json ./
USER node
RUN npm ci --only=production
COPY --chown=node:node . /app/
EXPOSE 4001
CMD npm run start
52 changes: 52 additions & 0 deletions deploy/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#! /bin/bash

# ----------------
# DECLERATIONS
# ----------------

set -e # fail with exit 1 on any error

echo "DOCKERTAG" $DOCKERTAG
echo "GITSHA" $GIT_SHA

# ----------------
# SCRIPTS
# ----------------

dockerPush(){
# $1: Project Name
# $2: docker tag to use

# Log in to the docker CLI
echo "$MY_DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin

# Push Image
docker push schulcloud/schulcloud-$1:$2
}

# BUILD SCRIPTS

buildeditor(){
docker build \
-t schulcloud/schulcloud-editor:$DOCKERTAG \
-t schulcloud/schulcloud-editor:$GIT_SHA \
-f Dockerfile \
../

dockerPush "editor" $DOCKERTAG
dockerPush "editor" $GIT_SHA
}

# ----------------
# MAIN SCRIPT
# ----------------
cd deploy

source ./buildAndDeployFilter.sh
buildAndDeployFilter

bash ./decryptSecrets.sh

buildeditor

exit 0
15 changes: 15 additions & 0 deletions deploy/buildAndDeployFilter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /bin/bash

buildAndDeployFilter () {
if [ "$TRAVIS_PULL_REQUEST" != "false" ]
then
echo "Pull Requests are not build/deployed. (Pull #$TRAVIS_PULL_REQUEST)"
exit 0
fi

if ! [[ $TRAVIS_BRANCH = master || $TRAVIS_BRANCH = develop || $TRAVIS_BRANCH = release* || $TRAVIS_BRANCH = hotfix* ]]
then
echo "Branch $TRAVIS_BRANCH is not supposed to be build/deployed.".
exit 0
fi
}
4 changes: 4 additions & 0 deletions deploy/decryptSecrets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
echo "decrypt secrets"

openssl aes-256-cbc -K $encrypted_dd6f15d73ffd_key -iv $encrypted_dd6f15d73ffd_iv -in travis_rsa.enc -out travis_rsa -d
chmod 600 travis_rsa
77 changes: 77 additions & 0 deletions deploy/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#! /bin/bash

# ----------------
# DECLERATIONS
# ----------------

set -e # fail with exit 1 on any error

# ----------------
# SCRIPTS
# ----------------

inform_live() {
# $1: Project Name (client, storybook, vuepress)
if [[ "$TRAVIS_EVENT_TYPE" != "cron" ]]
then
curl -X POST -H 'Content-Type: application/json' --data '{"text":":rocket: Die Produktivsysteme können aktualisiert werden: Schul-Cloud editor! Dockertag: '$DOCKERTAG'"}' $WEBHOOK_URL_CHAT
fi
}

inform_staging() {
if [[ "$TRAVIS_EVENT_TYPE" != "cron" ]]
then
curl -X POST -H 'Content-Type: application/json' --data '{"text":":boom: Das Staging-System wurde aktualisiert: Schul-Cloud editor! (Dockertag: '$DOCKERTAG')"}' $WEBHOOK_URL_CHAT
fi
}

deploy(){
SYSTEM=$1 # [staging, test, demo]

DOCKER_IMAGE=$2 # (editor), autoprefixed with "schulcloud-"
DOCKER_TAG=$3 # version/tag of the image to use. Usually the branch name or a GIT_SHA
DOCKER_SERVICE_NAME=$4 # docker service name on server

echo "deploy " $DOCKER_IMAGE ":" $DOCKER_TAG " to " $SYSTEM " as " $DOCKER_SERVICE_NAME

# deploy new dockerfile
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i travis_rsa linux@$SYSTEM.schul-cloud.org /usr/bin/docker service update --force --image schulcloud/schulcloud-$DOCKER_IMAGE:$DOCKER_TAG $DOCKER_SERVICE_NAME
}

# ----------------
# MAIN SCRIPT
# ----------------
cd deploy

source ./buildAndDeployFilter.sh
buildAndDeployFilter

bash ./decryptSecrets.sh

echo "DOCKERTAG" $DOCKERTAG

if [ -z "$DOCKERTAG" ];
then
echo "DOCKERTAG env is missing. Abort deployment."
exit 1;
fi


case "$TRAVIS_BRANCH" in

master)
inform_live
;;

develop)
echo "develop"
# deploy $SYSTEM $DOCKERFILE $DOCKERTAG $DOCKER_SERVICENAME $COMPOSE_DUMMY $COMPOSE_FILE $COMPOSE_SERVICENAME
deploy "test" "editor" $DOCKERTAG "test-schul-cloud_editor"
;;
release* | hotfix*)
echo "release/hotfix"
deploy "staging" "editor" $DOCKERTAG "staging_editor"
;;
esac

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

# example compose file

services:
editor-mongodb:
image: mongo:4.2
deploy:
replicas: 1
restart_policy:
condition: always
ports:
- 27017:27017
volumes:
- data-editor-mongodb:/data/db
restart: unless-stopped

redis:
image: redis:5.0.3

schulcloud-editor:
build:
context: ../
dockerfile: deploy/Dockerfile
environment:
- NODE_ENV=production
- MONGO_URI=mongodb://editor-mongodb:27017/schulcloud-editor
- PORT=4101
- SERVER_API_URL=http://server:3030
- TIMEOUT=30000
- REDIS_URI=redis://redis:6379
- REDIS_KEY=schulcloud-editor-sync
ports:
- 4101:4101
depends_on:
- editor-mongodb
- redis
restart: unless-stopped

volumes:
data-editor-mongodb:
Binary file added deploy/travis_rsa.enc
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"url": "git+https://github.com/schul-cloud/schulcloud-editor.git"
},
"keywords": [
"fathers"
"feathers"
],
"author": "",
"license": "GPL",
Expand Down
16 changes: 0 additions & 16 deletions src/database/redis.js

This file was deleted.

1 change: 1 addition & 0 deletions src/middleware/feathersSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ const sync = require('feathers-sync');
module.exports = (app) => {
app.configure(sync({
uri: app.get('redis'),
key: app.get('redis_key'),
}));
};
8 changes: 6 additions & 2 deletions src/middleware/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
const { systemInfo } = require('../logger');
const { systemInfo, logger } = require('../logger');
const addLoggerToApp = require('./addLoggerToApp');
const requestLogs = require('./requestLogs');
const ping = require('./ping');
Expand Down Expand Up @@ -31,8 +31,12 @@ module.exports = function setup(app) {
}
exec(aggregateAppVars, 'aggregateAppVars: Add aggregate app vars and display it.'); // TODO: no middleware
exec(socket, 'socket: Add socket connections');
if (app.get('redis') && app.get('redis') !== 'REDIS_URI') {
const redisUriDefined = app.get('redis') && app.get('redis') !== 'REDIS_URI';
const redisKeyDefined = app.get('redis_key') && app.get('redis_key') !== 'REDIS_KEY';
if (redisUriDefined && redisKeyDefined) {
exec(feathersSync, 'feathers-sync: Add feathers-sync');
} else {
logger.warning(`REDIS_URI (${app.get('redis')}) or REDIS_KEY (${app.get('redis_key')}) env is not defined`);
}
if (app.get('NODE_ENV') !== 'test') {
exec(sentry, 'sentry: Add sentry for logging errors.');
Expand Down

0 comments on commit 78d7467

Please sign in to comment.