File contents get mixed up

I have had some serious issues with Circle CI lately where the code of one file has ended up inside another file, and vice versa. Rerunning the same build, the file that gets mixed up changes, and sometimes nothing gets mixed up at all, and my build actually succeeds.

Running the same steps on the same docker image on my Mac locally does not produce the same irregular behaviour.

This is how the build environment image is setup:

FROM node:10.10-alpine

WORKDIR /root/folder-1

RUN apk -v --update add \
  bash \
  lcms2-dev \
  libpng-dev \
  python \
  py-pip \
  groff \
  less \
  mailcap \
  git \
  openssh-client \
  && \
  pip install --upgrade pip awscli==1.15.20 python-magic && \
  apk -v --purge del py-pip && \
  rm /var/cache/apk/*

RUN apk add --update --no-cache \
  --repository http://dl-3.alpinelinux.org/alpine/edge/testing \
  vips-dev fftw-dev gcc g++ make libc6-compat

COPY . .

RUN yarn

.circleci

  build:
    working_directory: ~/folder-2
    docker:
      - image: my-image

    steps:
      - checkout
      - run: ../folder-1/my-script.sh

my-script.sh

#!/bin/sh
mv -v ../folder-1/* ./
rm -rf ./src/content/
mv -v ./copied-content ./src/content

set -e

yarn build

Files that have their content replaced are usually typescript-files and reside inside the src folder, but not in src/content. However I do not know if it is limited to these circumstances.

I’d be willing to let somebody from the CircleCI team look at my builds if that could help the debugging.

What files get mixed up? Can you give a real example from a broken build (cut down if necessary)?

Have you any thoughts about what command causes the mix-up? For example, if you omit the yarn build, can it still happen (intermittently)?