рдбреЙрдХрд░ рдЪрд┐рддреНрд░реЛрдВ рдХреА рдЕрд╕реЗрдВрдмрд▓реА рдХреЛ рддреЗрдЬ рдХрд░рдиреЗ рдХреЗ рдХреБрдЫ рдЯрд┐рдкреНрд╕ред рдЙрджрд╛рд╣рд░рдг рдХреЗ рд▓рд┐рдП, 30 рд╕реЗрдХрдВрдб рддрдХ

рдЗрд╕рд╕реЗ рдкрд╣рд▓реЗ рдХрд┐ рд╕реБрд╡рд┐рдзрд╛ рдмрд┐рдХреНрд░реА рдкрд░ рдЬрд╛рддреА рд╣реИ, рд╣рдорд╛рд░реЗ рд╕рдордп рдореЗрдВ рдХреЙрдореНрдкреНрд▓реЗрдХреНрд╕ рдСрд░реНрдХреЗрдЯрд░ рдФрд░ рд╕реАрдЖрдИ / рд╕реАрдбреА рдХреЗ рд▓рд┐рдП рдХрдорд┐рдЯрдореЗрдВрдЯ рд╕реЗ рд▓реЗрдХрд░ рдкрд░реАрдХреНрд╖рдг рдФрд░ рдбрд┐рд▓реАрд╡рд░реА рддрдХ рд▓рдВрдмрд╛ рд░рд╛рд╕реНрддрд╛ рддрдп рдХрд░рдирд╛ рд╣реЛрддрд╛ рд╣реИред рдкрд╣рд▓реЗ, рдПрдлрд╝рдЯреАрдкреА рдХреЗ рдорд╛рдзреНрдпрдо рд╕реЗ рдирдИ рдлрд╝рд╛рдЗрд▓реЛрдВ рдХреЛ рдЕрдкрд▓реЛрдб рдХрд░рдирд╛ рд╕рдВрднрд╡ рдерд╛ (рдХреЛрдИ рдФрд░ рдРрд╕рд╛ рдирд╣реАрдВ рдХрд░рддрд╛ рд╣реИ, рдареАрдХ рд╣реИ?), рдФрд░ рддреИрдирд╛рддреА рдХреА рдкреНрд░рдХреНрд░рд┐рдпрд╛ рдореЗрдВ рд╕реЗрдХрдВрдб рд▓рдЧ рдЧрдПред рдЕрдм рдЖрдкрдХреЛ рдорд░реНрдЬ рдЕрдиреБрд░реЛрдз рдмрдирд╛рдиреЗ рдФрд░ рдЙрдкрдпреЛрдЧрдХрд░реНрддрд╛ рддрдХ рдкрд╣реБрдВрдЪрдиреЗ рддрдХ рдХрд╛рдлреА рд╕рдордп рдкреНрд░рддреАрдХреНрд╖рд╛ рдХрд░рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рд╣реИред


рдЗрд╕ рдпрд╛рддреНрд░рд╛ рдХрд╛ рдПрдХ рд╣рд┐рд╕реНрд╕рд╛ рдбреЙрдХрд░ рдЫрд╡рд┐ рдмрдирд╛ рд░рд╣рд╛ рд╣реИред рдХрднреА-рдХрднреА рд╡рд┐рдзрд╛рдирд╕рднрд╛ рдорд┐рдирдЯреЛрдВ рддрдХ рдЪрд▓рддреА рд╣реИ, рдХрднреА-рдХрднреА рджрд╕рд┐рдпреЛрдВ рдорд┐рдирдЯ рддрдХ, рдЬрд┐рд╕реЗ рд╢рд╛рдпрдж рд╣реА рд╕рд╛рдорд╛рдиреНрдп рдХрд╣рд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИред рдЗрд╕ рд▓реЗрдЦ рдореЗрдВ, рд╣рдо рдПрдХ рд╕рд░рд▓ рдЕрдиреБрдкреНрд░рдпреЛрдЧ рд▓реЗрддреЗ рд╣реИрдВ рдЬрд┐рд╕реЗ рд╣рдо рдПрдХ рдЫрд╡рд┐ рдореЗрдВ рдкреИрдХ рдХрд░рддреЗ рд╣реИрдВ, рд╡рд┐рдзрд╛рдирд╕рднрд╛ рдХреЛ рдЧрддрд┐ рджреЗрдиреЗ рдХреЗ рд▓рд┐рдП рдХрдИ рддрд░реАрдХреЗ рд▓рд╛рдЧреВ рдХрд░рддреЗ рд╣реИрдВ рдФрд░ рдЗрди рд╡рд┐рдзрд┐рдпреЛрдВ рдХреА рдмрд╛рд░реАрдХрд┐рдпреЛрдВ рдкрд░ рд╡рд┐рдЪрд╛рд░ рдХрд░рддреЗ рд╣реИрдВред



: , The Bell, " ", RepublicтАж , Reminder. , .


GitLab. , GitLab Registry . тАФ . : 14 .



, , , . 30 !



, Reminder', Angular. , :


ng n app

PWA ( ):


ng add @angular/pwa --project app

npm-, , docker-. Docker , . . , . , , , . тАФ . , Dockerfile:


FROM node:12.16.2
WORKDIR /app
COPY . .
RUN npm ci
RUN npm run build --prod

Dockerfile тАФ ; , Docker . . тАФ .


: . , . , . , :


  1. , .
    docker rmi $(docker images -q)
  2. .
    time docker build -t app .
  3. src/index.html тАФ .
  4. .
    time docker build -t app .

( ), . тАФ , . , тАФ , тАФ , , . , . , .


Dockerfile, , . .


$ time docker build -t app .
Sending build context to Docker daemon 409MB
Step 1/5 : FROM node:12.16.2
Status: Downloaded newer image for node:12.16.2
Step 2/5 : WORKDIR /app
Step 3/5 : COPY . .
Step 4/5 : RUN npm ci
added 1357 packages in 22.47s
Step 5/5 : RUN npm run build --prod
Date: 2020-04-16T19:20:09.664Z - Hash: fffa0fddaa3425c55dd3 - Time: 37581ms
Successfully built c8c279335f46
Successfully tagged app:latest

real 5m4.541s
user 0m0.000s
sys 0m0.000s

src/index.html .


$ time docker build -t app .
Sending build context to Docker daemon 409MB
Step 1/5 : FROM node:12.16.2
Step 2/5 : WORKDIR /app
 ---> Using cache
Step 3/5 : COPY . .
Step 4/5 : RUN npm ci
added 1357 packages in 22.47s
Step 5/5 : RUN npm run build --prod
Date: 2020-04-16T19:26:26.587Z - Hash: fffa0fddaa3425c55dd3 - Time: 37902ms
Successfully built 79f335df92d3
Successfully tagged app:latest

real 3m33.262s
user 0m0.000s
sys 0m0.000s

, , docker images:


REPOSITORY   TAG      IMAGE ID       CREATED              SIZE
app          latest   79f335df92d3   About a minute ago   1.74GB

Sending build context to Docker daemon 409MB. build. тАФ ┬л.┬╗, тАФ , . 409 тАФ : , .



, . , , . , : . .dockerignore , :


.git
/node_modules

:


$ time docker build -t app .
Sending build context to Docker daemon 607.2kB
Step 1/5 : FROM node:12.16.2
Step 2/5 : WORKDIR /app
 ---> Using cache
Step 3/5 : COPY . .
Step 4/5 : RUN npm ci
added 1357 packages in 22.47s
Step 5/5 : RUN npm run build --prod
Date: 2020-04-16T19:33:54.338Z - Hash: fffa0fddaa3425c55dd3 - Time: 37313ms
Successfully built 4942f010792a
Successfully tagged app:latest

real 1m47.763s
user 0m0.000s
sys 0m0.000s

607.2 тАФ , 409 . 1.74 1.38:


REPOSITORY   TAG      IMAGE ID       CREATED         SIZE
app          latest   4942f010792a   3 minutes ago   1.38GB

.


Alpine


тАФ . тАФ , . FROM Dockerfile. Ubuntu, nodejs. тАж


$ docker images -a | grep node
node 12.16.2 406aa3abbc6c 17 minutes ago 916MB

тАж . , Alpine Linux. Alpine тАФ . - nodejs alpine 88.5 . :


FROM node:12.16.2-alpine3.11
RUN apk --no-cache --update --virtual build-dependencies add \
    python \
    make \
    g++
WORKDIR /app
COPY . .
RUN npm ci
RUN npm run build --prod

, . , Angular ┬п(┬░_o)/┬п


619 :


REPOSITORY   TAG      IMAGE ID       CREATED          SIZE
app          latest   aa031edc315a   22 minutes ago   761MB

.



, , .


$ docker run app ls -lah
total 576K
drwxr-xr-x 1 root root 4.0K Apr 16 19:54 .
drwxr-xr-x 1 root root 4.0K Apr 16 20:00 ..
-rwxr-xr-x 1 root root 19 Apr 17 2020 .dockerignore
-rwxr-xr-x 1 root root 246 Apr 17 2020 .editorconfig
-rwxr-xr-x 1 root root 631 Apr 17 2020 .gitignore
-rwxr-xr-x 1 root root 181 Apr 17 2020 Dockerfile
-rwxr-xr-x 1 root root 1020 Apr 17 2020 README.md
-rwxr-xr-x 1 root root 3.6K Apr 17 2020 angular.json
-rwxr-xr-x 1 root root 429 Apr 17 2020 browserslist
drwxr-xr-x 3 root root 4.0K Apr 16 19:54 dist
drwxr-xr-x 3 root root 4.0K Apr 17 2020 e2e
-rwxr-xr-x 1 root root 1015 Apr 17 2020 karma.conf.js
-rwxr-xr-x 1 root root 620 Apr 17 2020 ngsw-config.json
drwxr-xr-x 1 root root 4.0K Apr 16 19:54 node_modules
-rwxr-xr-x 1 root root 494.9K Apr 17 2020 package-lock.json
-rwxr-xr-x 1 root root 1.3K Apr 17 2020 package.json
drwxr-xr-x 5 root root 4.0K Apr 17 2020 src
-rwxr-xr-x 1 root root 210 Apr 17 2020 tsconfig.app.json
-rwxr-xr-x 1 root root 489 Apr 17 2020 tsconfig.json
-rwxr-xr-x 1 root root 270 Apr 17 2020 tsconfig.spec.json
-rwxr-xr-x 1 root root 1.9K Apr 17 2020 tslint.json

docker run app ls -lah app ls -lah, .


dist. - . - HTTP- nodejs. . , ┬л┬╗. ! . nginx, dist :


server {
    listen 80 default_server;
    server_name localhost;
    charset utf-8;
    root /app/dist;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

multi-stage build. Dockerfile:


FROM node:12.16.2-alpine3.11 as builder
RUN apk --no-cache --update --virtual build-dependencies add \
    python \
    make \
    g++
WORKDIR /app
COPY . .
RUN npm ci
RUN npm run build --prod

FROM nginx:1.17.10-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/static.conf /etc/nginx/conf.d
COPY --from=builder /app/dist/app .

FROM Dockerfile, . builder, FROM . nginx. :


REPOSITORY   TAG      IMAGE ID       CREATED          SIZE
app          latest   2c6c5da07802   29 minutes ago   36MB

, :


docker run -p8080:80 app

-p8080:80 8080 80 , nginx. http://localhost:8080/ . !



1.74 36 . .


$ time docker build -t app .
Sending build context to Docker daemon 608.8kB
Step 1/11 : FROM node:12.16.2-alpine3.11 as builder
Step 2/11 : RUN apk --no-cache --update --virtual build-dependencies add python make g++
 ---> Using cache
Step 3/11 : WORKDIR /app
 ---> Using cache
Step 4/11 : COPY . .
Step 5/11 : RUN npm ci
added 1357 packages in 47.338s
Step 6/11 : RUN npm run build --prod
Date: 2020-04-16T21:16:03.899Z - Hash: fffa0fddaa3425c55dd3 - Time: 39948ms
 ---> 27f1479221e4
Step 7/11 : FROM nginx:stable-alpine
Step 8/11 : WORKDIR /app
 ---> Using cache
Step 9/11 : RUN rm /etc/nginx/conf.d/default.conf
 ---> Using cache
Step 10/11 : COPY nginx/static.conf /etc/nginx/conf.d
 ---> Using cache
Step 11/11 : COPY --from=builder /app/dist/app .
Successfully built d201471c91ad
Successfully tagged app:latest

real 2m17.700s
user 0m0.000s
sys 0m0.000s


( Using cache). RUN npm ci тАФ 47.338s. , ? , . , , , . , , , , , ! Dockerfile.


FROM node:12.16.2-alpine3.11 as builder
RUN apk --no-cache --update --virtual build-dependencies add \
    python \
    make \
    g++
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build --prod

FROM nginx:1.17.10-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/static.conf /etc/nginx/conf.d
COPY --from=builder /app/dist/app .

package.json package-lock.json, , . :


$ time docker build -t app .
Sending build context to Docker daemon 608.8kB
Step 1/12 : FROM node:12.16.2-alpine3.11 as builder
Step 2/12 : RUN apk --no-cache --update --virtual build-dependencies add python make g++
 ---> Using cache
Step 3/12 : WORKDIR /app
 ---> Using cache
Step 4/12 : COPY package*.json ./
 ---> Using cache
Step 5/12 : RUN npm ci
 ---> Using cache
Step 6/12 : COPY . .
Step 7/12 : RUN npm run build --prod
Date: 2020-04-16T21:29:44.770Z - Hash: fffa0fddaa3425c55dd3 - Time: 38287ms
 ---> 1b9448c73558
Step 8/12 : FROM nginx:stable-alpine
Step 9/12 : WORKDIR /app
 ---> Using cache
Step 10/12 : RUN rm /etc/nginx/conf.d/default.conf
 ---> Using cache
Step 11/12 : COPY nginx/static.conf /etc/nginx/conf.d
 ---> Using cache
Step 12/12 : COPY --from=builder /app/dist/app .
Successfully built a44dd7c217c3
Successfully tagged app:latest

real 0m46.497s
user 0m0.000s
sys 0m0.000s

46 3 тАФ ! : , , , , тАФ , .


CI/CD .



- SaaS-, . , .


GitHub Actions.


on:
  push:
    branches:
      - master

name: Test docker build

jobs:
  deploy:
    name: Build
    runs-on: ubuntu-latest
    env:
      IMAGE_NAME: docker.pkg.github.com/${{ github.repository }}/app
      IMAGE_TAG: ${{ github.sha }}

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Login to GitHub Packages
      env:
        TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        docker login docker.pkg.github.com -u $GITHUB_ACTOR -p $TOKEN

    - name: Build
      run: |
        docker build \
          -t $IMAGE_NAME:$IMAGE_TAG \
          -t $IMAGE_NAME:latest \
          .

    - name: Push image to GitHub Packages
      run: |
        docker push $IMAGE_NAME:latest
        docker push $IMAGE_NAME:$IMAGE_TAG

    - name: Logout
      run: |
        docker logout docker.pkg.github.com

GitHub Packages 20 :



, :


on:
  push:
    branches:
      - master

name: Test docker build

jobs:
  deploy:
    name: Build
    runs-on: ubuntu-latest
    env:
      IMAGE_NAME: docker.pkg.github.com/${{ github.repository }}/app
      IMAGE_TAG: ${{ github.sha }}

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Login to GitHub Packages
      env:
        TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        docker login docker.pkg.github.com -u $GITHUB_ACTOR -p $TOKEN

    - name: Pull latest images
      run: |
        docker pull $IMAGE_NAME:latest || true
        docker pull $IMAGE_NAME-builder-stage:latest || true

    - name: Images list
      run: |
        docker images

    - name: Build
      run: |
        docker build \
          --target builder \
          --cache-from $IMAGE_NAME-builder-stage:latest \
          -t $IMAGE_NAME-builder-stage \
          .
        docker build \
          --cache-from $IMAGE_NAME-builder-stage:latest \
          --cache-from $IMAGE_NAME:latest \
          -t $IMAGE_NAME:$IMAGE_TAG \
          -t $IMAGE_NAME:latest \
          .

    - name: Push image to GitHub Packages
      run: |
        docker push $IMAGE_NAME-builder-stage:latest
        docker push $IMAGE_NAME:latest
        docker push $IMAGE_NAME:$IMAGE_TAG

    - name: Logout
      run: |
        docker logout docker.pkg.github.com

, build. , - . . Docker c nodejs ( builder). , $IMAGE_NAME-builder-stage GitHub Packages, .



. .



тАФ Dockerfile, , Container Registry .


nodejs Angular-. Dockerfile.node


FROM node:12.16.2-alpine3.11
RUN apk --no-cache --update --virtual build-dependencies add \
    python \
    make \
    g++

Docker Hub:


docker build -t exsmund/node-for-angular -f Dockerfile.node .
docker push exsmund/node-for-angular:latest

Dockerfile :


FROM exsmund/node-for-angular:latest as builder
...

, , .



-. , , :


  • ;
  • ;
  • -;
  • Dockerfile, ;
  • CI/CD-;
  • .

, , Docker, . , , https://github.com/devopsprodigy/test-docker-build.


All Articles