【问题标题】:GitHub Action Is Not Publishing to ghcr.io What's Wrong with DockerfileGitHub Action 没有发布到 ghcr.io Dockerfile 出了什么问题
【发布时间】: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


【解决方案1】:

因此,为了克服它,我必须将完整路径添加到我的 GitHub Action 上下文中,我还有另一个问题,但它目前与路径上下文无关并且无法找到文件:

通过添加以下行,我可以通过指定上下文路径来修复它:

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:latest

【讨论】:

    猜你喜欢
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 2018-07-27
    • 1970-01-01
    • 2016-02-13
    • 2021-06-19
    • 2015-07-28
    • 2020-03-05
    相关资源
    最近更新 更多