Compare commits
4 Commits
dd8a29acc2
...
1.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 74bce88cc0 | |||
| 5a5e776e8b | |||
| 02b5d88d34 | |||
| 6ab48eb534 |
@@ -2,7 +2,8 @@ name: Arbeitszeitmessung Deploy
|
||||
run-name: ${{ gitea.actor }} is building and deploying arbeitszeitmesssung
|
||||
on:
|
||||
push:
|
||||
tags: "*"
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
jobs:
|
||||
testing:
|
||||
|
||||
@@ -15,8 +15,8 @@ jobs:
|
||||
POSTGRES_DB: arbeitszeitmessung
|
||||
env:
|
||||
POSTGRES_HOST: postgres
|
||||
POSTGRES_USER: root
|
||||
POSTGRES_PASSWORD: password
|
||||
POSTGRES_API_USER: root
|
||||
POSTGRES_API_PASS: password
|
||||
POSTGRES_DB: arbeitszeitmessung
|
||||
POSTGRES_PORT: 5432
|
||||
RUNNER_TOOL_CACHE: /toolcache # Runner Tool Cache
|
||||
|
||||
@@ -14,7 +14,8 @@ func OpenDatabase() (models.IDatabase, error) {
|
||||
dbName := helper.GetEnv("POSTGRES_DB", "arbeitszeitmessung")
|
||||
dbUser := helper.GetEnv("POSTGRES_API_USER", "api_nutzer")
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func renderPDF(days []typstDay, metadata typstMetadata) (bytes.Buffer, error) {
|
||||
// Import the template and invoke the template function with the custom data.
|
||||
// Show is used to replace the current document with whatever content the template function in `template.typ` returns.
|
||||
markup.WriteString(`
|
||||
#import "template.typ": abrechnung
|
||||
#import "templates/abrechnung.typ": abrechnung
|
||||
#show: doc => abrechnung(meta, days)
|
||||
`)
|
||||
|
||||
@@ -84,7 +84,10 @@ func renderPDF(days []typstDay, metadata typstMetadata) (bytes.Buffer, error) {
|
||||
// defer f.Close()
|
||||
//
|
||||
|
||||
typstCLI := typst.CLI{}
|
||||
// typstCLI := typst.CLI{}
|
||||
typstCLI := typst.DockerExec{
|
||||
ContainerName: helper.GetEnv("TYPST_CONTAINER", "arbeitszeitmessung-doc-creator"),
|
||||
}
|
||||
if err := typstCLI.Compile(&markup, &output, nil); err != nil {
|
||||
return output, err
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ require github.com/a-h/templ v0.3.943
|
||||
require github.com/alexedwards/scs/v2 v2.8.0
|
||||
|
||||
require (
|
||||
github.com/Dadido3/go-typst v0.3.0
|
||||
github.com/Dadido3/go-typst v0.8.0
|
||||
github.com/golang-migrate/migrate/v4 v4.18.3
|
||||
github.com/joho/godotenv v1.5.1
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||
github.com/Dadido3/go-typst v0.3.0 h1:Itix2FtQgBiOuHUNqgGUAK11Oo2WMlZGGGpCiQNK1IA=
|
||||
github.com/Dadido3/go-typst v0.3.0/go.mod h1:QYis9sT70u65kn1SkFfyPRmHsPxgoxWbAixwfPReOZA=
|
||||
github.com/Dadido3/go-typst v0.8.0 h1:uTLYprhkrBjwsCXRRuyYUFL0fpYHa2kIYoOB/CGqVNs=
|
||||
github.com/Dadido3/go-typst v0.8.0/go.mod h1:QYis9sT70u65kn1SkFfyPRmHsPxgoxWbAixwfPReOZA=
|
||||
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
||||
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
||||
github.com/a-h/templ v0.3.943 h1:o+mT/4yqhZ33F3ootBiHwaY4HM5EVaOJfIshvd5UNTY=
|
||||
|
||||
@@ -31,7 +31,6 @@ func FormatDuration(d time.Duration) string {
|
||||
|
||||
// Converts duration to string
|
||||
func FormatDurationFill(d time.Duration, fill bool) string {
|
||||
return fmt.Sprintf("%.1f", d.Hours())
|
||||
hours := int(d.Abs().Hours())
|
||||
minutes := int(d.Abs().Minutes()) % 60
|
||||
sign := ""
|
||||
@@ -69,3 +68,10 @@ func GetWorkingDays(startDate, endDate time.Time) int {
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func FormatGermanDayOfWeek(t time.Time) string {
|
||||
return days[t.Weekday()][:2]
|
||||
}
|
||||
|
||||
var days = [...]string{
|
||||
"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"}
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestGetMonday(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFormatDuration(t *testing.T) {
|
||||
durations := []struct {
|
||||
testCases := []struct {
|
||||
name string
|
||||
duration time.Duration
|
||||
}{
|
||||
@@ -28,9 +28,9 @@ func TestFormatDuration(t *testing.T) {
|
||||
{"-1h 30min", time.Duration(-90 * time.Minute)},
|
||||
{"", 0},
|
||||
}
|
||||
for _, d := range durations {
|
||||
t.Run(d.name, func(t *testing.T) {
|
||||
if FormatDuration(d.duration) != d.name {
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if FormatDuration(tc.duration) != tc.name {
|
||||
t.Error("Format missmatch in Formatduration.")
|
||||
}
|
||||
})
|
||||
@@ -58,3 +58,27 @@ func TestGetWorkingDays(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatGermanDayOfWeek(t *testing.T) {
|
||||
testCases := []struct {
|
||||
date string
|
||||
result string
|
||||
}{
|
||||
{"2025-12-01", "Mo"},
|
||||
{"2025-12-02", "Di"},
|
||||
{"2025-12-03", "Mi"},
|
||||
{"2025-12-04", "Do"},
|
||||
{"2025-12-05", "Fr"},
|
||||
{"2025-12-06", "Sa"},
|
||||
{"2025-12-07", "So"},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(fmt.Sprintf("FormatWeekDayTest: %s date", tc.date), func(t *testing.T) {
|
||||
date, _ := time.Parse(time.DateOnly, tc.date)
|
||||
if FormatGermanDayOfWeek(date) != tc.result {
|
||||
t.Error("Formatted workday did not match!")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ templ defaultWeekDayComponent(u models.User, day models.IWorkDay) {
|
||||
<div class="flex flex-row gap-2">
|
||||
@timeGaugeComponent(day.GetDayProgress(u), false)
|
||||
<div class="flex flex-col">
|
||||
<p class=""><span class="font-bold uppercase hidden md:inline">{ day.Date().Format("Mon") }:</span> { day.Date().Format("02.01.2006") }</p>
|
||||
<p class=""><span class="font-bold uppercase hidden md:inline">{ helper.FormatGermanDayOfWeek(day.Date()) }:</span> { day.Date().Format("02.01.2006") }</p>
|
||||
if day.IsWorkDay() {
|
||||
{{
|
||||
workDay, _ := day.(*models.WorkDay)
|
||||
|
||||
@@ -151,9 +151,9 @@ func defaultWeekDayComponent(u models.User, day models.IWorkDay) templ.Component
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var7 string
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(day.Date().Format("Mon"))
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(helper.FormatGermanDayOfWeek(day.Date()))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 35, Col: 92}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 35, Col: 108}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -166,7 +166,7 @@ func defaultWeekDayComponent(u models.User, day models.IWorkDay) templ.Component
|
||||
var templ_7745c5c3_Var8 string
|
||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(day.Date().Format("02.01.2006"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 35, Col: 136}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 35, Col: 152}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
||||
@@ -98,7 +98,7 @@ templ defaultDayComponent(day models.IWorkDay) {
|
||||
@timeGaugeComponent(day.GetDayProgress(user), day.Date().Equal(time.Now().Truncate(24*time.Hour)))
|
||||
<div>
|
||||
<p>
|
||||
<span class="font-bold uppercase hidden md:inline">{ day.Date().Format("Mon") }:</span> { day.Date().Format("02.01.2006") }
|
||||
<span class="font-bold uppercase hidden md:inline">{ helper.FormatGermanDayOfWeek(day.Date()) }:</span> { day.Date().Format("02.01.2006") }
|
||||
</p>
|
||||
if day.IsWorkDay() {
|
||||
{{
|
||||
|
||||
@@ -269,9 +269,9 @@ func defaultDayComponent(day models.IWorkDay) templ.Component {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var12 string
|
||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(day.Date().Format("Mon"))
|
||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(helper.FormatGermanDayOfWeek(day.Date()))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timePage.templ`, Line: 101, Col: 82}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timePage.templ`, Line: 101, Col: 98}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
@@ -284,7 +284,7 @@ func defaultDayComponent(day models.IWorkDay) templ.Component {
|
||||
var templ_7745c5c3_Var13 string
|
||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(day.Date().Format("02.01.2006"))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timePage.templ`, Line: 101, Col: 126}
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timePage.templ`, Line: 101, Col: 142}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
POSTGRES_USER=root
|
||||
POSTGRES_PASSWORD=very_secure
|
||||
POSTGRES_API_USER=api_nutzer
|
||||
POSTGRES_API_PASS=password
|
||||
POSTGRES_PATH=../DB
|
||||
POSTGRES_DB=arbeitszeitmessung
|
||||
EXPOSED_PORT=8000
|
||||
TZ=Europe/Berlin
|
||||
PGTZ=Europe/Berlin
|
||||
API_TOKEN=dont_access
|
||||
EMPTY_DAYS=false
|
||||
@@ -1,12 +1,6 @@
|
||||
name: arbeitszeitmessung-dev
|
||||
services:
|
||||
db:
|
||||
image: postgres:16
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
PGDATA: /var/lib/postgresql/data/pg_data
|
||||
volumes:
|
||||
- ${POSTGRES_PATH}:/var/lib/postgresql/data
|
||||
# - ${POSTGRES_PATH}/initdb:/docker-entrypoint-initdb.d
|
||||
@@ -19,21 +13,8 @@ services:
|
||||
ports:
|
||||
- 8001:8080
|
||||
backend:
|
||||
image: git.letsstein.de/tom/arbeitszeitmessung
|
||||
restart: unless-stopped
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
POSTGRES_HOST: db
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
EXPOSED_PORT: ${EXPOSED_PORT}
|
||||
NO_CORS: true
|
||||
ports:
|
||||
- ${EXPOSED_PORT}:8080
|
||||
volumes:
|
||||
- ../logs:/app/Backend/logs
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
swagger:
|
||||
image: swaggerapi/swagger-ui
|
||||
|
||||
@@ -6,28 +6,31 @@ services:
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
PGTZ: ${TZ}
|
||||
PGDATA: /var/lib/postgresql/data/pg_data
|
||||
volumes:
|
||||
- ${POSTGRES_PATH}:/var/lib/postgresql/data
|
||||
- ${POSTGRES_PATH}/initdb:/docker-entrypoint-initdb.d
|
||||
ports:
|
||||
- 5432:5432
|
||||
- ${POSTGRES_PORT}:5432
|
||||
|
||||
backend:
|
||||
image: git.letsstein.de/tom/arbeitszeitmessung
|
||||
image: git.letsstein.de/tom/arbeitszeitmessung-webserver
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
POSTGRES_HOST: db
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
EXPOSED_PORT: ${EXPOSED_PORT}
|
||||
ports:
|
||||
- ${EXPOSED_PORT}:8080
|
||||
- ${WEB_PORT}:8080
|
||||
depends_on:
|
||||
- db
|
||||
- document-creator
|
||||
volumes:
|
||||
- ../logs:/app/Backend/logs
|
||||
restart: unless-stopped
|
||||
|
||||
document-creator:
|
||||
image: git.letsstein.de/tom/arbeitszeitmessung-doc-creator
|
||||
container_name: ${TYPST_CONTAINER}
|
||||
restart: unless-stopped
|
||||
|
||||
12
Docker/env.example
Normal file
12
Docker/env.example
Normal file
@@ -0,0 +1,12 @@
|
||||
POSTGRES_USER=root # Postgres ADMIN Nutzername
|
||||
POSTGRES_PASSWORD=very_secure # Postgres ADMIN Passwort
|
||||
POSTGRES_API_USER=api_nutzer # Postgres API Nutzername (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_DB=arbeitszeitmessung # Postgres Datenbank Name
|
||||
POSTGRES_PORT=127.0.0.1:5432 # Postgres Port will not be exposed by default.
|
||||
TZ=Europe/Berlin # Zeitzone
|
||||
PGTZ=Europe/Berlin # Zeitzone
|
||||
API_TOKEN=dont_access # API Token für ESP Endpoints
|
||||
WEB_PORT=8000 # Port from which Arbeitszeitmessung should be accessable regex:^[0-9]{1,5}$
|
||||
TYPST_CONTAINER=arbeitszeitmessung-doc-creator # Name of the pdf compiler container
|
||||
6
DocumentCreator/Dockerfile
Normal file
6
DocumentCreator/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM ghcr.io/typst/typst:0.14.0
|
||||
|
||||
COPY ./templates ./templates
|
||||
COPY ./static ./static
|
||||
|
||||
ENTRYPOINT ["sh", "-c", "while true; do sleep 3600; done"]
|
||||
BIN
DocumentCreator/static/logo.png
Normal file
BIN
DocumentCreator/static/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
92
DocumentCreator/templates/abrechnung.typ
Normal file
92
DocumentCreator/templates/abrechnung.typ
Normal file
@@ -0,0 +1,92 @@
|
||||
#let table-header(..headers) = {
|
||||
table.header(
|
||||
..headers.pos().map(h => strong(h))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
#let abrechnung(meta, days) = {
|
||||
set page(paper: "a4", margin: (x:1.5cm, y:2.25cm),
|
||||
footer:[#grid(
|
||||
columns: (3fr, .65fr),
|
||||
align: left + horizon,
|
||||
inset: .5em,
|
||||
[#meta.EmployeeName -- #meta.TimeRange], grid.cell(rowspan: 2)[#image("static/logo.png")],
|
||||
[Arbeitszeitrechnung maschinell erstellt am #meta.CurrentTimestamp],
|
||||
)
|
||||
])
|
||||
set text(font: "Noto Sans", size:10pt, fill: luma(10%))
|
||||
set table(
|
||||
stroke: 0.5pt + luma(10%),
|
||||
inset: .5em,
|
||||
align: center + horizon,
|
||||
)
|
||||
show text: it => {
|
||||
if it.text == "0min"{
|
||||
text(oklch(70.8%, 0, 0deg))[#it]
|
||||
}else if it.text.starts-with("-"){
|
||||
text(red)[#it]
|
||||
}else{
|
||||
it
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[= Abrechnung Arbeitszeit -- #meta.EmployeeName]
|
||||
|
||||
[Zeitraum: #meta.TimeRange]
|
||||
|
||||
table(
|
||||
columns: (1fr, 1fr, 1fr, 1fr, 1fr, 1fr, 1.25fr),
|
||||
fill: (x, y) =>
|
||||
if y == 0 { oklch(87%, 0, 0deg) },
|
||||
table-header(
|
||||
[Datum], [Kommen], [Gehen], [Arbeitsart], [Stunden], [Pause], [Überstunden]
|
||||
),
|
||||
.. for day in days {
|
||||
(
|
||||
[#day.Date],
|
||||
if day.DayParts.len() == 0{
|
||||
table.cell(colspan: 3)[Keine Buchungen]
|
||||
}else if not day.DayParts.first().IsWorkDay{
|
||||
table.cell(colspan: 3)[#day.DayParts.first().WorkType]
|
||||
}
|
||||
else {
|
||||
|
||||
table.cell(colspan: 3, inset: 0em)[
|
||||
|
||||
#table(
|
||||
columns: (1fr, 1fr, 1fr),
|
||||
.. for Zeit in day.DayParts {
|
||||
(
|
||||
[#Zeit.BookingFrom],
|
||||
[#Zeit.BookingTo],
|
||||
[#Zeit.WorkType],
|
||||
)
|
||||
},
|
||||
)
|
||||
]
|
||||
},
|
||||
[#day.Worktime],
|
||||
[#day.Pausetime],
|
||||
[#day.Overtime],
|
||||
)
|
||||
if day.IsFriday {
|
||||
( table.cell(colspan: 7, fill: oklch(87%, 0, 0deg))[Wochenende], ) // note the trailing comma
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
table(
|
||||
columns: (3fr, 1fr),
|
||||
align: right,
|
||||
inset: (x: .25em, y:.75em),
|
||||
stroke: none,
|
||||
table.hline(start: 0, end: 2, stroke: stroke(dash:"dashed", thickness:.5pt)),
|
||||
[Arbeitszeit :], table.cell(align: left)[#meta.WorkTime],
|
||||
[Überstunden :], table.cell(align: left)[#meta.Overtime],
|
||||
[Überstunden :],table.cell(align: left)[#meta.OvertimeTotal],
|
||||
table.hline(start: 0, end: 2),
|
||||
|
||||
)
|
||||
}
|
||||
8
Makefile
8
Makefile
@@ -52,3 +52,11 @@ test:
|
||||
|
||||
scan: test
|
||||
$(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"
|
||||
|
||||
108
install.sh
Executable file
108
install.sh
Executable file
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
envFile=Docker/.env
|
||||
envExample=Docker/env.example
|
||||
|
||||
echo "Checking Docker installation..."
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo "Docker not found. Install Docker? [y/N]"
|
||||
read -r install_docker
|
||||
if [[ "$install_docker" =~ ^[Yy]$ ]]; then
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
else
|
||||
echo "Docker is required. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Docker is already installed."
|
||||
fi
|
||||
|
||||
echo "Checking Docker Compose..."
|
||||
if ! docker compose version >/dev/null 2>&1; then
|
||||
echo "Docker Compose plugin missing. You may need to update Docker."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Preparing .env file..."
|
||||
if [ ! -f $envFile ]; then
|
||||
if [ -f $envExample ]; then
|
||||
echo ".env not found. Creating interactively from .env.example."
|
||||
> $envFile
|
||||
|
||||
while IFS= read -r line; do
|
||||
|
||||
#ignore empty lines and comments
|
||||
[[ "$line" =~ ^#.*$ || -z "$line" ]] && continue
|
||||
|
||||
|
||||
key=$(printf "%s" "$line" | cut -d '=' -f 1)
|
||||
rest=$(printf "%s" "$line" | cut -d '=' -f 2-)
|
||||
|
||||
# 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
|
||||
|
||||
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
|
||||
|
||||
echo ".env created."
|
||||
else
|
||||
echo "No .env or .env.example found."
|
||||
echo "Creating an empty .env file for manual editing."
|
||||
touch $envFile
|
||||
fi
|
||||
else
|
||||
echo "Using existing .env. (found at $envFile)"
|
||||
fi
|
||||
|
||||
echo "Start containers with docker compose up -d? [y/N]"
|
||||
read -r start_containers
|
||||
if [[ "$start_containers" =~ ^[Yy]$ ]]; then
|
||||
cd Docker
|
||||
mkdir ../logs
|
||||
docker compose up -d
|
||||
echo "Containers started."
|
||||
else
|
||||
echo "You can start them manually with: docker compose up -d"
|
||||
fi
|
||||
Reference in New Issue
Block a user