-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
49 lines (37 loc) · 1.23 KB
/
build.sh
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
#!/bin/bash
base_dir=$(cd $(dirname $0);pwd)
sub_command=$1
base_version=$2
build_number=$3
if [ "${sub_command}" != "push" ] && [ "${sub_command}" != "build" ] ; then
echo "Sub command is push or build."
exit 1
fi
if [ "${base_version}" = "" ] || [ "${build_number}" = "" ] ; then
echo "Command arguments are x.x.x x"
exit 1
fi
h2o_version=${base_version}.${build_number}
build_image_tag=ghcr.io/codelibs/h2o-build:${h2o_version}
image_tag=ghcr.io/codelibs/h2o:${h2o_version}
dist_dir=${base_dir}/dist
src_path=/build/h2o-3/build/h2o.jar
dist_path=${dist_dir}/h2o.jar
rm -rf ${dist_dir}
echo "Building ${build_image_tag}"
docker build --rm -t ${build_image_tag} --build-arg GIT_BRANCH=jenkins-${h2o_version} --build-arg BUILD_NUMBER=${build_number} -f Dockerfile.build .
mkdir -p ${dist_dir}
container_id=$(docker create "$build_image_tag")
docker cp "$container_id:$src_path" "$dist_path"
docker rm "$container_id"
if [[ ! -f ${dist_path} ]] ; then
echo "${dist_path} does not exist."
exit 1
fi
if [ "${sub_command}" = "build" ] ; then
echo "Building ${image_tag}"
docker build --rm -t ${image_tag} .
else
echo "Pushing ${image_tag}"
docker buildx build --rm --platform linux/amd64,linux/arm64 -t ${image_tag} --push .
fi