-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-image.sh
executable file
·163 lines (119 loc) · 6.32 KB
/
build-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
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
162
163
#!/usr/bin/env bash
#### halt script on error
set -xe
#git clone -b v12.1 https://github.com/laradock/laradock.git
git clone https://github.com/laradock/laradock.git
cd laradock
# switch version to Commits on Dec 22, 2022
git checkout 6c8cb6dd85eb1fcad6f7dce3e9d6c6a29c6e3ed8
echo '##### Print docker version'
docker --version
echo '##### Print environment'
env | sort
BUILD_VERSION=latest
cp .env.example .env
if [[ `uname` == 'Darwin' ]]; then
alias sed=gsed;
fi
#### Build the Docker Images
if [ -n "${PHP_VERSION}" ]; then
BUILD_VERSION=${PHP_VERSION}
sed -i -- "s/PHP_VERSION=.*/PHP_VERSION=${PHP_VERSION}/g" .env
# sed -i -- 's/=false/=true/g' .env
sed -i -- 's/PHPDBG=true/PHPDBG=false/g' .env
if [[ "${PHP_VERSION}" == "7.2" || "${PHP_VERSION}" == "7.3" || "${PHP_VERSION}" == "7.4" ]]; then
# V8JS extension does not yet support PHP 7.3.
sed -i -- 's/WORKSPACE_INSTALL_V8JS=true/WORKSPACE_INSTALL_V8JS=false/g' .env
# This ssh2 extension does not yet support PHP 7.3.
sed -i -- 's/PHP_FPM_INSTALL_SSH2=true/PHP_FPM_INSTALL_SSH2=false/g' .env
# xdebug extension does not yet support PHP 7.3.
sed -i -- 's/PHP_FPM_INSTALL_XDEBUG=true/PHP_FPM_INSTALL_XDEBUG=false/g' .env
# memcached extension does not yet support PHP 7.3.
sed -i -- 's/PHP_FPM_INSTALL_MEMCACHED=true/PHP_FPM_INSTALL_MEMCACHED=false/g' .env
search='pecl -q install swoole;';
replace='pecl -q install swoole-4.8.9;';
sed -i "s/$search/$replace/g" ./workspace/Dockerfile;
search='pecl install swoole;';
replace='pecl install swoole-4.8.9;';
sed -i "s/$search/$replace/g" ./php-fpm/Dockerfile;
sed -i "s/$search/$replace/g" ./php-worker/Dockerfile;
fi
if [ "${PHP_VERSION}" == "8.0" ]; then
search='pecl -q install swoole;';
replace="yes yes | pecl install swoole-4.8.10;";
sed -i "s/^$search/^$replace/g" ./workspace/Dockerfile;
fi
# if [ "${PHP_VERSION}" == "7.4" ]; then
# search='docker-php-ext-configure gd --with-freetype-dir=/usr/lib/ --with-jpeg-dir=/usr/lib/ --with-png-dir=/usr/lib/ ';
# replace='docker-php-ext-configure gd --with-freetype --with-jpeg ';
# sed -i "s|$search|$replace|g" ./php-worker/Dockerfile
# # https://github.com/docker-library/php/issues/225#issuecomment-691989156
# search='apk add --update --no-cache freetype-dev libjpeg-turbo-dev jpeg-dev libpng-dev;';
# replace='apk add --no-cache freetype freetype-dev libpng libpng-dev libjpeg-turbo libjpeg-turbo-dev;';
# sed -i "s|$search|$replace|g" ./php-worker/Dockerfile
# fi
# sed -i -- 's/CHANGE_SOURCE=true/CHANGE_SOURCE=false/g' .env
### 自定义部分 ###
# 开启 中国源-阿里云
sed -i -- 's/CHANGE_SOURCE=false/CHANGE_SOURCE=true/g' .env
# 开启 ffmpeg 安装 (php-fpm php-worker workspace)
sed -i -- 's/PHP_FPM_FFMPEG=false/PHP_FPM_FFMPEG=true/g' .env
sed -i -- 's/PHP_WORKER_INSTALL_FFMPEG=false/PHP_WORKER_INSTALL_FFMPEG=true/g' .env
sed -i -- 's/WORKSPACE_INSTALL_FFMPEG=false/WORKSPACE_INSTALL_FFMPEG=true/g' .env
# 开启 redis 扩展
sed -i -- 's/PHP_WORKER_INSTALL_REDIS=false/PHP_WORKER_INSTALL_REDIS=true/g' .env
# 开启 bcmath 扩展
sed -i -- 's/PHP_WORKER_INSTALL_BCMATH=false/PHP_WORKER_INSTALL_BCMATH=true/g' .env
# 开启 swoole 安装 (php-fpm php-worker workspace)
sed -i -- 's/PHP_FPM_INSTALL_SWOOLE=false/PHP_FPM_INSTALL_SWOOLE=true/g' .env
sed -i -- 's/PHP_WORKER_INSTALL_SWOOLE=false/PHP_WORKER_INSTALL_SWOOLE=true/g' .env
sed -i -- 's/WORKSPACE_INSTALL_SWOOLE=false/WORKSPACE_INSTALL_SWOOLE=true/g' .env
# 开启 GD 和 ImageMagic
sed -i -- 's/PHP_WORKER_INSTALL_GD=false/PHP_WORKER_INSTALL_GD=true/g' .env
sed -i -- 's/PHP_WORKER_INSTALL_IMAGEMAGICK=false/PHP_WORKER_INSTALL_IMAGEMAGICK=true/g' .env
# 开启 RabbitMQ 支持
sed -i -- 's/PHP_FPM_INSTALL_AMQP=false/PHP_FPM_INSTALL_AMQP=true/g' .env
sed -i -- 's/WORKSPACE_INSTALL_AMQP=false/WORKSPACE_INSTALL_AMQP=true/g' .env
# 开启 MongoDB 支持
sed -i -- 's/WORKSPACE_INSTALL_MONGO=false/WORKSPACE_INSTALL_MONGO=true/g' .env
sed -i -- 's/PHP_FPM_INSTALL_MONGO=false/PHP_FPM_INSTALL_MONGO=true/g' .env
sed -i -- 's/PHP_WORKER_INSTALL_MONGO=false/PHP_WORKER_INSTALL_MONGO=true/g' .env
# 添加 php ini 配置文件至 php-fpm 镜像内
search='xlaravel.pool.conf';
insert='COPY php${LARADOCK_PHP_VERSION}.ini /usr/local/etc/php/php.ini';
sed -i "/$search/a$insert" ./php-fpm/Dockerfile;
fi
if [ "${BUILD_SERVICE}" == "nginx" ]; then
# 拷贝 nginx 默认配置文件
search='COPY nginx.conf';
insert='COPY sites /etc/nginx/sites-available';
sed -i "/$search/a$insert" ./nginx/Dockerfile;
fi
if [ -n "${MYSQL_VERSION}" ]; then
sed -i -- "s/MYSQL_VERSION=.*/MYSQL_VERSION=${MYSQL_VERSION}/g" .env
BUILD_VERSION=${MYSQL_VERSION}
fi
echo build version is ${BUILD_VERSION}
cat .env
docker-compose build ${BUILD_SERVICE}
#####################################
# push to docker hub
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker tag laradock_${BUILD_SERVICE}:latest ${DOCKER_USERNAME}/laradock-${BUILD_SERVICE}:latest
docker images
docker push ${DOCKER_USERNAME}/laradock-${BUILD_SERVICE}
if [[ ${BUILD_VERSION} != "latest" && ${BUILD_VERSION} != "NA" ]]; then
# push build version
docker tag ${DOCKER_USERNAME}/laradock-${BUILD_SERVICE}:latest ${DOCKER_USERNAME}/laradock-${BUILD_SERVICE}:${BUILD_VERSION}
docker push ${DOCKER_USERNAME}/laradock-${BUILD_SERVICE}:${BUILD_VERSION}
fi
# push to aliyun docker hub
echo "$ALIYUN_DOCKER_PASSWORD" | docker login -u "$ALIYUN_DOCKER_USERNAME" --password-stdin registry.cn-hangzhou.aliyuncs.com
docker tag laradock_${BUILD_SERVICE}:latest registry.cn-hangzhou.aliyuncs.com/${DOCKER_USERNAME}/laradock-${BUILD_SERVICE}:latest
docker images
docker push registry.cn-hangzhou.aliyuncs.com/${DOCKER_USERNAME}/laradock-${BUILD_SERVICE}
if [[ ${BUILD_VERSION} != "latest" && ${BUILD_VERSION} != "NA" ]]; then
# push build version
docker tag ${DOCKER_USERNAME}/laradock-${BUILD_SERVICE}:latest registry.cn-hangzhou.aliyuncs.com/${DOCKER_USERNAME}/laradock-${BUILD_SERVICE}:${BUILD_VERSION}
docker push registry.cn-hangzhou.aliyuncs.com/${DOCKER_USERNAME}/laradock-${BUILD_SERVICE}:${BUILD_VERSION}
fi