Skip to content

Commit

Permalink
Added warnings in setup if /app/data or /app/config is not mounted as…
Browse files Browse the repository at this point in the history
… a volume #203
  • Loading branch information
Forceu committed Dec 5, 2024
1 parent ddc72b0 commit a291030
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ FROM alpine:3.19


RUN addgroup -S gokapi && adduser -S gokapi -G gokapi
RUN apk update && apk add --no-cache su-exec tini ca-certificates curl tzdata && mkdir /app && touch /app/.isdocker
RUN apk update && apk add --no-cache su-exec tini ca-certificates curl tzdata && \
mkdir /app && touch /app/.isdocker

COPY dockerentry.sh /app/run.sh

Expand Down
2 changes: 2 additions & 0 deletions docs/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Set ``-e TZ=UTC`` to the timezone you are in, e.g. ``-e TZ=Europe/Berlin``.

If you do not want the binary to run as the root user in the container, you can set the environment variable ``DOCKER_NONROOT`` to true.

Please make sure that ``/app/data`` and ``/app/config`` are mounted as volumes (see example above), otherwise you will lose all your data after rebuilding or updating your container.


Native Deployment
""""""""""""""""""
Expand Down
56 changes: 41 additions & 15 deletions internal/configuration/setup/Setup.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package setup

import (
"bufio"
"context"
"embed"
"encoding/json"
Expand Down Expand Up @@ -670,25 +671,31 @@ func splitAndTrim(input string) []string {
}

type setupView struct {
IsInitialSetup bool
LocalhostOnly bool
HasAwsFeature bool
IsDocker bool
S3EnvProvided bool
Port int
OAuthUsers string
OAuthGroups string
HeaderUsers string
Auth models.AuthenticationConfig
Settings models.Configuration
CloudSettings cloudconfig.CloudConfig
DatabaseSettings models.DbConnection
ProtectedUrls []string
IsInitialSetup bool
LocalhostOnly bool
HasAwsFeature bool
IsDocker bool
S3EnvProvided bool
IsDataNotMounted bool
IsConfigNotMounted bool
Port int
OAuthUsers string
OAuthGroups string
HeaderUsers string
Auth models.AuthenticationConfig
Settings models.Configuration
CloudSettings cloudconfig.CloudConfig
DatabaseSettings models.DbConnection
ProtectedUrls []string
}

func (v *setupView) loadFromConfig() {
v.IsInitialSetup = isInitialSetup
v.IsDocker = environment.IsDockerInstance()
if environment.IsDockerInstance() {
v.IsDocker = true
v.IsDataNotMounted = !isVolumeMounted("/app/data")
v.IsConfigNotMounted = !isVolumeMounted("/app/config")
}
v.HasAwsFeature = aws.IsIncludedInBuild
v.ProtectedUrls = protectedUrls
if isInitialSetup {
Expand Down Expand Up @@ -721,6 +728,25 @@ func (v *setupView) loadFromConfig() {
v.DatabaseSettings = dbSettings
}

func isVolumeMounted(path string) bool {
file, err := os.Open("/proc/mounts")
if err != nil {
fmt.Println(err)
return false
}
defer file.Close()

scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
fields := strings.Fields(line)
if len(fields) > 1 && fields[1] == path {
return true
}
}
return false
}

// Handling of /start
func handleShowSetup(w http.ResponseWriter, r *http.Request) {
templateFolder, err := template.ParseFS(templateFolderEmbedded, "templates/*.tmpl")
Expand Down
11 changes: 11 additions & 0 deletions internal/configuration/setup/templates/setup.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@
You can now change the Gokapi configuration. For further information please refer to the <a href="https://gokapi.readthedocs.io/en/stable/" title="Gokapi Documentation" target="_blank" rel="noopener noreferrer">documentation</a>.
</p>
{{ end }}
<br>
{{ if .IsDataNotMounted }}
<p>
<span style="color:#FF0000;"><b>Warning:</b> It appears that your <code>/app/data</code> directory has not been mounted as a volume. This will result in complete data loss once you update or rebuild this container!</span>
</p>
{{ end }}
{{ if .IsConfigNotMounted }}
<p>
<span style="color:#FF0000;"><b>Warning:</b> It appears that your <code>/app/config</code> directory has not been mounted as a volume. This will result in complete data loss once you update or rebuild this container!</span>
</p>
{{ end }}

</div>
</div>
Expand Down

0 comments on commit a291030

Please sign in to comment.