Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Sep 16, 2023
2 parents d517d02 + 6d584c5 commit 5ebf043
Show file tree
Hide file tree
Showing 90 changed files with 1,074 additions and 812 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SENTRY_DSN=
SMTP_PASSWORD=
SMTP_URL=
SMTP_USERNAME=
SMTP_PORT=
SMTP_PORT=
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml → .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
name: CI
name: lint
on:
push:
branches: [ main ]
pull_request:

permissions:
contents: read

jobs:
ci:
lint:
name: lint
runs-on: ubuntu-latest
steps:
Expand All @@ -29,3 +27,7 @@ jobs:
version: v1.54
working-directory: client
args: --timeout=30m
- run: go install golang.org/x/tools/cmd/goimports@latest
- run: bash server/api/installBuf.bash
- name: pre-commit
uses: pre-commit/[email protected]
13 changes: 13 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@ on:
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache-dependency-path: |
server/go.sum
- name: run tests
run: go test -v ./...
working-directory: ./server
build:
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ __debug_bin
.env.local

apns_auth_key.p8

venv
39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
exclude: vscode/launch.json
- id: check-yaml
exclude: deployment/.*
- id: check-added-large-files
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.0
hooks:
- id: go-fmt
- id: go-imports
- repo: local
hooks:
- id: regen-protobuf
name: Regenerate protobuf files
files: server/api/
entry: bash server/api/generate.bash
language: system
pass_filenames: false
stages: [commit]
- id: go-mod-tidy-server
name: Check if go.mod and go.sum are up to date for server
files: server/
entry: sh -c "(cd server && go mod tidy)"
language: system
pass_filenames: false
stages: [commit]
- id: go-mod-tidy-client
name: Check if go.mod and go.sum are up to date for server
files: server/
entry: sh -c "(cd client && go mod tidy)"
language: system
pass_filenames: false
stages: [commit]
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
"program": "${workspaceFolder}/client/publicServer/client.go",
}
]
}
}
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,18 @@ Take a look at the [`lauch.json`](.vscode/launch.json) file for more details.


Please be respectful with its usage!

## pre-commit

To ensure that that common pitfalls which can be automated are not done, we recommend you to install `pre-commit`.
You can do so via

```bash
python -m venv venv
source venv/bin/activate
pip install pre-commit
pre-commit install
```

Certain `pre-commit` hooks will now be run on every commit where you change specific files.
If you want to run all files instead, run `pre-commit run -a`
2 changes: 1 addition & 1 deletion client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ standard system TLS CA's configured to securely connect via `api-grpc.tum.app` t
Alternatively you can also test the API using [grpcurl](https://github.com/fullstorydev/grpcurl) (also located in the `testLiveApi.sh`):
```
grpcurl -protoset <(buf build -o -) -H "x-device-id:grpc-tests" api-grpc.tum.app:443 api.Campus/GetNewsSources
```
```
3 changes: 2 additions & 1 deletion client/publicServer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package main
import (
"context"
"crypto/x509"
"time"

pb "github.com/TUM-Dev/Campus-Backend/server/api/tumdev"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/types/known/emptypb"
"time"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion client/testLiveApi.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

grpcurl -protoset <(buf build -o -) -plaintext -H "x-device-id:grpc-tests" api.tum.app:50052 api.Campus/GetNewsSources
grpcurl -protoset <(buf build -o -) -plaintext -H "x-device-id:grpc-tests" api.tum.app:50052 api.Campus/GetNewsSources
2 changes: 1 addition & 1 deletion deployment/charts/backend/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ dependencies:
- condition: mariadb.enabled
name: mariadb
repository: https://charts.bitnami.com/bitnami
version: 12.x.x
version: 12.x.x
12 changes: 12 additions & 0 deletions deployment/charts/backend/templates/deployments/backend-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ spec:
- name: logs
emptyDir: { }
containers:
- name: access-legacybackend
image: busybox:1.36
args: [/bin/sh, -c, 'tail -n+1 -F /var/log/apache2/access.log']
volumeMounts:
- name: logs
mountPath: /var/log
- name: error-legacybackend
image: busybox:1.36
args: [/bin/sh, -c, 'tail -n+1 -F /var/log/apache2/error.log']
volumeMounts:
- name: logs
mountPath: /var/log
- name: tca-legacybackend
image: ghcr.io/kordianbruck/tca-backend/tca-server:{{ $.Values.tag }}
imagePullPolicy: Always
Expand Down
2 changes: 1 addition & 1 deletion deployment/charts/backend/templates/deployments/hpas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ spec:
target:
type: Utilization
averageUtilization: 75
{{ end }}
{{ end }}
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ volumes:
campus-db-data:
driver: local
backend-storage:
driver: local
driver: local
4 changes: 2 additions & 2 deletions server/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ Follow the installation instructions detailed here: https://docs.buf.build/insta
Alternatively, we have prepared this installation script:

```shell
sh installBuf.sh
sh installBuf.bash
```

## Generating

Once you have installed all dependencies, run `./generate.sh` to update the client and server `Protocol Buffers` definitions.
Once you have installed all dependencies, run `./generate.bash` to update the client and server `Protocol Buffers` definitions.

# Common Issues

Expand Down
24 changes: 24 additions & 0 deletions server/api/generate.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# needs buf: https://docs.buf.build/installation#github-releases
BASEDIR=$(dirname "$0")
echo making sure that this script is run from $BASEDIR
pushd $BASEDIR > /dev/null

echo updating the generated files
buf mod update || exit 1
buf generate || exit 1

echo making sure the openapi document points to the valid api
grep -q '"basePath": "/v1"' ./tumdev/campus_backend.swagger.json || sed -i '1 a "basePath": "/v1",' ./tumdev/campus_backend.swagger.json

echo making sure that all artifacts we don\'t need are cleaned up
rm -f google/api/*.go
rm -f google/api/*.swagger.json

echo maing sure that the generated files are formatted
go fmt tumdev/*.go
goimports -w tumdev/*.go

# clean up the stack
popd > /dev/null
15 changes: 0 additions & 15 deletions server/api/generate.sh

This file was deleted.

14 changes: 13 additions & 1 deletion server/api/installBuf.sh → server/api/installBuf.bash
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
#!/bin/bash

BASEDIR=$(dirname "$0")
echo making sure that this script is run from $BASEDIR
pushd $BASEDIR > /dev/null

echo downloading...
go get github.com/bufbuild/buf/cmd/buf \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc

echo installing...
go install \
github.com/bufbuild/buf/cmd/buf \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc

go mod tidy

echo tidiing up
go mod tidy

popd
Loading

0 comments on commit 5ebf043

Please sign in to comment.