我有一个GitHub操作,它需要向特定的组织发布一个Dockerfile。行动看起来是这样的:
name: Docker dataeng_github_metrics
# Run workflow on tags starting with v (eg. v2, v1.2.0)
on:
push:
branches: [ "master" ]
paths:
- ./data_pipelines/dataeng_github_metrics/*
pull_request:
branches: [ "master" ]
jobs:
Deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_REGISTRY_TOKEN }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
file: ./data_pipelines/dataeng_github_metrics/Dockerfile
push: true # Will only build if this is not here
tags: |
ghcr.io/mirantis/dataeng_github_metrics:latest问题是,当我在本地运行Dockerfile时,它可以工作,但是在这个特定的操作工作流上,它不能工作。相反,我得到以下信息:
ERROR: failed to solve: failed to compute cache key: "/go.sum" not found: not found
Error: buildx failed with: ERROR: failed to solve: failed to compute cache key: "/go.sum" not found: not found以及对Dockerfile的检查
###############
# CACHE IMAGE #
###############
ARG GO_IMAGE=golang:1.17.3-alpine3.14
ARG BASE_IMAGE=alpine:3.14.2
FROM ${GO_IMAGE} AS cache
# Add the keys
ARG GITHUB_ID
ENV GITHUB_ID=$GITHUB_ID
ARG GITHUB_TOKEN
ENV GITHUB_TOKEN=$GITHUB_TOKEN
# Install Git
RUN apk add git
# TODO: ENCRYPT THE GITHUB_ID AND GITHUB_TOKEN
# Make Git Configuration
RUN git config \
--global \
url."https://${GITHUB_ID}:${GITHUB_TOKEN}@github.com/".insteadOf \
"https://github.com/"
WORKDIR /bin
COPY go.mod go.sum /bin/
RUN go mod download
##############
# BASE IMAGE #
##############
FROM cache AS dataeng_github_metrics
COPY . /bin
WORKDIR /bin
# Setup Git Terminal Prompt & Go Build
RUN go build .
###############
# FINAL IMAGE #
###############
FROM ${BASE_IMAGE}
COPY --from=dataeng_github_metrics /bin/dataeng_github_metrics bin/
ENTRYPOINT [ "bin/dataeng_github_metrics" ]它在以下几个方面失败:
COPY go.mod go.sum /bin/这是本地构建的,所以我不明白问题是什么。

发布于 2022-11-10 18:18:55
因此,为了通过它,我必须为GitHub操作将完整的路径添加到我的上下文中,我还有另外一个问题,但它目前与路径上下文无关,并且无法找到文件:
通过添加以下行,我能够通过指定上下文路径来修复它:
context: ./data_pipelines/dataeng_github_metrics/name: Docker dataeng_github_metrics
# Run workflow on tags starting with v (eg. v2, v1.2.0)
on:
push:
branches: [ "master" ]
paths:
- ./data_pipelines/dataeng_github_metrics/*
pull_request:
branches: [ "master" ]
jobs:
Deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_REGISTRY_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and Push Docker Image
uses: docker/build-push-action@v3
with:
context: ./data_pipelines/dataeng_github_metrics/
file: ./data_pipelines/dataeng_github_metrics/Dockerfile
push: true # Will only build if this is not here
tags: |
ghcr.io/mirantis/dataeng_github_metrics:latesthttps://stackoverflow.com/questions/74382648
复制相似问题