added install script + reworked pipeline
Some checks failed
Tests / Run Go Tests (push) Failing after 18s

This commit is contained in:
2025-11-30 19:54:00 +01:00
parent 8cb63d3342
commit dd8a29acc2
7 changed files with 75 additions and 21 deletions

View File

@@ -2,7 +2,8 @@ name: Arbeitszeitmessung Deploy
run-name: ${{ gitea.actor }} is building and deploying arbeitszeitmesssung run-name: ${{ gitea.actor }} is building and deploying arbeitszeitmesssung
on: on:
push: push:
tags: "*" tags:
- "*"
jobs: jobs:
testing: testing:

View File

@@ -15,8 +15,8 @@ jobs:
POSTGRES_DB: arbeitszeitmessung POSTGRES_DB: arbeitszeitmessung
env: env:
POSTGRES_HOST: postgres POSTGRES_HOST: postgres
POSTGRES_USER: root POSTGRES_API_USER: root
POSTGRES_PASSWORD: password POSTGRES_API_PASS: password
POSTGRES_DB: arbeitszeitmessung POSTGRES_DB: arbeitszeitmessung
POSTGRES_PORT: 5432 POSTGRES_PORT: 5432
RUNNER_TOOL_CACHE: /toolcache # Runner Tool Cache RUNNER_TOOL_CACHE: /toolcache # Runner Tool Cache
@@ -26,10 +26,7 @@ jobs:
with: with:
# Disabling shallow clone is recommended for improving relevancy of reporting # Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0 fetch-depth: 0
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: Backend/go.mod
- uses: https://gitea.com/actions/go-hashfiles@v0.0.1 - uses: https://gitea.com/actions/go-hashfiles@v0.0.1
id: hash-go id: hash-go
with: with:
@@ -46,6 +43,10 @@ jobs:
key: arbeitszeitmessung-${{ steps.hash-go.outputs.hash }} key: arbeitszeitmessung-${{ steps.hash-go.outputs.hash }}
restore-keys: |- restore-keys: |-
arbeitszeitmessung- arbeitszeitmessung-
- name: Setup go
uses: actions/setup-go@v5
with:
go-version-file: Backend/go.mod
- name: Run Go Tests - name: Run Go Tests
run: cd Backend && mkdir .test && go test ./... -coverprofile=.test/coverage.out -json > .test/report.json run: cd Backend && mkdir .test && go test ./... -coverprofile=.test/coverage.out -json > .test/report.json
- name: Verify coverage report exists - name: Verify coverage report exists

View File

@@ -14,7 +14,8 @@ func OpenDatabase() (models.IDatabase, error) {
dbName := helper.GetEnv("POSTGRES_DB", "arbeitszeitmessung") dbName := helper.GetEnv("POSTGRES_DB", "arbeitszeitmessung")
dbUser := helper.GetEnv("POSTGRES_API_USER", "api_nutzer") dbUser := helper.GetEnv("POSTGRES_API_USER", "api_nutzer")
dbPassword := helper.GetEnv("POSTGRES_API_PASS", "password") dbPassword := helper.GetEnv("POSTGRES_API_PASS", "password")
dbTz := helper.GetEnv("TZ", "Europe/Berlin")
connStr := fmt.Sprintf("postgres://%s:%s@%s:5432/%s?sslmode=disable&TimeZone=Europe/Berlin", dbUser, dbPassword, dbHost, dbName) connStr := fmt.Sprintf("postgres://%s:%s@%s:5432/%s?sslmode=disable&TimeZone=%s", dbUser, dbPassword, dbHost, dbName, dbTz)
return sql.Open("postgres", connStr) return sql.Open("postgres", connStr)
} }

View File

@@ -6,9 +6,7 @@ services:
env_file: env_file:
- .env - .env
environment: environment:
POSTGRES_USER: ${POSTGRES_USER} PGTZ: ${TZ}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
PGDATA: /var/lib/postgresql/data/pg_data PGDATA: /var/lib/postgresql/data/pg_data
volumes: volumes:
- ${POSTGRES_PATH}:/var/lib/postgresql/data - ${POSTGRES_PATH}:/var/lib/postgresql/data

View File

@@ -4,7 +4,7 @@ POSTGRES_API_USER=api_nutzer # Postgres API Nutzername (für Arbeitszeitmessu
POSTGRES_API_PASS=password # Postgres API Passwort (für Arbeitszeitmessung) POSTGRES_API_PASS=password # Postgres API Passwort (für Arbeitszeitmessung)
POSTGRES_PATH=../DB # Datebank Pfad (relativ zu Docker Ordner oder absoluter pfad mit /...) POSTGRES_PATH=../DB # Datebank Pfad (relativ zu Docker Ordner oder absoluter pfad mit /...)
POSTGRES_DB=arbeitszeitmessung # Postgres Datenbank Name POSTGRES_DB=arbeitszeitmessung # Postgres Datenbank Name
EXPOSED_PORT=8000 # Port auf welchem Arbeitszeitmessung läuft EXPOSED_PORT=8000 # Port auf welchem Arbeitszeitmessung läuft regex:^[0-9]{1,5}$
TZ=Europe/Berlin # Zeitzone TZ=Europe/Berlin # Zeitzone
PGTZ=Europe/Berlin # Zeitzone PGTZ=Europe/Berlin # Zeitzone
API_TOKEN=dont_access # API Token für ESP Endpoints API_TOKEN=dont_access # API Token für ESP Endpoints

View File

@@ -52,3 +52,11 @@ test:
scan: test scan: test
$(MAKE) -C Backend scan $(MAKE) -C Backend scan
Docker/.env:
cp Docker/env.example Docker/.env
echo "Konfigurations Datei erstellt (./Docker/.env), bitte zuerst ausfüllen und danach erneut 'make install' ausführen"
exit 0
install: Docker/.env
echo "Install"

View File

@@ -30,16 +30,60 @@ if [ ! -f $envFile ]; then
echo ".env not found. Creating interactively from .env.example." echo ".env not found. Creating interactively from .env.example."
> $envFile > $envFile
while IFS="=" read -r key val; do while IFS= read -r line; do
[[ "$key" =~ ^#.*$ || -z "$key" ]] && continue
default_value=$(echo "$val" | sed 's/"//g') #ignore empty lines and comments
printf "Value for $key (default: $default_value): " [[ "$line" =~ ^#.*$ || -z "$line" ]] && continue
read -r user_value < /dev/tty
if [ -z "$user_value" ]; then
echo "$key=$default_value" >> $envFile key=$(printf "%s" "$line" | cut -d '=' -f 1)
else rest=$(printf "%s" "$line" | cut -d '=' -f 2-)
echo "$key=$user_value" >> $envFile
# extract inline comment portion
comment=$(printf "%s" "$rest" | sed -n 's/.*# \(.*\)$/\1/p')
raw_val=$(printf "%s" "$rest" | sed 's/ *#.*//')
default_value=$(printf "%s" "$raw_val" | sed 's/"//g')
regex=""
if [[ "$comment" =~ regex:(.*)$ ]]; then
regex="${BASH_REMATCH[1]}"
fi fi
comment=$(printf "%s" "$comment" | sed 's/ regex:.*//')
while true; do
if [ -z "$comment" ]; then
printf "Value for $key - $comment (default: $default_value"
else
printf "Value for $key (default: $default_value"
fi
if [ -n "$regex" ]; then
printf ", must match: %s" "$regex"
fi
printf "):\n"
read user_input < /dev/tty
# empty input -> take default
[ -z "$user_input" ] && user_input="$default_value"
printf "\e[A$user_input\n"
# validate
if [ -n "$regex" ]; then
if [[ "$user_input" =~ $regex ]]; then
echo "$key=$user_input" >> $envFile
break
else
printf "Invalid value. Does not match regex: %s\n" "$regex"
continue
fi
else
echo "$key=$user_input" >> $envFile
break
fi
done
done < $envExample done < $envExample
echo ".env created." echo ".env created."
@@ -55,6 +99,7 @@ fi
echo "Start containers with docker compose up -d? [y/N]" echo "Start containers with docker compose up -d? [y/N]"
read -r start_containers read -r start_containers
if [[ "$start_containers" =~ ^[Yy]$ ]]; then if [[ "$start_containers" =~ ^[Yy]$ ]]; then
cd Docker
docker compose up -d docker compose up -d
echo "Containers started." echo "Containers started."
else else