【问题标题】:Backstage: build docker image后台:搭建docker镜像
【发布时间】:2022-08-03 17:04:51
【问题描述】:

我正在尝试构建后台代码的 docker 映像 (https://github.com/backstage/backstage) 此外,我的 dockerfile 与此处记录的相同:https://backstage.io/docs/deployment/docker#multi-stage-build

但是,每当我尝试构建 docker 映像时,它都会抱怨错误:

#19 [build 10/10] RUN yarn build
#19 sha256:230493e99704b51c04c3dfbb54c48c05c41decce3b8cac9992d7ce37b5211ea8
#19 1.208 yarn run v1.22.1
#19 1.257 $ backstage-cli repo build --all
#19 1.272 /bin/sh: 1: backstage-cli: not found
#19 1.287 error Command failed with exit code 127.
#19 1.287 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
#19 ERROR: executor failed running [/bin/sh -c yarn build]: exit code: 127

有人可以帮助我在构建 docker 映像时在这里缺少什么吗?

谢谢!

    标签: docker dockerfile backstage


    【解决方案1】:

    你可以试试下面的dockerfile:

    FROM node:16-bullseye-slim AS packages
    
    WORKDIR /app
    COPY package.json yarn.lock ./
    COPY packages packages
    COPY catalog-info.yaml ./
    
    #COPY plugins plugins
    
    RUN find packages \! -name "package.json" -mindepth 2 -maxdepth 2 -exec rm -rf {} \+
    
    # Stage 2 - Install dependencies and build packages
    
    FROM node:16-bullseye-slim AS build
    
    WORKDIR /app
    
    COPY --from=packages /app .
    
    # install sqlite3 dependencies 
    
    #RUN apt-get update && \
    #    apt-get install -y --no-install-recommends libsqlite3-dev python3 build-essential && \
    #    yarn config set python /usr/bin/python3
    
    RUN yarn install --frozen-lockfile --network-timeout 600000 && rm -rf "$(yarn cache dir)"
    
    COPY . .
    
    RUN yarn tsc
    RUN yarn --cwd packages/backend build
    
    # If you have not yet migrated to package roles, use the following command instead:
    #RUN yarn --cwd packages/backend backstage-cli backend:bundle --build-dependencies
    
    # Stage 3 - Build the actual backend image and install production dependencies
    FROM node:16-bullseye-slim
    
    WORKDIR /app
    
    # install sqlite3 dependencies, you can skip this if you don't use sqlite3 in the image
    #RUN apt-get update && \
    #    apt-get install -y --no-install-recommends libsqlite3-dev python3 build-essential && \
    #    rm -rf /var/lib/apt/lists/* && \
    #    yarn config set python /usr/bin/python3
    
    # Copy the install dependencies from the build stage and context
    COPY --from=build /app/yarn.lock /app/package.json /app/packages/backend/dist/skeleton.tar.gz ./
    RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz
    
    RUN yarn install --frozen-lockfile --production --network-timeout 600000 && rm -rf "$(yarn cache dir)"
    
    # Copy the built packages from the build stage
    COPY --from=build /app/packages/backend/dist/bundle.tar.gz .
    RUN tar xzf bundle.tar.gz && rm bundle.tar.gz
    
    # Copy any other files that we need at runtime
    COPY app-config.yaml ./
    #COPY github-app-proficloud-backstage-app-credentials.yaml ./ 
    
    #This is for Tech-Docs
    #RUN apt-get update && apt-get install -y python3 python3-pip
    #RUN pip3 install mkdocs-techdocs-core==1.0.1
    
    #This is enable for software templating to work
    #RUN pip3 install cookiecutter
    
    CMD ["node", "packages/backend", "--config", "app-config.yaml"]
    

    【讨论】:

    • 我没有安装 Sqlite3 依赖项,因为我已经配置了 postgres DB,在您的情况下可能需要它。
    猜你喜欢
    • 2021-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 2020-10-06
    • 1970-01-01
    相关资源
    最近更新 更多