dotnet new webapi --name Demo
在Program中修改启动地址:.UseUrls("*:80")
4.Dockerfile配置在VSCode中打开命令面板:Ctrl+Shift+P
输入:ADD Docker Files to Workspace
选择 ASP.Net Core
选择 Linux
80
默认配置可能有问题,修改Dockerfile文件,配置如下
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env WORKDIR /app # Copy csproj and restore as distinct layers COPY *.csproj ./ RUN dotnet restore # Copy everything else and build COPY . ./ RUN dotnet publish -c Release -o out # Build runtime image FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 WORKDIR /app COPY --from=build-env /app/out . EXPOSE 80 ENTRYPOINT ["dotnet", "Demo.dll"]确保文件在项目根目录下
5.配置docker-compose.yml在项目根目录下新建docker-compose.yml文件
添加配置如下,格式非常重要
version: '3' services: web: build: . container_name: aspnetcore ports: - '8080:80' 6.配置.gitlab-ci.yml在项目根目录下新建.gitlab-ci.yml文件
添加配置如下
rtest: script: - docker-compose up -d --build --force-recreate 7.在GitLab上添加一个新项目 8.GitLib Runner安装环境:win10
下载地址
注册一个runner
使用Powershell运行:./gitlab-runner.exe register
输入gitlab地址:
输入令牌:在gitlab的项目=>设置=>CI/CD=>Runner中 找到注册令牌
输出描述:test
输入tags:beta
输入excutor方式:shell
安装:gitlab-runner.exe install
启动:gitlab-runner.exe start
9.提交代码到gitlab每次提交会触发gitlab runner,实现自动化部署
git命令如下
git init git remote add origin ssh://地址 git add . git commit -m "Initial commit" git push -u origin master 10.在GitLab上查看运行状态 11.本地运行::8080/api/values