Skip to content

Commit 8c49758

Browse files
committed
add github actions to build cabot-driver image with tags
Signed-off-by: Daisuke Sato <[email protected]>
1 parent 90b2067 commit 8c49758

File tree

3 files changed

+101
-6
lines changed

3 files changed

+101
-6
lines changed

.github/workflows/build.yaml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Test Building Docker Image and Workspace
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
platform:
7+
required: true
8+
type: string
9+
secrets:
10+
dockerhub-token:
11+
required: true
12+
13+
jobs:
14+
reusable_workflow_job:
15+
runs-on: ubuntu-20.04
16+
steps:
17+
- name: Maximize build space
18+
run: |
19+
sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android
20+
sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET
21+
sudo rm -rf /opt/ghc
22+
echo "Available storage:"
23+
df -h
24+
25+
- uses: actions/checkout@v4
26+
27+
- uses: docker/setup-qemu-action@v3
28+
29+
- name: Install vcs
30+
run: pip3 install vcstool
31+
32+
- name: Prepare thirdparty repos
33+
run: ./setup-dependency.sh
34+
35+
- name: Buildx bake
36+
shell: bash
37+
run: |
38+
docker login -u daisukesato80 -p "${{ secrets.dockerhub-token }}"
39+
./bake-docker.sh -P ${{ inputs.platform }}

.github/workflows/push_action.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Test Building Docker Image and Workspace
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-20.04
11+
steps:
12+
- name: Maximize build space
13+
run: |
14+
sudo rm -rf /usr/local/lib/android # will release about 10 GB if you don't need Android
15+
sudo rm -rf /usr/share/dotnet # will release about 20GB if you don't need .NET
16+
sudo rm -rf /opt/ghc
17+
echo "Available storage:"
18+
df -h
19+
20+
- uses: actions/checkout@v4
21+
22+
- uses: docker/setup-qemu-action@v3
23+
24+
- name: Install vcs
25+
run: pip3 install vcstool
26+
27+
- name: Prepare thirdparty repos
28+
run: ./setup-dependency.sh
29+
30+
- name: Get branch name
31+
id: get_branch
32+
run: echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
33+
34+
- name: Buildx bake
35+
shell: bash
36+
run: |
37+
docker login -u daisukesato80 -p "${{ secrets.DOCKERHUB_TOKEN }}"
38+
./bake-docker.sh -t "latest,${{ env.BRANCH_NAME }}"

bake-docker.sh

+24-6
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ function help {
3636
echo "-l build using local registry"
3737
echo "-P <platform> specify platform"
3838
echo " build linux/arm64 and linux/amd64 if not specified"
39+
echo "-t <tags> additional tags"
3940
}
4041

4142
platform=
4243
base_name=cabot-base
44+
image_name=cabot-driver
4345
local=0
46+
tags=
4447

45-
while getopts "hb:ilP:" arg; do
48+
while getopts "hb:ilP:t:" arg; do
4649
case $arg in
4750
h)
4851
help
@@ -65,6 +68,9 @@ while getopts "hb:ilP:" arg; do
6568
P)
6669
platform=${OPTARG}
6770
;;
71+
t)
72+
tags=${OPTARG}
73+
;;
6874
esac
6975
done
7076
shift $((OPTIND-1))
@@ -88,6 +94,8 @@ if [[ $local -eq 1 ]]; then
8894
-p 127.0.0.1:9092:5000 \
8995
registry:2.7
9096
fi
97+
else
98+
export REGISTRY=cmucal
9199
fi
92100

93101
# setup multiplatform builder
@@ -105,14 +113,24 @@ if [[ -z $(docker buildx ls | grep "mybuilder\*") ]]; then
105113
fi
106114
fi
107115

108-
# bake
109-
export BASE_IMAGE=$base_name
116+
# tag option
117+
tag_option=""
118+
IFS=',' read -r -a tag_array <<< "$tags"
119+
tag_option="--set driver.tags='["
120+
for tag in "${tag_array[@]}"; do
121+
tag_option+="\"${REGISTRY}/${image_name}:${tag}\","
122+
done
123+
tag_option="${tag_option%,}]'"
124+
125+
# platform option
126+
platform_option=
110127
if [[ -n $platform ]]; then
111-
com="docker buildx bake -f docker-compose.yaml --set *.platform=\"$platform\" driver $@"
112-
else
113-
com="docker buildx bake -f docker-compose.yaml driver $@"
128+
platform_option="--set *.platform=\"$platform\""
114129
fi
115130

131+
# bake
132+
com="docker buildx bake -f docker-compose.yaml $platform_option $tag_option driver $@"
133+
export BASE_IMAGE=$base_name
116134
echo $com
117135
eval $com
118136

0 commit comments

Comments
 (0)