我正在使用下面的工作流代码(在github文件中找到)来构建一个码头映像,并将其发布到。
name: Create and publish a Docker image
on:
push:
branches: ['release']
pull_request:
branches: ['release']
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}这是可行的,我现在看到在github回购的“包”下的公共码头形象。当我单击图像时,我被定向到一个github页面,其中包含关于该映像的更多信息(正式文档这里):“从命令行安装:”docker pull ghcr.io/OWNER/IMAGE_NAME:pr-75
及其文摘:sha256:04ea7757e34c4fae527bbe6fb56eb984f54543f2313775572f0817d696ecf48a
我想在同一个工作流中添加一个新作业,它使用ssh将映像拖到虚拟机上。
deploy:
- name: Deploy to Digital Ocean droplet via SSH action
uses: appleboy/ssh-action@v0.1.4
with:
host: ${{ secrets.DO_HOST }}
username: root
key: ${{ secrets.DO_PRIVATE_SSHKEY }}
port: 22
script: |
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}这在以下情况下失败:err: invalid reference format: repository name must be lowercase (仅降低限制是不够的,请继续阅读)。
当然,我不能硬编码docker pull ghcr.io/OWNER/IMAGE_NAME:pr-75或Digest,因为每个新分支都会增加它的PR号,所以pr-75标记会改变。
如何部署刚刚发布的映像?似乎我既可以使用标记值,也可以使用sha,如何实时检索这些值?
发布于 2022-06-16 12:45:48
在上面的工作流中有两个作业:
第一种方法使用码头/元数据-行动检索标签名ghcr.io/OWNER/IMAGE_NAME:pr-75,在下一步使用码头/建造-推进-行动时使用它来命名图像。
我只是在第二项工作中再次使用了坞/元数据操作:
deploy:
needs: build-and-push-image
runs-on: ubuntu-latest
steps:
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Deploy to Digital Ocean droplet via SSH action
uses: appleboy/ssh-action@v0.1.4
with:
host: ${{ secrets.DO_HOST }}
username: root
key: ${{ secrets.DO_PRIVATE_SSHKEY }}
port: 22
script: |
docker pull ${{ steps.meta.outputs.tags }}https://stackoverflow.com/questions/72645009
复制相似问题