我目前正在尝试设置 GitHub 操作,以自动构建后端并将其推送到 DockerHub。但是,如果触发了工作流,它将开始创建 Docker 映像,但在以下行中build-and-deploy-backend
失败:23
server/Dockerfile
22 | COPY ./src ./src
23 | >>> COPY ./tsconfig.json ./
见:https ://github.com/bennodev19/dronies-watch/runs/4813916640?check_suite_focus=true
出现此错误:
Dockerfile:23
--------------------
21 | # Move required app source into the working directory referenced with './'
22 | COPY ./src ./src
23 | >>> COPY ./tsconfig.json ./
24 |
25 | # For debugging:
--------------------
error: failed to solve: failed to compute cache key: "/tsconfig.json": not found
Error: buildx failed with: error: failed to solve: failed to compute cache key: "/tsconfig.json": not found
见:https ://github.com/bennodev19/dronies-watch/runs/4813916640?check_suite_focus=true
在本地它构建没有任何问题。MacOS
在和上测试Windows 10
。
build-and-deploy-backend
# *
jobs:
build-and-deploy-backend:
name: Build Backend Image for Prod & Push to Dockerhub
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker Image to DockerHub
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: server/Dockerfile # Path to the Dockerfile from which to build the Docker Image from (default {context}/Dockerfile)
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: latest
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
查看完整文件:https ://github.com/bennodev19/dronies-watch/blob/master/.github/workflows/release.yaml
server/Dockerfile
FROM node:lts-alpine
RUN mkdir -p /app
WORKDIR /app
COPY package.json ./
COPY yarn.lock ./
RUN yarn install
COPY src ./src
COPY tsconfig.json ./
RUN yarn build
CMD [ "yarn", "start" ]
EXPOSE 5000
查看完整文件:https ://github.com/bennodev19/dronies-watch/blob/master/server/Dockerfile