GitHub Action制作镜像并推送到DockerHub

添加账号(设置当前仓库的秘密环境变量)

  • USERNAME:用户名
  • PASSWORD:密码

运行Action(设置仓库与镜像名)

  • 目标仓库,示例:wgp-2020/push_docker_image
  • 镜像名称,示例:username/demo:latest
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
name: Build and Push Docker Image
on:
workflow_dispatch: #手动触发工作流
inputs:
repository:
description: '目标仓库'
required: true
type: string
name:
description: '镜像名称'
required: true
type: string

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: 签出目标仓库
uses: actions/checkout@v3
with:
repository: ${{ inputs.repository }}

- name: 登录DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}

- name: 制作镜像并上传
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ inputs.name }}