dockergithub-actionsbuilding-github-actions

Error: buildx failed with: ERROR: invalid tag "***/e2bdy:": invalid reference format


I'm using github action to build&push docker image, but it failed with err.

errors screenshots

buildx failed with: ERROR: invalid tag "***/e2bdy:": invalid reference format

Is there anything wrong with my action.yml ? Local build is successful.

name: e2bdy docker
on:
  workflow_dispatch:
  push:
    branches:
      - main
    paths:
      - version.py
      - .github/workflows/build.yml
      - requirements.txt
      - dockerfile

jobs:
  build:
    runs-on: ubuntu-latest
    name: Build Docker Image
    steps:
      - name: Checkout
        uses: actions/checkout@main

      - name: Release version
        id: release_version
        run: |
          app_version=$(cat version.py |sed -ne "s/APP_VERSION\s=\s'v\(.*\)'/\1/gp")
          echo "app_version=$app_version" >> $GITHUB_ENV
      - name: Set Up QEMU
        uses: docker/setup-qemu-action@v1

      - name: Set Up Buildx
        uses: docker/setup-buildx-action@v1

      - name: Login DockerHub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Build Image
        uses: docker/build-push-action@v2
        with:
          context: docker
          file: dockerfile
          build-args: |
            GITHUB_TOKEN=${{ secrets.RELEASE_TOKEN }}
          platforms: |
            linux/amd64
            linux/arm64
          push: true
          tags: |
            musnows/e2bdy:latest
            musnows/e2bdy:${{ env.app_version }}

dockerfile

FROM python:3.11.2
COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

ENV LANG="C.UTF-8" \
    TZ="Asia/Shanghai" \
    PGID=0 \
    PUID=0 \
    BDY_SECRET_KEY="" \
    BDY_APP_KEY="" \
    BDY_APP_NAME="e2bdy" \
    ENCRYPT_UPLOAD=1 \
    SYNC_INTERVAL=600

WORKDIR /app

COPY . /app/
COPY ./config /app/config

VOLUME [ "/app/config" ]

CMD [ "python","main.py" ]

github repo:https://github.com/musnows/encrypt2bdy/tree/main

At first,I used ${{ secrets.DOCKER_USERNAME }}/e2bdy:latest for image name, it failed with this err.So I tryed to use my username instead of action secrets,but it still failed in build docker image


Solution

  • this yaml works

    name: Docker Image CI
    #触发器设置
    on:
      push:
        branches: [ "main" ]
      pull_request:
        branches: [ "main" ]
    
    #项目任务,任务之间可以并行调度
    jobs:
      build:
      #选择云端运行的环境
        runs-on: ubuntu-latest
        steps:
        #uses代表使用一个模块,此处使用的是checkout模块,将github项目文件导入到当前环境中
        - uses: actions/checkout@v3
        #使用with跟在后面来为前面的模块输入参数
          with:
            submodules: 'true'
        - name: Set up QEMU
          uses: docker/setup-qemu-action@v2
        - name: Set up Docker Buildx
          uses: docker/setup-buildx-action@v2
        - name: Login to DockerHub
          uses: docker/login-action@v2
          with:
         # 这里用到了github的secrets功能,避免账户和密码随仓库泄露
           username: ${{ secrets.DOCKER_USERNAME }}
           password: ${{ secrets.DOCKER_TOKEN }}
        - name: Build and push
          # 导入这个模块来完成自动编译和推送
          uses: docker/build-push-action@v3
          with:
              context: .
              push: true
              #在这里通过加入需要编译的平台和前面配好的QEMU,buildx来达到多平台编译
              platforms: linux/amd64,linux/arm64,linux/arm
              #指定用户/仓库名
              tags: musnows/e2bdy:latest
        - name: Docker Hub Description
          # 这里是通过md文件自动生成dockerhub描述的模块,也可以不需要
          uses: peter-evans/dockerhub-description@v3
          with:
            username: ${{ secrets.DOCKER_USERNAME }}
            password: ${{ secrets.DOCKER_PASSWORD }}
            repository: musnows/e2bdy
            readme-filepath: ./README.md
    

    The old one fiailed because I didn't set version.py correctly

    # the right one
    APP_VERSION = 'v0.1.0'
    # err!
    APP_VERSION = '0.1.0'
    

    Now I'm using this yaml,which cloud push docker images with latest & version in version.py

    name: Docker Image CI
    #触发器设置
    on:
      push:
        branches: [ "main" ]
      pull_request:
        branches: [ "main" ]
    
    # 项目任务,任务之间可以并行调度
    jobs:
      build:
      # 选择云端运行的环境
        runs-on: ubuntu-latest
        steps:
        #u ses代表使用一个模块,此处使用的是checkout模块,将github项目文件导入到当前环境中
        - uses: actions/checkout@v3
        # 使用with跟在后面来为前面的模块输入参数
          with:
            submodules: 'true'
        - name: Set up QEMU
          uses: docker/setup-qemu-action@v2
        - name: Set up Docker Buildx
          uses: docker/setup-buildx-action@v2
        - name: Login to DockerHub
          uses: docker/login-action@v2
          with:
        # 这里用到了github的secrets功能,避免账户和密码随仓库泄露
           username: ${{ secrets.DOCKER_USERNAME }}
           password: ${{ secrets.DOCKER_TOKEN }}
        # 设置当前的发行版本tag
        - name: Release version
          id: release_version
          run: |
            app_version=$(cat version.py |sed -ne "s/APP_VERSION\s=\s'v\(.*\)'/\1/gp")
            echo "app_version=$app_version" >> $GITHUB_ENV
        # 开始构建镜像
        - name: Build and push
          uses: docker/build-push-action@v2
          with:
            context: .
            file: dockerfile
            build-args: |
              GITHUB_TOKEN=${{ secrets.RELEASE_TOKEN }}
            platforms: |
              linux/amd64
              linux/arm64
              linux/arm
            push: true
            # 指定用户/仓库名
            tags: |
              ${{ secrets.DOCKER_USERNAME }}/e2bdy:latest
              ${{ secrets.DOCKER_USERNAME }}/e2bdy:${{ env.app_version }}
        # 这里是通过md文件自动生成dockerhub描述的模块,也可以不需要
        - name: Docker Hub Description
          uses: peter-evans/dockerhub-description@v3
          with:
            username: ${{ secrets.DOCKER_USERNAME }}
            password: ${{ secrets.DOCKER_PASSWORD }}
            repository: musnows/e2bdy
            readme-filepath: ./README.md