Description
I am trying to install a private repository in Dockerfile via ssh. But when the runner trying to install the package, I got the error
Load key "/root/.ssh/key-801a24afcf65bdde333b552f2805263d9fe735a5977559ff47216d0f58d02aa5": error in libcrypto
.
Here are what I have done:
- Gen the key pairs
ssh-keygen -t rsa -b 4096 -C "[email protected]:xxx/repo.git"
-
Add content of the public key as Deploy key to the
[email protected]:xxx/repo.git
. Then add the private key's content to secrets
SSH_PRIVATE_KEY of the project which wants to install repo.git. -
Here is my package json, build.yml and Dockerfile
// package.json
"repo": "git+ssh://[email protected]:xxx/repo.git",
// build.yml
name: Build & push image
on:
workflow_call:
inputs:
GITHUB_PACKAGE_REPO_NAME:
required: true
type: string
jobs:
build-push-image:
runs-on: ubuntu-latest
steps:
- name: Set up SSH agent
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v3
- name: Collect Git and SSH config files in a directory that is part of the Docker build context
run: |
mkdir root-config
cp -r ~/.gitconfig ~/.ssh root-config/
- name: Log in to the Github Packages
uses: docker/login-action@xxx
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Add VERSION_LABEL with commit short sha
run: echo "VERSION_LABEL=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ghcr.io/xxx/${{ inputs.GITHUB_PACKAGE_REPO_NAME }}:${{ env.VERSION_LABEL }}
ssh: |
default=${{ env.SSH_AUTH_SOCK }}
// Dockerfile:
FROM node:18-alpine
USER root
# Copy the two files in place and fix different path/locations inside the Docker image
COPY root-config /root/
RUN sed 's|/home/runner|/root|g' -i.bak /root/.ssh/config
# Install Git
RUN apk update && apk add git
RUN apk add --no-cache openssh-client
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN --mount=type=ssh ssh -q -T [email protected] 2>&1 | echo "Welcome to Github"
WORKDIR /app/
COPY package.json ./
COPY yarn.lock ./
COPY tsconfig.json ./
COPY ./ ./
# RUN yarn add @nestjs/cli
RUN yarn install --no-cache
RUN yarn prisma generate
RUN yarn build
EXPOSE 8100
CMD yarn start
Whenever the workflow ran into RUN yarn install --no-cache
and tried to install the [email protected]:xxx/repo.git
via SSH, I got the error: Load key "/root/.ssh/key-801a24afcf65bdde333b552f2805263d9fe735a5977559ff47216d0f58d02aa5
. Can you tell me where I did wrong or what I am missing?