This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ added docker setup + prepared travis deploy
- Loading branch information
1 parent
087722f
commit 83e7c59
Showing
14 changed files
with
280 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#! /bin/bash | ||
|
||
# ---------------- | ||
# DECLERATIONS | ||
# ---------------- | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
version: \"3.7\" | ||
|
||
services: | ||
editor-mongodb: | ||
image: mongo:3.4 | ||
deploy: | ||
replicas: 1 | ||
restart_policy: | ||
condition: always | ||
ports: | ||
- 27017:27017 | ||
volumes: | ||
- data-editor-mongodb:/data/db | ||
restart: unless-stopped | ||
|
||
schulcloud-editor: | ||
image: schulcloud/schulcloud-editor:$DOCKERTAG | ||
deploy: | ||
replicas: 1 | ||
restart_policy: | ||
condition: any | ||
environment: | ||
- NODE_ENV=production | ||
- MONGO_URI=mongodb://editor-mongodb:27017/schulcloud-editor | ||
- PORT=5001 | ||
- SERVER_API_URL=http://server:3030 | ||
- TIMEOUT=30000 | ||
ports: | ||
- \"5001:5001\" | ||
depends_on: | ||
- editor-mongodb | ||
- server | ||
restart: unless-stopped | ||
|
||
volumes: | ||
data-editor-mongodb: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
echo "decrypt secrets" | ||
|
||
openssl aes-256-cbc -K $encrypted_b7461320c5f4_key -iv $encrypted_b7461320c5f4_iv -in travis_rsa.enc -out travis_rsa -d | ||
chmod 600 travis_rsa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#! /bin/bash | ||
|
||
# ---------------- | ||
# DECLERATIONS | ||
# ---------------- | ||
|
||
|
||
# ---------------- | ||
# 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 | ||
|
||
COMPOSE_SRC=$5 # name of the docker-compose file which should be used as. | ||
COMPOSE_TARGET=$6 # name as which the compose file should be pushed to the server (auto prefixed with "docker-compose-") | ||
STACK_NAME=$7 # swarm stack name | ||
|
||
echo "deploy " $DOCKER_IMAGE ":" $DOCKER_TAG " to " $SYSTEM " as " $DOCKER_SERVICE_NAME | ||
echo "COMPOSEFILE: " $COMPOSE_SRC " => " $COMPOSE_TARGET | ||
|
||
# generate new compose file | ||
eval "echo \"$( cat $COMPOSE_SRC )\"" > docker-compose-$COMPOSE_TARGET | ||
|
||
# deploy new compose file | ||
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i travis_rsa docker-compose-$COMPOSE_TARGET linux@$SYSTEM.schul-cloud.org:~ | ||
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i travis_rsa linux@$SYSTEM.schul-cloud.org /usr/bin/docker stack deploy -c /home/linux/docker-compose-$COMPOSE_TARGET $STACK_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" "compose-editor_default.dummy" "editor.yml" "test-schul-cloud" | ||
release* | hotfix*) | ||
echo "release/hotfix" | ||
deploy "staging" "editor" $DOCKERTAG "staging_editor" "compose-editor_default.dummy" "editor_default.yml" "staging" | ||
esac | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
version: "3.7" | ||
|
||
# example compose file | ||
|
||
services: | ||
editor-mongodb: | ||
image: mongo:3.4 | ||
deploy: | ||
replicas: 1 | ||
restart_policy: | ||
condition: always | ||
ports: | ||
- 27017:27017 | ||
volumes: | ||
- data-editor-mongodb:/data/db | ||
restart: unless-stopped | ||
|
||
schulcloud-editor: | ||
build: | ||
context: ../ | ||
dockerfile: deploy/Dockerfile | ||
environment: | ||
- NODE_ENV=production | ||
- MONGO_URI=mongodb://editor-mongodb:27017/schulcloud-editor | ||
- PORT=5001 | ||
- SERVER_API_URL=http://server:3030 | ||
- TIMEOUT=30000 | ||
- REDIS_URI="redis://redis:6379/schulcloud-editor" # ??? where is it used | ||
ports: | ||
- 5001:5001 | ||
depends_on: | ||
- editor-mongodb | ||
restart: unless-stopped | ||
|
||
volumes: | ||
data-editor-mongodb: |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.