我正在尝试设置 bitbucket pipline 来自动化构建阶段 但我遇到了错误并且 pipline 失败了
COPY ./fronted/package*.json ./
COPY failed: no source files were specified
root@project:/frontend# docker build -f docker/Dockerfile -t frontend:6.0 .
构建成功 有什么想法吗?
bitbucket中的文件结构
|-- fronted
| |-- package.json
| |-- other frontend files
|-- docker
| |-- Dockerfile
| |-- nginx.conf
|-- bitbucket-pipelines.yml
Dockerfile
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# Step 2: Create Nginx Server
FROM nginx:stable-alpine as production-stage
COPY docker/nginx.conf /etc/nginx/nginx.conf
COPY --from=build-stage /app/dist /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
bitbucket-pipline.yml
image: atlassian/default-image:3
pipelines:
branches:
master:
- step:
runs-on:
- 'self.hosted'
- 'linux'
name: Build and Save image
script:
- echo "Building Docker image"
- export DOCKER_HOST=tcp://127.0.0.1:2375
- docker login docker-c2.comp.net -u admin -p $NEXUS_PASSWORD
- docker build -f frontend/docker/Dockerfile -t docker-c2.comp.net/support-center-netcore/fronted-support-center-netcore-kz:v1.$BITBUCKET_BUILD_NUMBER .
# Push the Docker image to the container registry2
- docker push docker-c2.comp.net/support-center-netcore/fronted-support-center-netcore-kz:v1.$BITBUCKET_BUILD_NUMBER
这是由于工作目录所致。
在您的主机中,您正在 frontend 文件夹下构建,docker 可以在其中 COPY package*.json。
在bamboo服务器中,您正在frontend的父文件夹中构建,其中package*.json不存在,因此docker会抛出错误。
要修复它,您需要在竹作业中添加cd前端步骤。