1
1
#! /usr/bin/env bash
2
2
set -e
3
3
4
+ # Build the sasl2 library with the sasl-xoauth2 plugin.
5
+ #
6
+ # The sasl-xoauth2 plugin is a SASL plugin that provides support for XOAUTH2 (OAuth 2.0) authentication.
7
+ #
8
+ # The build is done in /sasl-xoauth2/build.
9
+ #
10
+ # This script clones the sasl-xoauth2 repository, applies patches to:
11
+ # - remove the build of the documentation
12
+ # - fix the path to the python interpreter in the sasl-xoauth2-tool
13
+ # - fix the path to the library when building on Alpine
14
+ #
15
+ # After building and installing the sasl2 library with the sasl-xoauth2 plugin, the
16
+ # postfix-sasl-xoauth2-update-ca-certs script is installed into the /etc/ca-certificates/update.d directory.
17
+ # This script is run by the update-ca-certificates command to update the list of trusted certificates.
4
18
build_sasl2 () {
5
19
git clone --depth 1 --branch ${SASL_XOAUTH2_GIT_REF} ${SASL_XOAUTH2_REPO_URL} /sasl-xoauth2
6
20
cd /sasl-xoauth2
@@ -27,27 +41,60 @@ build_sasl2() {
27
41
update-ca-certificates
28
42
}
29
43
44
+ # Installs rust. Debian bookwork comes with an old version of rust, so we can't use the one from the repository.
45
+ # Rust is needed, though for installation of msal library. On some architectures, we cannot use pre-compiled packages
46
+ # (because they don't exist in the PIP repositories) and "pip install" will fail without rust. Specifically, when
47
+ # compiling cryptographic libraries.
48
+ setup_rust () {
49
+ curl --proto ' =https' --tlsv1.3 https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal
50
+ export PATH=" $HOME /.cargo/bin:$PATH "
51
+ }
52
+
53
+ # Create a virtual environment and install the msal library for the
54
+ # sasl-xoauth2-tool.
30
55
setup_python_venv () {
31
56
python3 -m venv /sasl
32
57
. /sasl/bin/activate
33
58
pip3 install msal
34
59
}
35
60
61
+ # Installs the base components into the docker image:
62
+ #
63
+ # 1. sasl2 using the sasl-xoauth2 plugin
64
+ # 2. a python virtual environment with the msal library
65
+ base_install () {
66
+ setup_rust
67
+ build_sasl2
68
+ setup_python_venv
69
+ rustup self uninstall
70
+ }
71
+
72
+
36
73
[ -f /etc/lsb-release ] && . /etc/lsb-release
37
74
[ -f /etc/os-release ] && . /etc/os-release
75
+
76
+ # Determine the base installation method based on the OS.
77
+ # Alpine Linux has a different package management system than Debian-based systems.
38
78
if [ -f /etc/alpine-release ]; then
39
- LIBS=" git cmake clang make gcc g++ libc-dev pkgconfig curl-dev jsoncpp-dev cyrus-sasl-dev patch rust cargo libffi-dev python3-dev"
79
+ # Install necessary libraries
80
+ LIBS=" git cmake clang make gcc g++ libc-dev pkgconfig curl-dev jsoncpp-dev cyrus-sasl-dev patch libffi-dev python3-dev"
40
81
apk add --upgrade --virtual .build-deps ${LIBS}
41
- build_sasl2
42
- setup_python_venv
82
+
83
+ # Run compilation and installation
84
+ base_install
85
+
86
+ # Cleanup. This is important to ensure that we don't keep unnecessary files laying around and thus increasing the size of the image.
43
87
apk del .build-deps;
44
88
else
89
+ # Install necessary libraries
45
90
apt-get update -y -qq
46
- LIBS=" git build-essential cmake pkg-config libcurl4-openssl-dev libssl-dev libjsoncpp-dev libsasl2-dev rustc cargo rustfmt python3-dev"
91
+ LIBS=" git build-essential cmake pkg-config libcurl4-openssl-dev libssl-dev libjsoncpp-dev libsasl2-dev python3-dev"
47
92
apt-get install -y --no-install-recommends ${LIBS}
48
- build_sasl2
49
- apt-get install -y --no-install-recommends python3-venv
50
- setup_python_venv
93
+
94
+ # Run compilation and installation
95
+ base_install
96
+
97
+ # Cleanup. This is important to ensure that we don't keep unnecessary files laying around and thus increasing the size of the image.
51
98
apt-get remove --purge -y ${LIBS} python3-venv
52
99
apt-get autoremove --yes
53
100
apt-get clean autoclean
0 commit comments