项目描述
- 框架:vue
- 包管理工具:yarn
前提:Dockerfile、基础镜像已准备好
安装docker for windows
官方地址
https://docs.docker.com/v17.09/docker-for-windows/install/
配置私有仓库地址
创建脚本&配置基本信息
创建脚本
cd 项目目录
vim build_upload.sh
// build_upload.sh
#!/bin/bash
# 解析配置文件
host=$(grep -Po '(?<=host": ").*?(?=")' build.config.json)
username=$(grep -Po '(?<=username": ").*?(?=")' build.config.json)
password=$(grep -Po '(?<=password": ").*?(?=")' build.config.json)
version=$(grep -Po '(?<=version": ").*?(?=")' build.config.json)
path=$(grep -Po '(?<=path": ").*?(?=")' build.config.json)
# 获取当前目录名, 作为镜像名
string=$(pwd)
OLD_IFS="$IFS"
IFS="/"
array=($string)
IFS="$OLD_IFS"
length=${#array[@]}
nameLastIndex=${array[length-1]}
yarn build
docker build -t "$nameLastIndex:$version" .
docker login -u $username -p $password $host
docker tag "$nameLastIndex:$version" "$host$path/$nameLastIndex:$version"
docker push "$host$path/$nameLastIndex:$version"
echo '-------------------'
echo 'finish!'
echo '-------------------'
配置基本信息
vim build.config.json
// build.config.json
{
"host": "ip:端口",
"path": "/项目目录",
"username": "用户名",
"password": "密码",
"version": "版本号"
}
运行脚本,一键打包并上传
// package.json
"scripts": {
"auto": "./build_upload.sh"
},
yarn auto
网友评论