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

fix: use correct uid/gid to avoid cache saving propems in GH action mode #65

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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
6 changes: 4 additions & 2 deletions Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM debian:12.6-slim

RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates
RUN update-ca-certificates
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && update-ca-certificates && \
addgroup --system --gid 127 docker && adduser --uid 1001 --gid 127 --disabled-password runner

COPY k6registry /usr/bin/

USER runner

ENTRYPOINT ["k6registry"]
27 changes: 0 additions & 27 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import (
"io/fs"
"log/slog"
"os"
"path/filepath"

"github.com/adrg/xdg"
"github.com/grafana/k6registry"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -55,9 +53,6 @@ func New(levelVar *slog.LevelVar) (*cobra.Command, error) {

return run(cmd.Context(), args, opts)
},
PostRunE: func(_ *cobra.Command, _ []string) error {
return ghActionFixPerm(xdg.CacheHome)
},
}

ctx, err := newContext(context.TODO(), root.Root().Name())
Expand Down Expand Up @@ -171,28 +166,6 @@ func run(ctx context.Context, args []string, opts *options) (result error) {
return nil
}

func ghActionFixPerm(dir string) error {
if os.Getenv("GITHUB_ACTIONS") != "true" { //nolint:forbidigo
return nil
}

return filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}

var mode fs.FileMode

if info.IsDir() {
mode = permDir
} else {
mode = permFile
}

return os.Chmod(path, mode) //nolint:forbidigo
})
}

const (
permFile fs.FileMode = 0o644
permDir fs.FileMode = 0o755
Expand Down
9 changes: 9 additions & 0 deletions releases/v0.1.23.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
k6registry `v0.1.23` is here 🎉!

This is an internal maintenance release.

**Fix cache saving issue**

The GitHub workflow is running with user id `1001` and group id `127`. The k6registry docker container runs with the default user id in debian. As a consequence, the cache directory created under XDG_CACHE_HOME fails to save.

The solution is to use the same user id and group id as the GitHub workflow in the k6registry docker container (user id: `1001`, group id: `127`).
Loading