forked from curl/curl-container
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_dev_image.sh
More file actions
executable file
·162 lines (141 loc) · 5.54 KB
/
create_dev_image.sh
File metadata and controls
executable file
·162 lines (141 loc) · 5.54 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
158
159
160
161
#!/usr/bin/env bash
###############################################################
#
# Copyright (C) 2023 James Fuller, <jim@webcomposite.com>, 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})
# *** Allowing the image to be built for multiple platforms ***
# 1 - Extracting the part before the colon
image_name_without_tag="${image_name%%:*}"
# 2- Extracting the part after the colon
image_tag="${image_name#*:}"
# 3- Constructing the new image name
image_name="${image_name_without_tag}-$(echo ${platform} | tr / -):${image_tag}"
else
echo "creating ..."
bdr=$(buildah from ${dist})
fi
# label/env
buildah config --label maintainer="James Fuller <jim.fuller@webcomposite.com>" $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 "
package_manager_remove="apt-get -y remove "
package_manager_clean="apt-get -y clean"
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
# Install quictls, nghttp3, ngtcp2
# See: https://curl.se/docs/http3.html
if [[ "$dist" =~ .*"debian".* ]]; then
# build quictls
buildah config --workingdir /src/ $bdr
buildah run $bdr git clone --depth 1 -b openssl-3.1.4+quic https://github.com/quictls/openssl
buildah config --workingdir /src/openssl $bdr
buildah run $bdr ./config enable-tls1_3 --prefix=/usr/local --libdir=lib # it'll be installed in /usr/local/lib or it'll end up in /usr/local/lib64, which isn't in LD_LIBRARY_PATH
buildah run $bdr make -j$(nproc)
buildah run $bdr make install
buildah run $bdr make clean
# build nghttp3
buildah config --workingdir /src/ $bdr
buildah run $bdr git clone -b v1.1.0 https://github.com/ngtcp2/nghttp3
buildah config --workingdir /src/nghttp3 $bdr
buildah run $bdr git submodule update --init
buildah run $bdr autoreconf -fi
buildah run $bdr ./configure --prefix=/usr/local --enable-lib-only
buildah run $bdr make -j$(nproc)
buildah run $bdr make install
buildah run $bdr make clean
# build ngtcp2
buildah config --workingdir /src/ $bdr
buildah run $bdr git clone -b v1.2.0 https://github.com/ngtcp2/ngtcp2
buildah config --workingdir /src/ngtcp2 $bdr
buildah run $bdr autoreconf -fi
buildah run $bdr ./configure PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig LDFLAGS="-Wl,-rpath,/usr/local/lib" --prefix=/usr/local --enable-lib-only
buildah run $bdr make -j$(nproc)
buildah run $bdr make install
buildah run $bdr make clean
buildah config --workingdir / $bdr
fi
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 --env "LDFLAGS=-Wl,-rpath,/usr/local/lib" $bdr ./configure ${build_opts}
buildah run $bdr make -j$(nproc)
# clean curl
buildah run $bdr make clean -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 curl in /usr/local
buildah run $bdr make install -j$(nproc)
# set cwd to /
buildah config --workingdir / $bdr
# delete source code
buildah run $bdr rm -rf /src
# delete distro-packaged curl
buildah run $bdr ${package_manager_remove} "curl"
buildah run $bdr ${package_manager_remove} "libcurl4"
# clean downloaded packages
buildah run $bdr ${package_manager_clean}
# 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