Skip to content

Commit

Permalink
Merge pull request #65 from grafana/64-fix-cache-saving-issue
Browse files Browse the repository at this point in the history
fix: use correct uid/gid to avoid cache saving propems in GH action mode
  • Loading branch information
szkiba committed Sep 10, 2024
2 parents b48c917 + f61faa4 commit 9c17379
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 29 deletions.
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`).

0 comments on commit 9c17379

Please sign in to comment.