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

Error in unit test: read-only file system #9

Open
arossmann opened this issue Mar 23, 2021 · 2 comments
Open

Error in unit test: read-only file system #9

arossmann opened this issue Mar 23, 2021 · 2 comments

Comments

@arossmann
Copy link

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?

@TomFreudenberg
Copy link

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

@chris-crone
Copy link
Owner

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 ./...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants