11

使用GitHub Action构建全平台docker镜像

 2 years ago
source link: https://vps.la/2021/10/03/%e4%bd%bf%e7%94%a8github-action%e6%9e%84%e5%bb%ba%e5%85%a8%e5%b9%b3%e5%8f%b0docker%e9%95%9c%e5%83%8f/
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构建全平台docker镜像

使用GitHub Action构建全平台docker镜像

GitHub Action这个工具实在是太方便了,不仅速度快,配置简单,还能够方便的在没有真机的情况下制作全平台的docker image

GitHub Action的前期配置请参考我这篇博客: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/

我选用的是https://github.com/ilteoood/docker_buildx 的workflow,可以非常方便的配置各项参数

下面以我的这个配置文件举例

Code example

name: Build Amd64 Image
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
name: Build image job
steps:
- name: Checkout master
uses: actions/checkout@master
- name: Build and publish image
uses: ilteoood/docker_buildx@master
with:
publish: true
imageName: 你的docker id/你的镜像名
platform: linux/amd64,linux/arm64,linux/arm/v7 # 你准备构建的镜像平台
tag: latest # 默认latest,可以针对平台,修改tag
dockerHubUser: ${{ secrets.DOCKER_USERNAME }} # docker hub userid
dockerHubPassword: ${{ secrets.DOCKER_PASSWORD }} # docker hub password

platform支持:linux/amd64,linux/arm64,linux/arm/v7

crazy-max/ghaction-docker-buildx

再举例一个比较复杂的,crazy-max/ghaction-docker-buildx的workflow比较复杂,使用这个的一般都是大项目,参数很多,大家可以参照我上面的内容来理解

Code example

name: Build Image
on:
push:
branches:
- 'master'
paths-ignore:
- "README.md"
jobs:
buildx:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Dockerhub login
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin
- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
buildx-version: latest
- name: Build dockerfile (with push)
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
docker buildx build
--platform=linux/amd64,linux/arm/v7,linux/arm64
--output "type=image,push=true"
--file ./Dockerfile .
--tag superng6/aria2:latest

推送到Docker HUB之后的效果图

使用GitHub Action构建全平台docker镜像
使用GitHub Action构建全平台docker镜像

本教程是针对有一定编程能力的人,需要注意的是,底层镜像必须是多平台的才可以,还有你的代码和库也必须是对应平台的,所以我的建议是,针对不同平台创建不同分支,这样虽然麻烦,但是灵活性更高

使用GitHub Action构建全平台docker镜像
原文链接:https://sleele.com/2020/01/10/%E4%BD%BF%E7%94%A8github-action%E6%9E%84%E5%BB%BA%E5%85%A8%E5%B9%B3%E5%8F%B0docker%E9%95%9C%E5%83%8F/

未经允许不得转载:VPS啦 » 使用GitHub Action构建全平台docker镜像


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK