Skip to content

Commit

Permalink
Merge branch 'main' into feature/alarm-cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Sep 17, 2023
2 parents 5e0a2ee + 6d584c5 commit 2972e2d
Show file tree
Hide file tree
Showing 93 changed files with 1,182 additions and 966 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ APNS_P8_FILE_PATH=/secrets/AuthKey_XXXX.p8

ENVIRONMENT=dev

SENTRY_DSN=
SENTRY_DSN=
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
```
```
8 changes: 3 additions & 5 deletions client/localServer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func canteenHeadCount(c pb.CampusClient, ctx context.Context) {
})

if err != nil {
log.Error(err)
log.WithError(err).Error("Canteen HeadCount data request failed.")
} else {
log.WithField("res", res).Info("Canteen HeadCount data request successful.")
}
Expand Down Expand Up @@ -245,8 +245,7 @@ func getImageToBytes(path string) []byte {
}

defer func(file *os.File) {
err := file.Close()
if err != nil {
if err := file.Close(); err != nil {
log.WithError(err).Error("could not close file")
}
}(file)
Expand Down Expand Up @@ -291,8 +290,7 @@ func storeImage(path string, i []byte) (string, error) {
log.WithError(errFile).Error("Unable to create the new testfile")
}
defer func(out *os.File) {
err := out.Close()
if err != nil {
if err := out.Close(); err != nil {
log.WithError(err).Error("File was not closed successfully")
}
}(out)
Expand Down
8 changes: 4 additions & 4 deletions 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 All @@ -25,11 +26,10 @@ func main() {

conn, err := grpc.Dial(address, grpc.WithTransportCredentials(creds))
if err != nil {
log.WithError(err).Fatalf("did not connect")
log.WithError(err).Fatal("did not connect")
}
defer func(conn *grpc.ClientConn) {
err := conn.Close()
if err != nil {
if err := conn.Close(); err != nil {
log.WithError(err).Error("did not close connection")
}
}(conn)
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 @@ -46,4 +46,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 2972e2d

Please sign in to comment.