• Gitlab CI/CD


    参考链接:https://www.cnblogs.com/tianyaguoke/p/11219648.html

    1.安装Gitlab

    version: '3.6'
    services:
      web:
        image: 'registry.gitlab.cn/omnibus/gitlab-jh:latest'
        restart: always
        container_name: gitlab
        hostname: '192.168.1.2'
        environment:
          GITLAB_OMNIBUS_CONFIG: |
            external_url 'http://192.168.1.2:8090' #若有域名可以写域名
            gitlab_rails['gitlab_shell_ssh_port'] = 8022
            gitlab_rails['smtp_enable'] = true
            gitlab_rails['smtp_address'] = "smtp.163.com"
            gitlab_rails['smtp_port'] = 25
            gitlab_rails['smtp_user_name'] = "****@163.com"
            gitlab_rails['smtp_password'] = "123456"
            gitlab_rails['smtp_domain'] = "163.com"
            gitlab_rails['smtp_authentication'] = :login
            gitlab_rails['smtp_enable_starttls_auto'] = true
            gitlab_rails['gitlab_email_enabled'] = true
            gitlab_rails['gitlab_email_from'] = '*****@163.com'
            gitlab_rails['gitlab_email_display_name'] = 'gitlab'
        privileged: true
        ports:
          - '8090:8090'
          - '8022:22'
        volumes:
          - './config:/etc/gitlab'
          - './logs:/var/log/gitlab'
          - './data:/var/opt/gitlab'
        shm_size: '256m'
    docker-compose

    2.使用命令

    docker-compose up -d 创建容器

    3.访问Gitlab

    http://localhost:8090

    账号为root

    密码:

    使用powershell 输入 docker exec -it gitlab容器ID /bin/sh
    cat /etc/gitlab/initial_root_password 获取密码
     
    4.修改语言可以在设置中修改为中文,创建一个Test项目。
     
    5.注册gitlab runner
    mac安装runner 其他系统也类似 直接安装即可
    sudo curl --output /usr/local/bin/gitlab-runner "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64"
    拉取runner镜像
    gitlab-runner install
    gitlab-runner start
    gitlab-runner register ()
    注册时 需要下图gitlab项目中的网址和令牌。 在注册时 注意选择shell executor。
     

    6.注册完后修改一些东西

    在下图红色位置 修改Runner的运行未标记作业。因为可能yml中没有配置标记。


    7.在管理员界面配置去除默认使用DevOps


    8.开始新建一个WebApi项目进行提交代码进行流水线测试。

    dotnet new webapi --name Demo   # 新建一个webapi项目

    在VSCode中打开命令面板:Ctrl+Shift+P

    输入:ADD Docker Files to Workspace

      • 选择 ASP.Net Core
      • 选择 Linux
      • 80

    这边直接使用默认的dockerfile(在根目录下)

    FROM mcr.microsoft.com/dotnet/aspnet:6.0-focal AS base
    WORKDIR /app
    EXPOSE 80
    
    ENV ASPNETCORE_URLS=http://+:80
    
    # Creates a non-root user with an explicit UID and adds permission to access the /app folder
    # For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
    RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
    USER appuser
    
    FROM mcr.microsoft.com/dotnet/sdk:6.0-focal AS build
    WORKDIR /src
    COPY ["Demo.csproj", "./"]
    RUN dotnet restore "Demo.csproj"
    COPY . .
    WORKDIR "/src/."
    RUN dotnet build "Demo.csproj" -c Release -o /app/build
    
    FROM build AS publish
    RUN dotnet publish "Demo.csproj" -c Release -o /app/publish /p:UseAppHost=false
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    ENTRYPOINT ["dotnet", "Demo.dll"]

    配置docker-compose.yml(一样在根目录下)

    version: '3'
    
    services:
        web:
          build: .
          container_name: aspnetcore
          ports:
            - '8080:80'

    最后配置.gitlab-ci.yml

    test:
         script:
          - docker-compose up -d --build --force-recreate

    提交代码到gitlab

    git init 
    git remote add origin http:// #地址 
    git add . 
    git commit -m "Initial commit" 
    git push -u origin master

    这样就完成了。

    本地测试下

    成功。

  • 相关阅读:
    我所知道的JS调试
    css加载会造成阻塞吗?
    移动端图片上传旋转、压缩的解决方案
    JS组件系列——自己动手扩展BootstrapTable的 冻结列 功能:彻底解决高度问题
    什么是BFC
    CSS中margin边界叠加问题及解决方案
    JavaScript 中回调地狱的今生前世
    用css实现自定义虚线边框
    仿淘宝,京东红包雨
    css3实现可以计算的自适应布局——calc()
  • 原文地址:https://www.cnblogs.com/cdjbolg/p/16213741.html
Copyright © 2020-2023  润新知