-
Notifications
You must be signed in to change notification settings - Fork 259
157 lines (149 loc) · 5.56 KB
/
build_ckb_image.yml
File metadata and controls
157 lines (149 loc) · 5.56 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Build and Push CKB Docker Images
on:
push:
tags:
- 'v*'
permissions:
contents: read
packages: write
jobs:
validate-version:
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.validate.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate version format and tag existence
id: validate
run: |
VERSION=${{ github.ref_name }}
echo "version=$VERSION" >> $GITHUB_OUTPUT
if [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$ ]]; then
echo "Valid version format: $VERSION"
else
echo "Invalid version format: $VERSION. Must be like vX.Y.Z or vX.Y.Z-rcN."
exit 1
fi
if git rev-parse "refs/tags/$VERSION" >/dev/null 2>&1; then
echo "Git tag $VERSION exists"
else
echo "Error: Git tag $VERSION does not exist"
exit 1
fi
build-x86_64:
runs-on: ubuntu-22.04
needs: validate-version
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout specific tag
run: |
git checkout tags/${{ needs.validate-version.outputs.version }}
- name: Set up Docker
run: |
docker version
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push x86_64 image
run: |
docker build --progress=plain --no-cache -f docker/hub/Dockerfile -t nervos/ckb:x64-${{ needs.validate-version.outputs.version }} .
docker run --rm nervos/ckb:x64-${{ needs.validate-version.outputs.version }} --version
docker push nervos/ckb:x64-${{ needs.validate-version.outputs.version }}
build-aarch64:
runs-on: ubuntu-22.04-arm
needs: validate-version
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout specific tag
run: |
git checkout tags/${{ needs.validate-version.outputs.version }}
- name: Set up Docker
run: |
docker version
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push aarch64 image
run: |
docker build --progress=plain --no-cache -f docker/hub/Dockerfile-aarch64 -t nervos/ckb:aarch64-${{ needs.validate-version.outputs.version }} .
docker run --rm nervos/ckb:aarch64-${{ needs.validate-version.outputs.version }} --version
docker push nervos/ckb:aarch64-${{ needs.validate-version.outputs.version }}
create-manifest:
runs-on: ubuntu-22.04
needs: [build-x86_64, build-aarch64]
environment: docker-build
outputs:
version: ${{ steps.validate.outputs.version }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate version (for output)
id: validate
run: |
VERSION=${{ github.ref_name }}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create and push version manifest
run: |
docker manifest create nervos/ckb:${{ steps.validate.outputs.version }} \
--amend nervos/ckb:x64-${{ steps.validate.outputs.version }} \
--amend nervos/ckb:aarch64-${{ steps.validate.outputs.version }}
docker manifest push nervos/ckb:${{ steps.validate.outputs.version }}
- name: Create and push latest manifest (formal release)
if: contains(steps.validate.outputs.version, '-rc') == false
run: |
docker manifest create nervos/ckb:latest \
--amend nervos/ckb:x64-${{ steps.validate.outputs.version }} \
--amend nervos/ckb:aarch64-${{ steps.validate.outputs.version }}
docker manifest push nervos/ckb:latest
notify-discord:
runs-on: ubuntu-22.04
needs: create-manifest
if: always()
steps:
- name: Notify Discord on success
if: needs.create-manifest.result == 'success'
continue-on-error: true
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
title: "CKB Docker Build Succeeded"
description: "Successfully built and pushed CKB Docker images for tag ${{ needs.create-manifest.outputs.version }} to nervos/ckb. Triggered by ${{ github.actor }}."
color: 0x00ff00
- name: Notify Discord on failure
if: needs.create-manifest.result != 'success'
continue-on-error: true
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
title: "CKB Docker Build Failed"
description: "Failed to build or push CKB Docker images for tag ${{ needs.create-manifest.outputs.version }}. Check run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}."
color: 0xff0000