💐我们知道Mac自带了Apache服务器,可以方便将个人站点以及文件放到指定目录,实现内网用户分享,大部分mac用户并没有用到此功能,如果简单设置就能实现文件服务器分享、结合jenkins还可以实现自动化根据项目名称发布版本。
🍱 环境参考
Mac : Monterey12.6
Apache: 2.4.
🎍遇到的场景
🚀经常分享一些jar包,文件、Tools、Docs、Wiki、pdf 等,而这些文件可能有所变动(比如更新)怎么实现快速分享到最新的版本,还能查阅到以前的版本呢?
举例你每天维护两三个项目,每天可能需要多次构建,怎么让测试或者用户拿到最新的版本,是复制粘贴吗?每时每刻看着打包然后发布、重命名 复制,发送?不不不,这样是最最最浪费时间,不容易归档,不容易查阅更改的内容,不容易查看和归档,又浪费大量的磁盘空间!
分享一下解决方案:
🚀如下图:实现的效果(可以分享文件、pdf等任何文件)
关于Mac Apache 配置
Mac apache配置比较简单,不过随着mac升级apache 配置比较麻烦,需要注意.
配置文件
/etc/apache2/httpd.conf
修改如下配置
修改之前,请先备份,发现修改错了,随时还原!这个很关键!比如先复制一份叫httpd.conf_back
在这里我先分享一下我的httpd.conf文件。文件目录/etc/apache2/httpd.conf
全部httpd.conf文件下载:
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
Options Indexes FollowSymLinks Multiviews
IndexOptions Charset=UTF-8
IndexOptions NameWidth=*
MultiviewsMatch Any
AllowOverride None
Require all granted
</Directory>
重启Apache服务
命令可以依次执行,或者同时执行
sudo apachectl stop
sudo apachectl start
sudo apachectl restart
Apache默认分享文件目录:
Library/WebServer/Documents/
实现的思路,就是将需要分享的文件全部复制到Documents文件夹下,如果打包的话,结合Jenkins在此文件夹下自动化创建文件夹,和Copy每次构建好的文件到这个文件夹,实现按照项目名、分支名、日期、渠道包、更新日志等。那么用户就可以按照时间、项目、分支、渠道包拿到想要的文件、比如我就想要2022.1.1日构建的,我就想要Develop分支的,那么刚好,我的文件服务器最适合你!
效果如下:
分享构建脚本
本脚本放在Android project build同目录,执行即可自动化构建
#!/bin/bash
set -eo pipefail
echo '
/ ()\
_|_____|_
| | === | |
|_| O |_|
|| O ||
||__*__||
|~ ___/ ~|
/=\ /=\ /=\
________________________[_]_[_]_[_]_________________________'
webHeader="http://"
projectName=project_vmc_management
appPath=/Users/lixiaodaoaaa/project/want_project/${projectName}/app
apkFile=/Users/lixiaodaoaaa/project/want_project/${projectName}/apkFile
currentTag=$( git symbolic-ref --short --q HEAD | sed 's///_/' )
cd ${apkFile}
if [ "`ls -A `" = "" ]; then
echo "apkFile directory is empty not need to delete"
else
echo " apkFile directory not empty need to delete then execute delete it!!!!"
rm *.*
fi
cd ${appPath}
versionName=$(gradle printVersionName --q)
webServerFileApkName=/Library/WebServer/Documents/apk/${projectName}/${currentTag}/`date +%Y%m%d`
cd ${appPath}
gradle aR
echo ${webServerFileApkName}
if [ ! -d ${webServerFileApkName} ]; then
mkdir -p ${webServerFileApkName}
fi
cd ${webServerFileApkName}
if [ "`ls -A `" = "" ]; then
echo "directory is empty not need to delete"
else
echo "sever apk directory not empty need to delete then execute delete it!!!!"
rm *.*
fi
cd ${apkFile}
cp *.apk ${webServerFileApkName}
ipAddress=$(ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:" | grep 10 | cut -d: -f2)
fullWebAddress=${webHeader}${ipAddress}/apk/${projectName}/${currentTag}/`date +%Y%m%d`
open ${fullWebAddress}
echo "success move apk file To Server apk Folder"
echo '
'
echo "add ip address is "${fullWebAddress}