Skip to content

Commit da2a4e8

Browse files
committed
Initial version
1 parent 3cc410d commit da2a4e8

File tree

5 files changed

+190
-0
lines changed

5 files changed

+190
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
release/
2+
.ssh/
3+
.git
4+
.idea
5+
.vscode
6+
.aws
7+
.env
8+
*.pem
9+
*.key
10+
*.log
11+
*.lock
12+
*.tmp
13+
authorized_keys

build_static_sqlite.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/sh
2+
3+
SQLITE_ZIP_URL='https://www.sqlite.org/2021/sqlite-amalgamation-3370000.zip'
4+
SQLite_compressor='upx' # Programm to use for compressing compiled sqlite
5+
# Keep it empty as "" to disable compression
6+
7+
DockerImage='static-sqlite'
8+
9+
### No user intervention below this point ######################################
10+
11+
onErr(){
12+
local msg errNum
13+
msg="${1}"
14+
errNum=$2
15+
printf "Error[%i]: %s\n" ${errNum} "${msg}"
16+
exit 1
17+
}
18+
19+
errMsgDep="Cannot continue due to absents of required dependancy"
20+
21+
ID=$(type id); [ $? -eq 0 ] && ID="/${ID#*/}" || onErr "${errMsgDep}" 1
22+
23+
if [ $($ID -u) -eq 0 ]; then
24+
SUDO=''
25+
else
26+
SUDO=$(type sudo); [ $? -eq 0 ] && SUDO="/${SUDO#*/}" || SUDO=''
27+
fi
28+
29+
DOCKER=$(type docker);
30+
[ $? -eq 0 ] && DOCKER="/${DOCKER#*/}" || onErr "Install please docker first..." 2
31+
32+
$SUDO $DOCKER version >/dev/null 2>&1
33+
[ $? -ne 0 ] && {
34+
errMsg="$(printf '\n You are not authorized to run docker,')"
35+
errMsg="${errMsg}$(printf '\n try to "su -" into root account and try again.\n\n')"
36+
onErr "${errMsg}" 3
37+
}
38+
39+
40+
41+
cd ./docker
42+
43+
#$SUDO $DOCKER build --no-cache -t static-sqlite . \
44+
$SUDO $DOCKER build --rm -t "${DockerImage}" . \
45+
--build-arg URL_SQLITE_SOURCE_ZIP="${SQLITE_ZIP_URL}" \
46+
--build-arg COMPRESS_SQLITE3="${SQLite_compressor}"
47+
cd ..
48+
49+
printf "\n\n===== Taking ready to use static sqlite3 =======================================\n\n"
50+
51+
arch="${SQLITE_ZIP_URL##*/}"
52+
workdir="${arch%.*}"
53+
54+
[ ! -d release ] && mkdir release
55+
56+
$SUDO $DOCKER run --rm -v $(pwd)/release:/release/ \
57+
-it "${DockerImage}" \
58+
cp -fv /app/${workdir}/sqlite3 /release/
59+
60+
$SUDO $DOCKER stop "${DockerImage}"
61+
62+
cd release
63+
echo "=============================="
64+
ldd sqlite3
65+
echo "------------------------------"
66+
file sqlite3
67+
echo "------------------------------"
68+
echo '.version' | ./sqlite3
69+
echo "=============================="
70+
71+
cd ..
72+
73+
# Cleanup the built image
74+
$SUDO $DOCKER image rm "${DockerImage}" >/dev/null 2>&1
75+

docker/.dockerignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.ssh/
2+
.git
3+
.idea
4+
.vscode
5+
.aws
6+
.env
7+
travis.yml
8+
*.pem
9+
*.key
10+
authorized_keys
11+
Dockerfile*
12+
docker-compose*
13+
README.md
14+
LICENSE
15+
config.json
16+
prerequisite.txt

docker/Build.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
3+
src="${1}"
4+
arch="${src##*/}"
5+
workdir="${arch%.*}"
6+
7+
[ ! -f "${arch}" ] && wget "${src}"
8+
[ $? -ne 0 ] && {
9+
echo "===== FAILED ....... ==========================================================="
10+
printf "Can not download: %s\n\n" "${src}"
11+
exit 1
12+
}
13+
14+
unzip ${arch}
15+
16+
cd "${workdir}"
17+
18+
printf "\n\n===== Compiling... Please wait... ==============================================\n\n"
19+
20+
gcc -O2 \
21+
-DHAVE_USLEEP \
22+
-DSQLITE_DQS=0 \
23+
-DHAVE_READLINE \
24+
-DSQLITE_USE_ALLOCA \
25+
-DSQLITE_THREADSAFE=0 \
26+
-DSQLITE_ENABLE_FTS4 \
27+
-DSQLITE_ENABLE_FTS5 \
28+
-DSQLITE_ENABLE_JSON1 \
29+
-DSQLITE_ENABLE_RTREE \
30+
-DSQLITE_ENABLE_GEOPOLY \
31+
-DSQLITE_OMIT_DECLTYPE \
32+
-DSQLITE_OMIT_DEPRECATED \
33+
-DSQLITE_OMIT_SHARED_CACHE \
34+
-DSQLITE_OMIT_LOAD_EXTENSION \
35+
-DSQLITE_OMIT_PROGRESS_CALLBACK \
36+
-DSQLITE_LIKE_DOESNT_MATCH_BLOBS \
37+
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
38+
-DSQLITE_ENABLE_MATH_FUNCTIONS \
39+
shell.c sqlite3.c \
40+
-static -lm \
41+
-lreadline \
42+
-lncursesw -o sqlite3 # On apline use ncursesw instead of ncurses (!!!)
43+
44+
rc=$?
45+
if [ $rc -eq 0 ]; then
46+
cp sqlite3 sqlite3_orig # Keep naked, unstripped, unpacked version
47+
echo "===== Stripping... ============================================================="
48+
strip --strip-unneeded sqlite3
49+
if [ -n "${2}" ]; then
50+
echo "===== Compressing... ==========================================================="
51+
$2 sqlite3
52+
fi
53+
else
54+
echo "================================ FAILED to compile ============================="
55+
exit 1
56+
fi
57+
58+
echo "===================================== Done ====================================="
59+
60+
exit 0

docker/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM alpine:latest
2+
3+
# Version of this Dockerfile
4+
ENV SCRIPT_VERSION=1.0.5
5+
6+
ARG URL_SQLITE_SOURCE_ZIP
7+
ARG COMPRESS_SQLITE3
8+
9+
# Version of SQLite to download (full url to sqlite-amalgamation.zip)
10+
ENV SQLITE_URL_SRC="${URL_SQLITE_SOURCE_ZIP}"
11+
ENV COMPRESSOR="${COMPRESS_SQLITE3}"
12+
13+
RUN echo >> /etc/apk/repositories && \
14+
echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" \
15+
>> /etc/apk/repositories && \
16+
apk update && apk upgrade && \
17+
apk add --no-cache fakeroot musl-dev linux-headers gcc libgcc ccache \
18+
binutils upx file wget unzip zlib-dev zlib-static \
19+
libhistory readline-static readline-dev \
20+
ncurses-static ncurses-dev
21+
22+
WORKDIR /app
23+
24+
COPY Build.sh /app/
25+
RUN chmod +x /app/Build.sh && ./Build.sh "${SQLITE_URL_SRC}" "${COMPRESSOR}"
26+

0 commit comments

Comments
 (0)