原文:https://docs.docker.com/ci-cd/github-actions/

可以直接fork这个项目 (opens new window)练习 这里假设你已有docker hub账号,先登录,进到https://hub.docker.com/settings/security生成access token,注意好记好。 然后打开Github到Settings > Secrets > New secret添加两条记录:

  • 键名:DOCKER_HUB_USERNAME,值是Docker hub的用户名
  • 键名:DOCKER_HUB_ACCESS_TOKEN,值是刚才复制的access token,值类似c292155d-1bd7-xxxx-xxxx-4da75bedb178

关于参见 buildx (opens new window) 修改.github/workflows/main.yml文件

name: CI to Docker Hub 

on:
  push:
        branches: [ master ]
   # tags:
   #   - "v*.*.*"

jobs:

  build:
    runs-on: ubuntu-latest
    steps:
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      -
        name: Login to DockerHub
        uses: docker/login-action@v1 
        with:
          username: ${{ secrets.DOCKER_HUB_USERNAME }}
          password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
      -
        name: Build and push
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: finleyma/simplewhale:latest
          build-args: |
            arg1=value1
            arg2=value2
      -
        name: Image digest
        run: echo ${{ steps.docker_build.outputs.digest }}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

# 参考

https://docs.docker.com/ci-cd/github-actions/ https://segmentfault.com/a/1190000021166703 https://github.com/docker/build-push-action

上次更新: 2022/5/17 11:31:39