SSH private repos with docker and yarn

Viewed 309

We are currently pulling private repos using ssh and npm.

# syntax=docker/dockerfile:experimental
FROM node:14.15.4-alpine
EXPOSE 4800

# Below is needed so that postinstall scripts can run inside docker
RUN npm set unsafe-perm true

COPY . /workspace
WORKDIR /workspace
# Install ssh client and git
RUN apk add --no-cache openssh-client git

# Download public key for github.com
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

RUN --mount=type=ssh npm ci

CMD ["npm", "run", "start:docker"]

Everything works fine. However, we want to move to yarn for other reasons. But this

# syntax=docker/dockerfile:experimental
FROM node:14.15.4-alpine
EXPOSE 4800

# Below is needed so that postinstall scripts can run inside docker
RUN yarn config set unsafe-perm true

COPY . /workspace
WORKDIR /workspace
# Install ssh client and git
RUN apk add --no-cache openssh-client git

# Download public key for github.com
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

RUN --mount=type=ssh yarn install

CMD ["yarn", "start:docker"]

throws a 401 on the private repos. I should also add that building locally with yarn has no issues. So the SSH keys are correct.

0 Answers
Related