【发布时间】:2022-11-11 02:18:55
【问题描述】:
我有一个 GitHub Action 需要将 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/
这是在本地构建的,所以我不明白问题是什么。
【问题讨论】:
-
您可能需要设置一个特定的语境或更改您的文件路径,但没有minimal reproducible example,这只是猜测。
-
我很困惑,即使我只是做
COPY go.mod .,它也可以与 docker-compose 一起使用,但不能与 dockerfile build 一起使用,它不会在 docker build 中使用 -
go.mod文件在您的项目中位于何处?您是否尝试将context: .参数添加到构建操作中? -
go.* 文件与 Dockerfile 处于同一级别,我确实尝试添加 context 。这似乎并没有让我过去。
标签: docker github dockerfile github-actions