Skip to content

Commit

Permalink
refacgtor: enhance docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
leftstick committed Dec 26, 2019
1 parent 5e3bc15 commit 3e7c866
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bash shells/build.sh
### docker pattern

```bash
bash shells/build.sh && docker build --no-cache -t <app-name>:<tag>
docker build --no-cache -t <app-name>:<tag> .
```

> find generated image via `docker image ls`
Expand Down
12 changes: 10 additions & 2 deletions generators/app/templates/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
FROM node:13 AS compile-env

WORKDIR /src

COPY . /src

RUN apt-get update -y && apt-get install zip && bash ./shells/build.sh

FROM node:13-alpine

COPY *-zip-dist/ /usr/src/app/
WORKDIR /application

WORKDIR /usr/src/app
COPY --from=compile-env /src/*-zip-dist /application

EXPOSE 3000

Expand Down
8 changes: 7 additions & 1 deletion generators/app/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ yarn
yarn start
```

## Packaging
## Packaging in .zip

```bash
bash shells/build.sh
```

## Packaging in docker image

```bash
docker build --no-cache -t <app-name>:<tag> .
```
4 changes: 3 additions & 1 deletion generators/app/templates/dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
node_modules/

# dist
dist/
dist/
*-zip-dist/
*.zip
4 changes: 2 additions & 2 deletions generators/app/templates/shells/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mkdir ./${output}/bin

rm -rf package-lock.json

yarn
yarn --registry <%= answers.registry %>

if [ $? -ne 0 ]; then
echo "Failed to install first depenedencies"
Expand Down Expand Up @@ -68,7 +68,7 @@ fi
cd ./${output}

# 安装运行时依赖
npm i express replace-in-file --registry=https://registry.npm.taobao.org
npm i express replace-in-file --registry=<%= answers.registry %>

if [ $? -ne 0 ]; then
echo "Install runtime dependencies failed, check network first!"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-umi",
"version": "3.1.0",
"version": "3.1.1",
"description": "umi project generator",
"files": [
"generators"
Expand Down

0 comments on commit 3e7c866

Please sign in to comment.