发布于 

gitlab-ci的模版

模块说明

  1. 在项目根目录添加.gitlab-ci.yml文件,内容:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    stages:
    - build

    build-code-job:
    stage: build
    script:
    - pwd
    - sh ./build.sh
    tags:
    - normal4
  2. 在项目根目录添加.dockerignore文件,内容保持跟.gitignore文件一致。

  3. 在项目目录添加build.sh脚本

    1
    2
    3
    4
    5
    6
    7
    8
    9
    #!/bin/bash

    NAME=blog

    docker build -t $NAME .

    docker-compose up -d --scale $NAME=2 --no-recreate

    docker-compose up -d --scale $NAME=1 --no-recreate
  4. 在项目目录添加Dockerfile

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    FROM node:18-alpine

    ENV TZ Asia/Shanghai

    RUN apk update && apk add bash && apk add tzdata && cp /usr/share/zoneinfo/${TZ} /etc/localtime \
    && echo ${TZ} > /etc/timezone \
    && apk del tzdata

    WORKDIR /home

    RUN addgroup --system --gid 1001 nodejs
    RUN adduser --system --uid 1001 stone-jin

    COPY ./package.json /home

    RUN npm install --registry=https://registry.npmmirror.com

    COPY . /home

    USER stone-jin

    EXPOSE 80

    CMD npm run server
  5. docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
version: '3'
services:
blog:
image: blog
restart: always
labels:
- "traefik.http.routers.blog.rule=Host(`home.fedfans.com`)"
networks:
- traefik_home_default
networks:
traefik_home_default:
external: true

如果你有什么意见和建议,可以点击: 反馈地址 进行反馈。