-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
create_dev_image.sh
executable file
·102 lines (87 loc) · 3.14 KB
/
create_dev_image.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
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
#!/usr/bin/env bash
###############################################################
#
# Copyright (C) 2023 James Fuller, <[email protected]>, et al.
#
# SPDX-License-Identifier: curl-container
###############################################################
#
# Create a dev image
# ex.
# > create_dev_image.sh {arch} {base image} {compiler} {deps} {build_opts} {branch or tag} {resultant_image_name} {run_tests}
#
#
echo "####### creating curl dev image."
# get invoke opts
platform=${1}
dist=${2}
compiler_deps=${3}
deps=${4}
build_opts=${5}
branch_or_tag=${6}
image_name=${7}
run_tests=${8}
# set base and platform
if [[ -n $platform ]]; then
echo "creating with platform=${platform}"
bdr=$(buildah --platform ${platform} from ${dist})
else
echo "creating ..."
bdr=$(buildah from ${dist})
fi
# label/env
buildah config --label maintainer="James Fuller <[email protected]>" $bdr
buildah config --label name="${image_name}" $bdr
# determine dist package manager
if [[ "$dist" =~ .*"alpine".* ]]; then
package_manage_update="apk upgrade"
package_manage_add="apk add "
fi
if [[ "$dist" =~ .*"fedora".* ]]; then
package_manage_update="dnf update upgrade"
package_manage_add="dnf -y install"
fi
if [[ "$dist" =~ .*"debian".* ]]; then
package_manage_update="apt-get update"
package_manage_add="apt-get -y install "
fi
# install deps using specific dist package manager
buildah run $bdr ${package_manage_update}
buildah run $bdr ${package_manage_add} ${deps}
# setup curl source derived from branch or tag
echo "get curl source"
buildah run $bdr mkdir /src
if [ "${branch_or_tag:0:4}" = "curl" ]; then
# its a tag, retrieve release source
buildah run $bdr /usr/bin/curl -L -o curl.tar.gz "https://github.com/curl/curl/releases/download/${branch_or_tag}/curl-${release_tag}.tar.gz"
buildah run $bdr tar -xvf curl.tar.gz
buildah run $bdr rm curl.tar.gz
buildah run $bdr mv curl-${release_tag} /src/curl-${release_tag}
buildah config --workingdir /src/curl-${release_tag} $bdr
else
# its a branch, retrieve archive source
buildah run $bdr /usr/bin/curl -L -o curl.tar.gz https://github.com/curl/curl/archive/refs/heads/${branch_or_tag}.tar.gz
buildah run $bdr tar -xvf curl.tar.gz
buildah run $bdr rm curl.tar.gz
buildah run $bdr mv curl-${branch_or_tag} /src/curl-${branch_or_tag}
buildah config --workingdir /src/curl-${branch_or_tag} $bdr
fi
# build curl
buildah run $bdr autoreconf -fi
buildah run $bdr ./configure ${build_opts}
buildah run $bdr make -j$(nproc)
# run tests
if [[ $run_tests -eq 1 ]]; then
buildah run $bdr make test
fi
# install curl in /build
buildah run $bdr make DESTDIR="/build/" install -j$(nproc)
# install useful dev deps¡
buildah run $bdr python3 -m ensurepip
#buildah run $bdr pip3 --no-input install -r ./requirements.txt
# label image
buildah config --label org.opencontainers.image.source="https://github.com/curl/curl-container" $bdr
buildah config --label org.opencontainers.image.description="minimal dev image for curl" $bdr
buildah config --label org.opencontainers.image.licenses="MIT" $bdr
# commit image
buildah commit $bdr "${image_name}" # --disable-compression false --squash --sign-by --tls-verify