Skip to content

Commit 95aa5db

Browse files
committed
chore(cosmos): attempt to work around fs perms
1 parent 014da25 commit 95aa5db

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

golang/cosmos/Makefile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,37 @@ endif
9191
### Protobuf ###
9292
###############################################################################
9393

94+
usertag:=$(shell id -u)-$(shell id -g)
95+
protoImageStamp=build/proto-image-$(usertag).stamp
9496
protoVer=0.15.3
95-
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
96-
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)
97+
protoSourceImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
98+
protoImageName=$(protoSourceImageName)-user-$(usertag)
99+
#protoUserFlags=-e HOME=/tmp \
100+
# --user=$(shell id -u):$(shell id -g) \
101+
# $(shell id -G | xargs -n1 printf -- ' --group-add %s')
102+
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace:z --workdir /workspace $(protoImageName)
103+
104+
$(protoImageStamp):
105+
@echo "Creating user-specific Protobuf builder image $(protoImageName)"
106+
mkdir -p build/empty
107+
$(DOCKER) build \
108+
--build-arg NEW_UID=$(shell id -u) --build-arg SOURCE_IMAGE=$(protoSourceImageName) \
109+
--pull --load -f proto/Dockerfile -t $(protoImageName) build/empty
110+
@touch $(protoImageStamp)
97111

98112
proto-all: proto-format proto-lint proto-gen
99113

100-
proto-gen:
114+
proto-gen: $(protoImageStamp)
101115
@echo "Generating Protobuf files"
102116
@$(protoImage) sh ./scripts/protocgen.sh
103117

104-
proto-format:
118+
proto-format: $(protoImageStamp)
105119
@$(protoImage) find ./proto -name "*.proto" -exec clang-format -i {} \;
106120

107-
proto-lint:
121+
proto-lint: $(protoImageStamp)
108122
@$(protoImage) buf lint --error-format=json ./proto
109123

110-
proto-check-breaking:
124+
proto-check-breaking: $(protoImageStamp)
111125
@$(protoImage) buf breaking --against $(PR_TARGET_REPO)#branch=$(PR_TARGET_BRANCH),subdir=golang/cosmos
112126

113127
GOGO_PROTO_URL = file://$(shell go list -m -f '{{ .Dir }}' github.com/cosmos/gogoproto)

golang/cosmos/proto/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ARG SOURCE_IMAGE
2+
FROM ${SOURCE_IMAGE}
3+
4+
ARG NEW_UID
5+
RUN id -u > old_uid
6+
USER root
7+
8+
# Change file ownership from old UID to NEW_UID
9+
RUN find / -path /proc -prune -o -user $(cat old_uid) -print0 | \
10+
xargs -0 -n256 chown ${NEW_UID}
11+
12+
# Modify /etc/passwd to set the user ID to NEW_UID
13+
RUN sed -i -e "s/\\(^[^:]*:[^:]*:\\)$(cat old_uid)/\\1${NEW_UID}/" /etc/passwd
14+
USER ${NEW_UID}

golang/cosmos/scripts/protocgen.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@
55
# docker run --rm -v $(pwd):/workspace --workdir /workspace cosmossdk-proto sh ./scripts/protocgen.sh
66

77
set -eo pipefail
8+
cd proto
9+
10+
if touch .permtest; then
11+
rm -f .permtest
12+
else
13+
echo "ERROR: Cannot write to the current directory. Please check the permissions for this user."
14+
id || true
15+
ls -ald . || true
16+
exit 1
17+
fi
818

919
echo "Generating gogo proto code"
10-
cd proto
1120
proto_dirs=$(find . -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
1221
for dir in $proto_dirs; do
1322
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do

0 commit comments

Comments
 (0)