containerized-go-dev
containerized-go-dev copied to clipboard
Error in unit test: read-only file system
My application creates files and in my test I check whether the creation was successful or not. with go test
everything is fine, but with the containerised build I get the error of
read-only file system
I tried it with setting the mount to "bind"
FROM base AS unit-test RUN --mount=target=. \ --mount=type=bind,target=/root/.cache/go-build \ go test -v .
but without success.
Any hints for me?
Hi Arne @arossmann maybe you try once this containerized starter which was influenced from Chris one.
https://github.com/TomFreudenberg/golang-cli-cmd-dev-starter
I had the sme experience as you "read only" - for me it happens only when using docker build
and use the mount
experimental features in Dockerfile on OSX. I guess you also use a Mac?
For that I rewrote the processes and put the build statements into the Makefile with docker run
commands.
Hope that helps for you.
Cheers Tom
Bind mounts in this context mean bind mounting of the build context, not the files directly on the host. Note that the default mount without specifying a type
is bind.
By default bind mounts are readonly with the option for read-write but written files are discarded from the final build.
If you want to keep the outputs of tests, you try to output them to somewhere outside of the working directory that you've bind mounted into or you can do a COPY . .
instead of the mount=target=.
.
Old:
FROM base AS unit-test
RUN --mount=target=. \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
mkdir /out && go test -v -coverprofile=/out/cover.out ./...
New:
FROM base AS unit-test
COPY . .
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
mkdir /out && go test -v -coverprofile=/out/cover.out ./...