Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
Merge to master for deployment (#189)
Browse files Browse the repository at this point in the history
Infrastructure rollout
  • Loading branch information
JohannesGuenther authored Apr 11, 2020
1 parent 62e3b7d commit 34a8945
Show file tree
Hide file tree
Showing 280 changed files with 11,167 additions and 4,655 deletions.
2 changes: 0 additions & 2 deletions .dockerignore

This file was deleted.

6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# These are explicitly windows files and should use crlf
*.bat text eol=crlf

12 changes: 4 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ on:
- master
- dev
pull_request:
branches: [ master ]
branches:
- master
- dev

# Environment variables available to all jobs and steps in this workflow
env:
Expand All @@ -25,10 +27,4 @@ jobs:

# Configure docker to use the gcloud command-line tool as a credential helper
- run: |
(cd server && gradle clean test)
(cd client && gradle build)
# Build the Docker image
- name: Build
run: |
docker-compose build
gradle build lint test
85 changes: 0 additions & 85 deletions .github/workflows/deploy-staging.yml

This file was deleted.

76 changes: 42 additions & 34 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: Production
name: Deploy

on:
release:
types: [published]
push:
branches:
- dev
- jib-integration

# Environment variables available to all jobs and steps in this workflow
env:
Expand All @@ -11,13 +15,9 @@ env:
CLOUD_SQL_SERVICE_ACCOUNT: ${{ secrets.CLOUD_SQL_SERVICE_ACCOUNT }}
CLOUD_STORE_SERVICE_ACCOUNT: ${{ secrets.CLOUD_STORE_SERVICE_ACCOUNT }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
SENTRY_BACKEND_DSN: ${{ secrets.SENTRY_BACKEND_DSN }}
SENTRY_FRONTEND_DSN: ${{ secrets.SENTRY_FRONTEND_DSN }}
GITHUB_SHA: ${{ github.sha }}
GKE_ZONE: europe-west3-b
GKE_CLUSTER: cluster-1
CLIENT_IMAGE: imis-client
SERVER_IMAGE: imis-server
REGISTRY_HOSTNAME: eu.gcr.io

jobs:
Expand All @@ -29,39 +29,45 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v1
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
# Setup gcloud CLI
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '270.0.0'
service_account_email: ${{ secrets.GKE_EMAIL }}
service_account_key: ${{ secrets.GKE_KEY }}
project_id: ${{ secrets.GKE_PROJECT_ID }}
- uses: actions/[email protected]
with:
java-version: 1.11

# Configure docker to use the gcloud command-line tool as a credential helper
- run: |
# Set up docker to authenticate
# via gcloud command-line tool.
gcloud auth configure-docker
# Build the Docker image
- name: Build client
run: |
(cd client && docker build -f Dockerfile.prod -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT_ID"/"$CLIENT_IMAGE":"$GITHUB_SHA" \
--build-arg SENTRY_FRONTEND_DSN="${SENTRY_FRONTEND_DSN}" \
--build-arg DEPLOY_ENV=production \
--build-arg GITHUB_SHA="${GITHUB_SHA}" \
--build-arg GITHUB_REF="${GITHUB_REF}" .)
- name: Build server
run: |
docker build -f Dockerfile.prod -t "$REGISTRY_HOSTNAME"/"$GKE_PROJECT_ID"/"$SERVER_IMAGE":"$GITHUB_SHA" \
--build-arg GITHUB_SHA="${GITHUB_SHA}" \
--build-arg GITHUB_REF="${GITHUB_REF}" .
# Push the Docker image to Google Container Registry
- name: Publish
run: |
docker push "$REGISTRY_HOSTNAME/$GKE_PROJECT_ID/$CLIENT_IMAGE:$GITHUB_SHA"
docker push "$REGISTRY_HOSTNAME/$GKE_PROJECT_ID/$SERVER_IMAGE:$GITHUB_SHA"
# Build and push image to Google Container Registry
- name: Build
run: |-
gradle jib --image "$REGISTRY_HOSTNAME/$GKE_PROJECT_ID/imis:$GITHUB_SHA"
# Deploy the Docker image to the GKE cluster
- name: Prepare Helm
Expand All @@ -74,12 +80,14 @@ jobs:
gcloud container clusters get-credentials "$GKE_CLUSTER" --zone "$GKE_ZONE" --project "$GKE_PROJECT_ID"
echo -n "${CLOUD_SQL_SERVICE_ACCOUNT}" > chart/cloudsql.base64.json
echo -n "${CLOUD_STORE_SERVICE_ACCOUNT}" > chart/cloudstore.base64.json
helm repo add stable https://kubernetes-charts.storage.googleapis.com
helm dependency build chart
helm upgrade --install imis chart \
--set gitSha=${GITHUB_SHA} --set "secrets.postgres=$(echo -n ${POSTGRES_PASSWORD} | base64)" \
--set "secrets.sentry.backend=${SENTRY_BACKEND_DSN}" \
--set "secrets.sentry.frontend=${SENTRY_FRONTEND_DSN}"
kubectl rollout status deployment/imis-client
kubectl rollout status deployment/imis-server
kubectl get services -o wide
helm repo add stable "https://kubernetes-charts.storage.googleapis.com"
helm upgrade --install traefik stable/traefik -f chart/traefik.values.yaml
if [[ "$GITHUB_REF" == "refs/heads/master" ]]; then
helm upgrade --install imis-production chart \
--set gitSha=${GITHUB_SHA} --set "secrets.postgres=$(echo -n ${POSTGRES_PASSWORD} | base64)"
kubectl rollout status deployment/imis-production
else
helm upgrade --install imis-staging chart -f chart/values.staging.yml \
--set gitSha=${GITHUB_SHA} --set "secrets.postgres=$(echo -n ${POSTGRES_PASSWORD} | base64)"
kubectl rollout status deployment/imis-staging
fi
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# CMake
cmake-build-*/

# TODO
#client/src/store/SwaggerApi.ts

# File-based project format
*.iws

Expand Down Expand Up @@ -40,15 +43,32 @@ fabric.properties

# Package Files #
*.jar
!gradle/wrapper/gradle-wrapper.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# local env files
.env.local
.env.*.local

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/.project
server/build
server/.classpath

### Node
node_modules
client/dist
# we use client/yarn.lock instead!
client/package-lock.json

# Log files
client/npm-debug.log*
client/yarn-debug.log*
client/yarn-error.log*
/build/
5 changes: 0 additions & 5 deletions Dockerfile

This file was deleted.

9 changes: 0 additions & 9 deletions Dockerfile.prod

This file was deleted.

59 changes: 45 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Development happens in `dev` using feature branches and PR. `dev` branch is depl
- Backend: Spring Boot
- Frontend: Vue.js
- Persistence: PostgreSQL
- Deployment: GKE
- Deployment: Google Kubernetes Engine (GKE)

## Benötigte Tools
1. Docker
Expand All @@ -36,34 +36,65 @@ Development happens in `dev` using feature branches and PR. `dev` branch is depl
- Home: https://docs.docker.com/toolbox/toolbox_install_windows/
2. JDK 11 (Java)
- https://adoptopenjdk.net/
3. NPM/YARN
3. YARN
- https://classic.yarnpkg.com/en/docs/install#mac-stable

## How to run this server?
Install Docker and run: `docker-compose up`

## Quickstart for frontend development
```docker-compose up -d postgres server```
## Quickstart for server development
```docker-compose up -d postgres client```

## Local development setup

### Run full application
Run application (including frontend)
```./gradlew bootRun```
### Server
1. Shell öffnen
1. Make sure your $JAVA_PATH is set correctly
1. Start PostgreSQL in docker container (before starting application):
```docker-compose up -d ```
1. Download Gradle wrapper
1. Make sure your $JAVA_PATH is set correctly (java11)
#### Postgres
- Start PostgreSQL in docker container (before starting application):
```docker-compose up -d postgres```
- When you are not using docker you have to setup postgres manually and add a user as specified in `server/src/main/resources/application.yml`

#### Spring Boot Server
- Using Gradle
- Download Gradle wrapper
```gradle wrapper```
1. Build application
- Build application
```./gradlew clean build```
1. Test application
```./gradlew test```
1. Run application (including frontend)
- Test application
```./gradlew test lint```
- Run server application
```./gradlew bootRun```
1. Start local development server for vue.js development
- Start local development server for vue.js development
```./gradlew serve```
- Using Intellij:
- Import Project by opening the `build.gradle` file. Intellij resolves all dependencies and you can run the application by pressing the run button.

But you have to run Postgres in docker or install it and run it locally manually

### Frontend ([more](client/README.md))
- Start local development server for vue.js development
```./gradlew serve```
## Quickstart for Backendserver to enable Frontend Development
```docker-compose -f docker-compose.yml -f docker-compose.frontend_dev.yml up ```
- Alternatively you can also us `yarn serve` within the client folder, make sure you installed all dependencies using `yarn install`
- Update TypeScript API client for frontend using `generate:api-client`, make sure the server is running on `localhost:80`. Do not manually change the `SwaggerApi.ts` file.

## API communication

An API developed by the backend is served via swagger on the server: http://localhost/swagger-ui.html
If you have a new API that should be created add them into the api-frontend folder.
We are using the swagger docs to autogenerate the typescript api client.
```yarn generate:api-client```
Make sure the server is running locally, the command updates the ts api client

When you make changes to the backend, make sure to generate a new client.

## CI system
All commits to `dev`, `master`, `feature/*` and all PRs will be CI checked.

New commit to `dev` will result in new release to `staging.imis-prototyp.de`.

A new release to `imis-prototyp.de` is not triggerd by commit on `master` but by a new release tag.
Loading

0 comments on commit 34a8945

Please sign in to comment.