使用 Github 操作创建 Docker 容器不会更新 github 包中的包

Creating a Docker container using Github actions does not update package in github packages

以下 .github 工作流脚本不会更新部署在 Github 个包上的包。

每次部署后,我希望脚本更新部署的包。

这是我的部署脚本。有人可以告诉我如何修改它以便在每次部署后创建一个新包吗?

name: Continuous Integration and Delivery

on: [ push ]

env:
  WEB_IMAGE: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')/web
  NGINX_IMAGE: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')/nginx

jobs:

  build:
    name: Build Docker Images
    runs-on: ubuntu-latest
    steps:
      - name: Log in to GitHub Packages
        run: echo ${PERSONAL_ACCESS_TOKEN} | docker login ghcr.io -u ${{ secrets.NAMESPACE }} --password-stdin
        env:
          PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
      - name: Build images
        run: |
          docker-compose down -v
          docker-compose -f docker-compose.ci.yml build
      - name: Push images
        run: |
          docker push ${{ env.WEB_IMAGE }}
          docker push ${{ env.NGINX_IMAGE }}

github包只停留在初始推送时的原始时间,不更新包。并且经检查,代码改动是原来的,并没有改成新的。

在github个动作上,说明推送成功

这里是docker.ci

version: "3.8"

services:
  web:
    build:
      context: ./app
      dockerfile: Dockerfile.prod
    image: "${WEB_IMAGE}"
    command: gunicorn hello_django.wsgi:application --bind 0.0.0.0:8000
    volumes:
      - static_volume:/usr/src/app/staticfiles
      - media_volume:/usr/src/app/mediafiles
    expose:
      - 8000
    env_file: .env
  nginx:
    build:
      context: ./nginx
    image: "${NGINX_IMAGE}"
    volumes:
      - static_volume:/usr/src/app/staticfiles
      - media_volume:/usr/src/app/mediafiles
    ports:
      - 80:80
    depends_on:
      - web

volumes:
  static_volume:
  media_volume:

问题是 docker 标签没有包含在推送中。我在推送上添加了标签,它是固定的。

以下内容不够,您还必须将标签添加到推送中,否则github 存储库由于某种原因不会更新它。

  - name: Push images
    run: |
      docker push ${{ env.WEB_IMAGE }}
      docker push ${{ env.NGINX_IMAGE }}

您必须执行以下操作

  - name: Push images
    run: |
      docker tag ${{ env.WEB_IMAGE }}  ${{ env.WEB_IMAGE_BASE }}:latest
      docker push ${{ env.WEB_IMAGE }}
      docker push ${{ env.WEB_IMAGE_BASE }}:latest
      docker tag ${{ env.NGINX_IMAGE }} ${{ env.NGINX_IMAGE_BASE }}:latest
      docker push ${{ env.NGINX_IMAGE }}
      docker push ${{ env.NGINX_IMAGE_BASE }}:latest