Skip to content

Commit

Permalink
ci(): 修改docker构建,使用国内镜像,使用缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuler committed Jul 29, 2020
1 parent c18b568 commit 22124db
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 62 deletions.
45 changes: 0 additions & 45 deletions .github/workflows/pr-auto-labels.yml

This file was deleted.

16 changes: 15 additions & 1 deletion Dockerfile
@@ -1,9 +1,23 @@
FROM node:10 as stage-build
ARG VERSION
ENV VERSION=$VERSION
ARG NPM_REGISTRY="https://registry.npm.taobao.org"
ENV NPM_REGISTY=$NPM_REGISTRY
ARG SASS_BINARY_SITE="https://npm.taobao.org/mirrors/node-sass"
ENV SASS_BINARY_SITE=$SASS_BINARY_SITE

WORKDIR /data

# Install deps
RUN npm config set sass_binary_site=${SASS_BINARY_SITE}
RUN npm config set registry ${NPM_REGISTRY}
COPY package.json package-lock.json /data/
COPY utils /data/utils
RUN cd utils && bash -ixeu build.sh dep

# Build
ADD . /data
RUN cd utils && bash -ixeu build.sh
RUN cd utils && ls .. && bash -ixeu build.sh build

FROM nginx:alpine
COPY --from=stage-build /data/release/luna /opt/luna/
Expand Down
50 changes: 34 additions & 16 deletions utils/build.sh
Expand Up @@ -5,30 +5,48 @@ utils_dir=$(pwd)
project_dir=$(dirname "$utils_dir")
release_dir=${project_dir}/release

if [[ $(uname) == 'Darwin' ]];then
if [[ $(uname) == 'Darwin' ]]; then
alias sedi="sed -i ''"
else
alias sedi='sed -i'
fi

function change_version() {
sedi "s@[0-9].[0-9].[0-9]@${VERSION}@g" "${project_dir}/src/environments/environment.prod.ts" || return 2
sedi "s@[0-9].[0-9].[0-9]@${VERSION}@g" "${project_dir}/src/environments/environment.prod.ts" || return 2
}

# 修改版本号文件
if [[ -n ${VERSION-''} ]]; then
change_version || exit 2
fi
install_deps() {
# 下载依赖模块并构建
cd "${project_dir}" && npm i --loglevel verbose || exit 3
npm rebuild node-sass
}

# 下载依赖模块并构建
cd "${project_dir}" && npm i || exit 3
npm rebuild node-sass
npm run-script build || exit 4
build() {
# 修改版本号文件
cd "${project_dir}" || exit 1
if [[ -n ${VERSION-''} ]]; then
change_version || exit 2
fi

# 打包
rm -rf "${release_dir:?}"/*
to_dir="${release_dir}"
mkdir -p "${to_dir}"
npm run-script build || exit 4

# 打包
rm -rf "${release_dir:?}"/*
to_dir="${release_dir}"
mkdir -p "${to_dir}"
mv luna "${to_dir}"
cp -R src/assets/i18n "${to_dir}/luna"
}

mv luna "${to_dir}"
cp -R src/assets/i18n "${to_dir}/luna"
case "${1-}" in
dep)
install_deps
;;
build)
build
;;
*)
install_deps
build
;;
esac

0 comments on commit 22124db

Please sign in to comment.