Skip to content

Commit 9a795c9

Browse files
authored
Create docker-image.yml
1 parent 446aa17 commit 9a795c9

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

.github/workflows/docker-image.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
# 每次 push tag 时进行构建,不需要每次 push 都构建。使用通配符匹配每次 tag 的提交,记得 tag 名一定要以 v 开头
6+
tags:
7+
- v*
8+
9+
env:
10+
# 设置 docker 镜像名
11+
IMAGE_NAME: nginx-http-flv-module
12+
13+
jobs:
14+
# 运行测试,如果需要的话,将注释取消掉并且修改为自己需要的内容
15+
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
16+
# test:
17+
# runs-on: ubuntu-latest
18+
#
19+
# steps:
20+
# - uses: actions/checkout@v2
21+
#
22+
# - name: Run tests
23+
# run: |
24+
# if [ -f docker-compose.test.yml ]; then
25+
# docker-compose --file docker-compose.test.yml build
26+
# docker-compose --file docker-compose.test.yml run sut
27+
# else
28+
# docker build . --file Dockerfile
29+
# fi
30+
31+
# Push image to GitHub Packages.
32+
# See also https://docs.docker.com/docker-hub/builds/
33+
push:
34+
# 如果需要在构建前进行测试的话需要取消下面的注释和上面对应的 test 动作的注释。
35+
# needs: test
36+
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v2
40+
# 构建镜像,指定镜像名
41+
- name: Log into registry
42+
run: echo "${{ secrets.ACCESS_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
43+
44+
- name: Push image
45+
run: |
46+
# 拼接镜像 id,这个镜像 id 就是在使用 docker 镜像时 pull 后面的名字。
47+
IMAGE_ID=${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME
48+
49+
# 将所有的大写字母转为小写
50+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
51+
52+
# 从 GitHub.ref 中取出版本
53+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
54+
55+
# 从 tag 名字中替换 v 字符
56+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
57+
58+
# Use Docker `latest` tag convention
59+
[ "$VERSION" == "master" ] && VERSION=latest
60+
61+
echo IMAGE_ID=$IMAGE_ID
62+
echo VERSION=$VERSION
63+
64+
# 设置镜像 id 和版本号
65+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
66+
67+
# 如果VERSION不带ffmpeg,打包之前将Dockerfile中的ffmpeg替换为空
68+
if [[ $VERSION != *"ffmpeg"* ]]; then
69+
sed -i 's/ffmpeg//g' Dockerfile
70+
fi
71+
72+
# 创建一个多平台构建环境
73+
docker buildx create --name multi-platform --use --platform linux/amd64,linux/arm64 --driver docker-container
74+
# 进行 push
75+
docker buildx build --platform linux/arm64,linux/arm64/v8,linux/ppc64le,linux/amd64,linux/386 -t $IMAGE_ID:$VERSION . --push

0 commit comments

Comments
 (0)