-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuild_container.sh
More file actions
executable file
·146 lines (131 loc) · 5.33 KB
/
build_container.sh
File metadata and controls
executable file
·146 lines (131 loc) · 5.33 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
#!/bin/sh
VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'")
ENABLE_PYPI_BUILD=$1
STABLE_VERSION=$2
verify_package() {
local version=$1
local pip_index=$2
echo "Verifying package availability..."
for i in $(seq 1 30); do
if pip install --index-url $pip_index socketsecurity==$version; then
echo "Package $version is now available and installable"
pip uninstall -y socketsecurity
return 0
fi
echo "Attempt $i: Package not yet installable, waiting 20s... ($i/30)"
sleep 20
done
echo "Package verification failed after 30 attempts"
return 1
}
echo $VERSION
if [ -z $ENABLE_PYPI_BUILD ] || [ -z $STABLE_VERSION ]; then
echo "$0 pypi-build=<option> stable=<true|false|prod|test>"
echo "\tpypi-build: Options are prod, test, or local"
echo "\t - prod: Build and publish to production PyPI, then build Docker images"
echo "\t - test: Build and publish to test PyPI, then build Docker images"
echo "\t - local: Build Docker images only using existing PyPI package (specify prod or test via stable parameter)"
echo "\tstable: true/false/prod/test - Also tag as stable; for local builds:"
echo "\t - stable=prod: Use production PyPI package"
echo "\t - stable=test: Use test PyPI package"
echo "\t - stable=false: Use local development install (pip install -e .)"
exit
fi
if [ $ENABLE_PYPI_BUILD = "pypi-build=prod" ]; then
echo "Doing production build"
# if ! python -m build --wheel --sdist; then
# echo "Build failed"
# exit 1
# fi
#
# if ! twine upload dist/*$VERSION*; then
# echo "Upload to PyPI failed"
# exit 1
# fi
#
# if ! verify_package $VERSION "https://pypi.org/simple"; then
# echo "Failed to verify package on PyPI"
# exit 1
# fi
docker build --no-cache --build-arg CLI_VERSION=$VERSION --platform linux/amd64,linux/arm64 -t socketdev/cli:$VERSION . \
&& docker build --no-cache --build-arg CLI_VERSION=$VERSION --platform linux/amd64,linux/arm64 -t socketdev/cli:latest . \
&& docker push socketdev/cli:$VERSION \
&& docker push socketdev/cli:latest
fi
if [ $ENABLE_PYPI_BUILD = "pypi-build=test" ]; then
echo "Doing test build"
if ! python -m build --wheel --sdist; then
echo "Build failed"
exit 1
fi
if ! twine upload --repository testpypi dist/*$VERSION*; then
echo "Upload to TestPyPI failed"
exit 1
fi
if ! verify_package $VERSION "https://test.pypi.org/simple"; then
echo "Failed to verify package on TestPyPI"
exit 1
fi
docker build --no-cache \
--build-arg CLI_VERSION=$VERSION \
--build-arg PIP_INDEX_URL=https://test.pypi.org/simple \
--build-arg PIP_EXTRA_INDEX_URL=https://pypi.org/simple \
--platform linux/amd64,linux/arm64 \
-t socketdev/cli:$VERSION-test . \
&& docker build --no-cache \
--build-arg CLI_VERSION=$VERSION \
--build-arg PIP_INDEX_URL=https://test.pypi.org/simple \
--build-arg PIP_EXTRA_INDEX_URL=https://pypi.org/simple \
--platform linux/amd64,linux/arm64 \
-t socketdev/cli:test . \
&& docker push socketdev/cli:$VERSION-test \
&& docker push socketdev/cli:test
fi
if [ $STABLE_VERSION = "stable=true" ]; then
if [ $ENABLE_PYPI_BUILD = "pypi-build=enable" ]; then
if ! verify_package $VERSION "https://pypi.org/simple"; then
echo "Failed to verify package on PyPI"
exit 1
fi
fi
docker build --no-cache --build-arg CLI_VERSION=$VERSION --platform linux/amd64,linux/arm64 -t socketdev/cli:stable . \
&& docker push socketdev/cli:stable
fi
if [ $ENABLE_PYPI_BUILD = "pypi-build=local" ]; then
echo "Building local version without publishing to PyPI"
# Determine PyPI source based on stable parameter
if [ $STABLE_VERSION = "stable=prod" ]; then
echo "Using production PyPI"
PIP_INDEX_URL="https://pypi.org/simple"
PIP_EXTRA_INDEX_URL="https://pypi.org/simple"
TAG_SUFFIX="local"
USE_LOCAL_INSTALL="false"
elif [ $STABLE_VERSION = "stable=test" ]; then
echo "Using test PyPI"
PIP_INDEX_URL="https://test.pypi.org/simple"
PIP_EXTRA_INDEX_URL="https://pypi.org/simple"
TAG_SUFFIX="local-test"
USE_LOCAL_INSTALL="false"
elif [ $STABLE_VERSION = "stable=false" ]; then
echo "Using local development install (pip install -e .)"
TAG_SUFFIX="local-dev"
USE_LOCAL_INSTALL="true"
else
echo "For local builds, use stable=prod, stable=test, or stable=false"
exit 1
fi
if [ $USE_LOCAL_INSTALL = "true" ]; then
docker build --no-cache \
--build-arg USE_LOCAL_INSTALL=true \
-t socketdev/cli:$VERSION-$TAG_SUFFIX \
-t socketdev/cli:$TAG_SUFFIX .
else
docker build --no-cache \
--build-arg CLI_VERSION=$VERSION \
--build-arg PIP_INDEX_URL=$PIP_INDEX_URL \
--build-arg PIP_EXTRA_INDEX_URL=$PIP_EXTRA_INDEX_URL \
-t socketdev/cli:$VERSION-$TAG_SUFFIX \
-t socketdev/cli:$TAG_SUFFIX .
fi
echo "Local build complete. Tagged as socketdev/cli:$VERSION-$TAG_SUFFIX and socketdev/cli:$TAG_SUFFIX"
fi