Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce git config on startup for Docker container #383

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ FROM base AS dev
EXPOSE 6157 2222 16157
VOLUME /opengist

RUN git config --global --add safe.directory /opengist

CMD ["make", "watch"]


Expand All @@ -60,7 +58,7 @@ RUN apk update && \
libstdc++

RUN addgroup -S opengist && \
adduser -S -G opengist -H -s /bin/ash -g 'Opengist User' opengist
adduser -S -G opengist -s /bin/ash -g 'Opengist User' opengist

COPY --from=build --chown=opengist:opengist /opengist/config.yml config.yml

Expand Down
4 changes: 4 additions & 0 deletions internal/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func Initialize(ctx *cli.Context) {
"Current git version: " + gitVersion)
}

if err := git.InitGitConfig(); err != nil {
log.Fatal().Err(err).Send()
}

homePath := config.GetHomeDir()
log.Info().Msg("Data directory: " + homePath)

Expand Down
23 changes: 23 additions & 0 deletions internal/git/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package git

import "os/exec"

func InitGitConfig() error {
configs := map[string]string{
"receive.advertisePushOptions": "true",
"safe.directory": "*",
}

for key, value := range configs {
if err := setGitConfig(key, value); err != nil {
return err
}
}

return nil
}

func setGitConfig(key, value string) error {
cmd := exec.Command("git", "config", "--global", key, value)
return cmd.Run()
}
Loading