Skip to content

Commit

Permalink
Merge pull request #1990 from xiagw/fix-docker
Browse files Browse the repository at this point in the history
fix docker
  • Loading branch information
star7th committed Jul 14, 2023
2 parents 8051126 + 95ebb92 commit 0fcbbce
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.dockerignore
.github
.gitignore
Dockerfile*

.git/
Application/Runtime/
server/Application/Runtime/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
with:
push: true
tags: star7th/showdoc:arm-latest
file: DockerfileARM # 使用仓库下的DockerfileARM文件进行构建
file: Dockerfile.ARM # 使用仓库下的Dockerfile.ARM文件进行构建
platforms: |
linux/arm/v5
linux/arm/v7
Expand Down
27 changes: 8 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
FROM webdevops/php-nginx:7.4-alpine

COPY ./ /var/www/html/
RUN mkdir -p /showdoc_data/html
RUN cp -R /var/www/html/ /showdoc_data/
RUN rm -rf /app && ln -s /var/www/html /app
RUN echo "<?php echo file_get_contents('index.html'); ?>" > /var/www/html/web/index.php
## docker build --build-arg=IN_CHINA=true .
ARG IN_CHINA=false

RUN echo "upload_max_filesize=5000M;" >> /opt/docker/etc/php/php.ini
RUN echo "post_max_size=5000M;" >> /opt/docker/etc/php/php.ini
RUN echo "client_max_body_size 5000m;" > /opt/docker/etc/nginx/vhost.common.d/10-general.conf
# 环境变量
ENV SHOWDOC_DOCKER_VERSION 2.4

RUN apk update
RUN apk add --update nodejs npm
RUN mv /showdoc_data/html/mock/ /showdoc_data/mock
RUN (cd /showdoc_data/mock/ && npm install )
WORKDIR /showdoc_data/html
COPY . .

# 写环境变量
ENV SHOWDOC_DOCKER_VERSION 2.4
RUN bash docker.build.sh

CMD if [ ! -f "/var/www/html/index.php" ]; then \cp -fr /showdoc_data/html/ /var/www/ ;fi \
;chmod 777 -R /var/www/ \
;(sleep 3 && cd /showdoc_data/html/server && php index.php /api/update/dockerUpdateCode && chmod 777 -R /var/www/ ) \
;(sleep 30 && cd /showdoc_data/mock/ && npm run start) \
& supervisord
CMD ["bash", "docker.run.sh"]
File renamed without changes.
22 changes: 0 additions & 22 deletions DockerfileChina

This file was deleted.

29 changes: 29 additions & 0 deletions docker.build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -xe

rm -rf /app
ln -s /var/www/html /app
(
echo "upload_max_filesize=5120M;"
echo "post_max_size=5120M;"
) >>/opt/docker/etc/php/php.ini
echo "client_max_body_size 5120m;" >/opt/docker/etc/nginx/vhost.common.d/10-general.conf
## fix nginx warning
sed -i -e '1d' /opt/docker/etc/nginx/vhost.ssl.conf
sed -i -e '/443\ default_server/s//443\ default_server\ ssl/' /opt/docker/etc/nginx/vhost.conf

if [ "$IN_CHINA" = true ] && [ -f /etc/apk/repositories ]; then
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories
fi
apk update
apk add --update --no-cache nodejs npm

mv /showdoc_data/html/mock /showdoc_data/
cd /showdoc_data/mock || exit 1
if [ "$IN_CHINA" = true ]; then
npm config set registry https://registry.npmmirror.com/
fi
## fix old warn
rm -f package-lock.json
npm install
35 changes: 35 additions & 0 deletions docker.run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -e

if [ ! -f "/var/www/html/index.php" ]; then
\cp -fr /showdoc_data/html/* /var/www/html/
fi

## backup sqlite file every day
db_file=/var/www/html/Sqlite/showdoc.db.php
while [ -f $db_file ]; do
# backup on 20:01 (UTC) every day
if [[ $(date +%H%M) == 2001 ]]; then
\cp $db_file ${db_file}."$(date +%F-%H-%M-%S)".php
## remove old files (15 days ago)
find ${db_file}.* -type f -ctime +15 -print0 |
xargs -t -0 rm -f >/dev/null
fi
sleep 50
done &

chmod 777 -R /var/www/
(
sleep 3
cd /showdoc_data/html/server
php index.php /api/update/dockerUpdateCode
chmod 777 -R /var/www/
)
(
sleep 30
cd /showdoc_data/mock/
npm run start
) &

supervisord

0 comments on commit 0fcbbce

Please sign in to comment.