6

使用GitHub Action构建image&推送docker hub

 2 years ago
source link: https://vps.la/2021/10/03/%e4%bd%bf%e7%94%a8github-action%e6%9e%84%e5%bb%baimage%e6%8e%a8%e9%80%81docker-hub/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
使用GitHub Action构建image&推送docker hub

docker hub自带链接GitHub仓库功能,提交更改会自动构建docker image,那么为什么还要用GitHub Action来构建?原因如下,docker hub构建镜像速度很慢,简单一点的镜像,构建的速度还能接受,复杂一点的,比如说需要编译程序,那速度就很捉急了,这时候就需要用到GitHub Action,速度翻个3倍还是能做到的,其二:docker hub的自动构建是每一条推送修改都会构建,意味着即使只修改readme,它也会再build,因为队列排队的缘故,真正修改好,需要用的时候,那个镜像还再排队等着构建,这就很难让人接受了,并且这样很浪费docker hub的资源,GitHub Action在这方面就的可自定义能力就强很多了

在仓库中开启GitHub Action功能

使用GitHub Action构建image&推送docker hub

之后所在仓库会出现一个yml,路径是/.github/workflows/

使用GitHub Action构建image&推送docker hub

这里我用的是https://github.com/elgohr/Publish-Docker-Github-Action 的yml

把下面这段代码复制进这个yml,并重命名为Publish Docker.yml

Code example

name: Publish Docker
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: superng6/test
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tag_names: true
cache: true

部分名词解释:on,条件判断,判断是何种情况开始执行流程,常用的有push,release,我推荐release

name:这个job的名字,我这个job是构建镜像并推送

uses:这个是yml编写者的名字和流程名,我这里选用的是elgohr/Publish-Docker-Github-Action@master,简单易用,文档也写的非常翔实

后面with这个,name就不说了,你的dockerhub id和你的docker镜像名,我相信都能看懂

cache:加快构建速度,如果镜像不复杂不需要编译的话可以不用

tag_names:依据分支名称推送,master分支默认latest,其他分支按照分支名称命名并推送

着重说一下最后两个参数

username:dockerhub id

password:dockerhub password

需要在GitHub这个项目的所在仓库创建secrets

使用GitHub Action构建image&推送docker hub
使用GitHub Action构建image&推送docker hub

在这里手动添加KV

使用GitHub Action构建image&推送docker hub
使用GitHub Action构建image&推送docker hub

如果你的仓库已经准备好开始构建镜像了,就点击release,之后会自动构建并推送到docker hub上

原本在dockerhub需要90分钟才能构建完成的镜像,在GitHub Action中只需要30分钟(编译qBittorrent-Enhanced-Edition

使用GitHub Action构建image&推送docker hub
原文链接:https://sleele.com/2020/01/06/%E4%BD%BF%E7%94%A8github-action%E6%9E%84%E5%BB%BAimage%E6%8E%A8%E9%80%81docker-hub/

未经允许不得转载:VPS啦 » 使用GitHub Action构建image&推送docker hub


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK