首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GitHub操作不向ghcr.io发布Dockerfile出了什么问题

GitHub操作不向ghcr.io发布Dockerfile出了什么问题
EN

Stack Overflow用户
提问于 2022-11-09 23:45:20
回答 1查看 39关注 0票数 1

我有一个GitHub操作,它需要向特定的组织发布一个Dockerfile。行动看起来是这样的:

代码语言:javascript
复制
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时,它可以工作,但是在这个特定的操作工作流上,它不能工作。相反,我得到以下信息:

代码语言:javascript
复制
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的检查

代码语言:javascript
复制
###############
# 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" ]

它在以下几个方面失败:

代码语言:javascript
复制
COPY go.mod go.sum /bin/

这是本地构建的,所以我不明白问题是什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-10 18:18:55

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

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

代码语言:javascript
复制
context: ./data_pipelines/dataeng_github_metrics/
代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74382648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档