我一直在努力使用Github操作自动构建我的Dockerfile(位于子目录中)。
我的目录结构如下:
app
├── .github
│ ├── workflows
│ │ └── build.yml
├── encoding
│ ├── encoder.py
│ └── Dockerfile
├── database
│ └── Dockerfile
├── db
└── <data>
[...]
├── poetry.lock
├── pyproject.toml
├── LICENSE
└── README.md
我的build.yml
如下所示(出于限制目的,仅包括encoding
步骤的构建):
name: Build
on:
push:
branches: [ main ]
defaults:
run:
shell: bash
jobs:
encoding_build:
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to private Docker registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Build Docker image
uses: docker/build-push-action@v2
with:
context: ../../../encoding
dockerfile: ./encoding/Dockerfile
push: true
tags: <username>/<project_name>:<tag>
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
我的Dockerfile如下所示:
FROM python:3.8
WORKDIR /app/
ADD ./pyproject.toml /tmp/
ADD ./poetry.lock /tmp/
RUN cp /tmp/pyproject.toml /tmp/poetry.lock /app/
RUN pip install poetry
RUN poetry config virtualenvs.create false && poetry install --no-root --no-dev -vvv
COPY encoder.py /app/
WORKDIR /app/
CMD ["python", "encoder.py", "--input_file", "/app/input.txt", "--output_file", "/app/output.txt", "--model_name_or_path", "bert-base-uncased"]
我已经检查了this SO question,并根据vivekyad 4v和Sal Borrelli的答案创建了上下文和dockerfile参数;但是自动构建似乎不起作用。当我将任何更改推送到我的存储库时,我得到了以下错误:
Error: buildx failed with: ERROR: unable to prepare context: path "../../../encoding" not found
如果有人能帮助我解决我的错误,我将非常感激。此外,任何额外的Docker或Github行动相关的评论是受欢迎的!
1条答案
按热度按时间rxztt3cl1#
嘿,你的上下文路径是不正确的,我相信。
你能不能试试这样的:
当前工作目录应该已经是/app
并且
build.yml
中的context
与dockerfile
一样,将使用当前工作目录进行解析