蛮子哥 蛮子哥
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • ArgoCD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

蛮子哥

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • ArgoCD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • ansible系列文章

  • Kubernetes笔记

  • elk

  • jenkins

  • GitLabCI_CD

    • Gitlab ci与Jenkins对比
    • GitLabRunner简介
    • GitLabRunner安装
    • GitLabRunner注册
    • Runner-命令
    • 运行流水线任务
    • 集成构建工具
    • 制品库集成
    • 按时间统计GitLab所有用户代码提交量
    • gitlab ci部署web程序示例
    • gitlab部署

      • docker部署gitlab
      • rpm包部署gitlab
      • k8s yaml部署gitlab
      • gitlabci部署kubernetes应用程序示例
  • AI编程

  • 提示词

  • ArgoCD

  • 专题
  • GitLabCI_CD
  • gitlab部署
蛮子哥
2025-05-21

gitlabci部署kubernetes应用程序示例

# 创建Dockerfile文件

FROM docker.cnb.cool/zzppjj/docker-images/php:7.2.34-fpm-alpine

WORKDIR /app
ENV TZ=Asia/Shanghai

# === 重点修改这里 ===
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
    sed -i 's/mirrors.ustc.edu.cn/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
    apk update && \
    apk add --no-cache \
        autoconf g++ libtool make \
        curl-dev libxml2-dev linux-headers \
        freetype-dev libjpeg-turbo-dev libpng-dev

# 后面部分保持不变(建议拆分 RUN)
RUN docker-php-ext-install -j2 zip

RUN docker-php-ext-configure gd \
    --with-freetype-dir=/usr/include/freetype2 \
    --with-jpeg-dir=/usr/include/ && \
    docker-php-ext-install -j2 gd

RUN docker-php-ext-install -j$(nproc) bcmath mysqli pdo_mysql

RUN apk add --no-cache nginx && mkdir -p /run/nginx

COPY docker/site.conf /etc/nginx/conf.d/default.conf
COPY . .
COPY docker/start.sh /start.sh

RUN chmod +x /start.sh && \
    chown -R www-data:www-data /app

EXPOSE 80
CMD ["/start.sh"]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

docker目录下内容

# site.conf
server {
    listen 80;
    server_name localhost;
    root /app/public;

    client_max_body_size 50m;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    add_header 'Access-Control-Allow-Headers' 'X-CSRF-Token';

    index index.html index.htm index.php;

    charset utf-8;

    location / { 
      if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?s=/$1  last;
      }
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        root /app/public;
        fastcgi_pass                  127.0.0.1:9000;
        fastcgi_index                 index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include                       fastcgi_params;
    }

    #location ~ /\.(?!well-known).* {
    #    deny all;
   # }
   # location ~* \.(sh)$ {
   #  deny all;    
   # }
}
# start.sh
nginx
php-fpm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

# 在代码仓库创建.gitlab-ci.yml文件

variables:
  IMAGE_NAME: "docker.cnb.cool/zzppjj/docker-images/litghtpicture"
  IMAGE_TAG: "$CI_COMMIT_SHORT_SHA"
  CONFIG_REPO: "git@192.168.51.50:root/argo-demo.git"

stages:
  - build
  - deploy

build:
  stage: build
  image: docker:24.0
  services:
    - docker.cnb.cool/zzppjj/docker-images/docker:24.0-dind
  script:
    - docker login -u cnb docker.cnb.cool -p 01d21Lwxp6gMZBcf0o7BnPeaNgM
    - docker build -t $IMAGE_NAME:$IMAGE_TAG -t $IMAGE_NAME:latest .
    - docker push $IMAGE_NAME:$IMAGE_TAG
    - docker push $IMAGE_NAME:latest
  only:
    - main

update-manifests:
  stage: deploy
  image: docker.cnb.cool/zzppjj/docker-images/git  # 留着没事,等以后换了 Docker Executor 会自动生效
  needs: ["build"]
  script:
    # 1. 删掉了 apk add --no-cache git openssh-client (因为宿主机已经装好了)
    - git config --global user.email "ci@gitlab.com"
    - git config --global user.name "GitLab CI"
    
    - git clone $CONFIG_REPO
    - cd argo-demo
    
    - cd manifests
    - |
        find . -type f \( -name "*.yaml" -o -name "*.yml" \) | xargs sed -i "s|image: .*picture:[^[:space:]]*|image: $IMAGE_NAME:$IMAGE_TAG|g"
    
    - git add .
    - |
        git diff --cached --quiet || git commit -m "chore: update image $IMAGE_NAME to $IMAGE_TAG [skip ci]"
    - git push origin main
  only:
    - main
  environment: production
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
微信 支付宝
上次更新: 2026/05/21, 21:01:23

← k8s yaml部署gitlab OpenCode-CLI配置→

最近更新
01
kubernetes证书续签到100年
05-04
02
istio入门
04-29
03
ES故障排查命令
04-29
更多文章>
Theme by Vdoing | Copyright © 2019-2026 | 点击查看十年之约 | 鄂ICP备2024072800号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式