# 1、准备公网上的测试数据库。
之前我们在Visual Studio里面调试的时候,使用的都是localhost的数据库。现在需要在公网上准备一个SQL Server。然后执行下面的步骤
1)把Study.BlazorOne.DbMigrator设置为启动项目;
2)修改appsettings.json中的连接字符串
将本地localhost的配置注释掉,加上公网的连接字符串
3)运行DbMigrator
# 2、为Study.BlazorOne.Blazor项目启用Dockers支持
# 3、在解决方案根目录下放置自动集成的配置文件
# 4、签入代码,尝试首次让gitlab的runner来构建Docker镜像
Gitlab中显示的完整信息如下
Running with gitlab-runner 15.11.0 (436955cb) on gr05 YozfsKoh, system ID: r_QId06ioCL2oU Preparing the "docker" executor 00:01 Using Docker executor with image proget.abcdefg.cn/gitlab/runner:7.0 ... Authenticating with credentials from $DOCKER_AUTH_CONFIG Pulling docker image proget.abcdefg.cn/gitlab/runner:7.0 ... Using docker image sha256:79e3cb48a17b32ddebfbd69a5cee6f9f4cc0c9c3fb0dd669bd8bed8a6690de95 for proget.abcdefg.cn/gitlab/runner:7.0 with digest proget.loda.net.cn/gitlab/runner@sha256:a467584163ae036b191065de98fde78f378ef84ef06feef5be66f272e0b7504b ... Preparing environment 00:01 Running on runner-yozfskoh-project-8-concurrent-0 via gr02... Getting source from Git repository 00:01 Fetching changes with git depth set to 20... Initialized empty Git repository in /builds/YozfsKoh/0/study/blazor-one/.git/ Created fresh repository. Checking out 42f160af as detached HEAD (ref is main)... Skipping Git submodules setup Executing "step_script" stage of the job script 00:12 Using docker image sha256:79e3cb48a17b32ddebfbd69a5cee6f9f4cc0c9c3fb0dd669bd8bed8a6690de95 for proget.abcdefg.cn/gitlab/runner:7.0 with digest proget.abcdefg.cn/gitlab/runner@sha256:a467584163ae036b191065de98fde78f378ef84ef06feef5be66f272e0b7504b ... $ docker login -u $DOCKER_DEV_USERNAME -p $DOCKER_DEV_PASSWORD $DOCKER_DEV_SERVER WARNING! Using --password via the CLI is insecure. Use --password-stdin. WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded $ cd . $ docker build -t $BLAZOR_DEV_REPO:$BLAZORONE_IMAGE_TAG -f src/Study.BlazorOne.Blazor/Dockerfile --no-cache . Step 1/24 : FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base 7.0: Pulling from dotnet/aspnet Get "https://mcr.microsoft.com/v2/dotnet/aspnet/manifests/sha256:136deb59fc62f52d7d9dde928cdefeaa7b25ef72c4e8bc8c56e676c6b5d7ab53": net/http: TLS handshake timeout Cleaning up project directory and file based variables 00:01 ERROR: Job failed: exit code 1
卡在了最后一步,就是从microsoft.com下载aspnet:7.0的基础镜像的时候,TLS握手超时。
简单,我们在自己的私有docker registry中放置这个aspnet:7.0的基础镜像即可。
然后修改Study.BlazorOne.Blazor项目的Dockerfile文件,改动第3行和第8行,指向我们修改过后的基础镜像:
签入代码。Gitlab的Runner立即尝试自动构建。
# 5、看起来顺利构建,但是还是卡在最后一步:
a0acdda47b2a: Retrying in 1 second e2fed13a1ac3: Retrying in 1 second 03cef3692ade: Retrying in 1 second 39d424e26f18: Waiting unknown: Could not resolve ProGet feed "study". Docker repository names in ProGet must include the feed as a prefix. Example: MyFeed/library/ubuntu Cleaning up project directory and file based variables 00:01 ERROR: Job failed: exit code 1
这个错误的意思,是我们指定的路径是用于上传NuGet包的,不能用于推送Docker镜像。重新在ProGet里面创建新的Feed,用于储存Docker的构建的成果。然后修改.gitlab-ci.yml中的变量。修改了下图第9行的URL:
签入代码,Gitlab中立即调用了Runner,成功自动构建。
# 6、上图显示,自动集成任务的第一步,构建Docker镜像是成功了,第二步报错。
错误信息如下:
Running with gitlab-runner 15.11.0 (436955cb) on gr05 YozfsKoh, system ID: r_QId06ioCL2oU Preparing the "docker" executor 00:01 Using Docker executor with image proget.abcdefg.cn/gitlab/runner:7.0 ... Authenticating with credentials from $DOCKER_AUTH_CONFIG Pulling docker image proget.abcdefg.cn/gitlab/runner:7.0 ... Using docker image sha256:79e3cb48a17b32ddebfbd69a5cee6f9f4cc0c9c3fb0dd669bd8bed8a6690de95 for proget.abcdefg.cn/gitlab/runner:7.0 with digest proget.abcdefg.cn/gitlab/runner@sha256:a467584163ae036b191065de98fde78f378ef84ef06feef5be66f272e0b7504b ... Preparing environment 00:01 Running on runner-yozfskoh-project-8-concurrent-0 via gr02... Getting source from Git repository 00:01 Fetching changes with git depth set to 20... Reinitialized existing Git repository in /builds/YozfsKoh/0/study/blazor-one/.git/ Checking out 0087e923 as detached HEAD (ref is main)... Skipping Git submodules setup Restoring cache 00:00 Checking cache for default-protected... No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. Successfully extracted cache Executing "step_script" stage of the job script 00:01 Using docker image sha256:79e3cb48a17b32ddebfbd69a5cee6f9f4cc0c9c3fb0dd669bd8bed8a6690de95 for proget.abcdefg.cn/gitlab/runner:7.0 with digest proget.abcdefg.cn/gitlab/runner@sha256:a467584163ae036b191065de98fde78f378ef84ef06feef5be66f272e0b7504b ... $ mkdir -p ~/.ssh $ chmod 700 ~/.ssh $ cd /root/.ssh $ cp /home/gitlab-runner/ssh/* . $ echo "部署到Brain测试站……" 部署到Brain测试站…… $ cd /home/gitlab-runner/scripts $ bash ssh-deploy.sh blazor_one_test 8606 80 $BLAZOR_DEV_REPO:$BLAZORONE_IMAGE_TAG amisoft $DOCKER_DEV_SERVER $DOCKER_DEV_USERNAME $DOCKER_DEV_PASSWORD $SSH_AUTO_LOGIN_USER $TEST_APP_SERVER docker容器实例名称: blazor_one_test 目标服务器对外端口号 8606 docker容器开放端口号 80 docker镜像URL proget.abcdefg.cn/study-images/blazor:15 容器启动配置环境 amisoft Docker服务器DNS名称 proget.abcdefg.cn 登入Docker服务器的用户名称 usernamexxxxx 登入Docker服务器的密码 myPassword SSH自动登入目标服务器使用的用户名 username SSH自动登入的目标服务器 proget.abcdefg.cn 在服务器上执行的命令是 docker run -d --privileged=true --restart=always -d --name blazor_one_test -v /mnt/data/yee-change:/var/config -e ASPNETCORE_ENVIRONMENT=amisoft -p 8606:80 proget.abcdefg.cn/study-images/blazor:15 Pseudo-terminal will not be allocated because stdin is not a terminal. Warning: Permanently added 'proget.abcdefg.cn,47.106.133.5' (ECDSA) to the list of known hosts. Permission denied, please try again. Permission denied, please try again. username@proget.abcdefg.cn: Permission denied (publickey,password). Cleaning up project directory and file based variables 00:01 ERROR: Job failed: exit code 1
很清楚,SSH登入服务器的时候,被拒绝了。
# 7、让Gitlab的Runner能自动登入用于运行容器的测试服务器
很简单,在服务器上创建名为tommy的linux用户,在该用户的/home/tommy/.ssh文件夹的密钥文件里,加入我们的公钥
# 8、再次触发自动集成
得到如下错误:
Welcome to Alibaba Cloud Elastic Compute Service ! The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. bash: /home/great/docker/gitlab/runner/deploy.sh: No such file or directory Cleaning up project directory and file based variables 00:01 ERROR: Job failed: exit code 1
上述错误很简单,是服务器的/home/greate/docker/gitlab/runner这个目录下,没有deploy.sh这个脚本,这个脚本的内容如下:
#!/bin/bash conName=$1 eonPort=$2 conPort=$3 images=$4 count=`docker ps -a |grep "$conName"|wc -l ` if [ $count -eq 0 ];then echo "$conName container is not exit" else id=$(docker ps -a |grep "$conName" |awk '{print $1}') for i in $id do docker stop $i docker rm $i done fi docker rmi $images docker login -u david -p NXbdusoeiu*2349243_ded docker.amicap.cn docker run --restart=always -d --name $conName -v /mnt/config:/var/config -e ASPNETCORE_ENVIRONMENT=$5 -p $eonPort:$conPort $images
拷贝到服务器后,记得改一下权限。
# 9、再次触发自动集成
在Gitlab中的完整日志控制台输出如下
Running with gitlab-runner 15.11.0 (436955cb) on gr05 YozfsKoh, system ID: r_QId06ioCL2oU Preparing the "docker" executor 00:01 Using Docker executor with image proget.abcdefg.cn/gitlab/runner:7.0 ... Authenticating with credentials from $DOCKER_AUTH_CONFIG Pulling docker image proget.abcdefg.cn/gitlab/runner:7.0 ... Using docker image sha256:79e3cb48a17b32ddebfbd69a5cee6f9f4cc0c9c3fb0dd669bd8bed8a6690de95 for proget.abcdefg.cn/gitlab/runner:7.0 with digest proget.abcdefg.cn/gitlab/runner@sha256:a467584163ae036b191065de98fde78f378ef84ef06feef5be66f272e0b7504b ... Preparing environment 00:00 Running on runner-yozfskoh-project-8-concurrent-0 via gr02... Getting source from Git repository 00:01 Fetching changes with git depth set to 20... Reinitialized existing Git repository in /builds/YozfsKoh/0/study/blazor-one/.git/ Checking out b34700f3 as detached HEAD (ref is main)... Skipping Git submodules setup Restoring cache 00:01 Checking cache for default-protected... No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. Successfully extracted cache Executing "step_script" stage of the job script 00:01 Using docker image sha256:79e3cb48a17b32ddebfbd69a5cee6f9f4cc0c9c3fb0dd669bd8bed8a6690de95 for proget.abcdefg.cn/gitlab/runner:7.0 with digest proget.abcdefg.cn/gitlab/runner@sha256:a467584163ae036b191065de98fde78f378ef84ef06feef5be66f272e0b7504b ... $ mkdir -p ~/.ssh $ chmod 700 ~/.ssh $ cd /root/.ssh $ cp /home/gitlab-runner/ssh/* . $ echo "部署到Brain测试站……" 部署到Brain测试站…… $ cd /home/gitlab-runner/scripts $ bash ssh-deploy.sh blazor_one_test 8606 80 $BLAZOR_DEV_REPO:$BLAZORONE_IMAGE_TAG amisoft $DOCKER_DEV_SERVER $DOCKER_DEV_USERNAME $DOCKER_DEV_PASSWORD $SSH_AUTO_LOGIN_USER $TEST_APP_SERVER docker容器实例名称: blazor_one_test 目标服务器对外端口号 8606 docker容器开放端口号 80 docker镜像URL proget.abcdefg.cn/study-images/blazor:17 容器启动配置环境 amisoft Docker服务器DNS名称 proget.abcdefg.cn 登入Docker服务器的用户名称 username@docker 登入Docker服务器的密码 MySecretPassword SSH自动登入目标服务器使用的用户名 great SSH自动登入的目标服务器 proget.abcdefg.cn 在服务器上执行的命令是 docker run -d --privileged=true --restart=always -d --name blazor_one_test -v /mnt/data/yee-change:/var/config -e ASPNETCORE_ENVIRONMENT=amisoft -p 8606:80 proget.abcdefg.cn/study-images/blazor:17 Pseudo-terminal will not be allocated because stdin is not a terminal. Warning: Permanently added 'proget.abcdefg.cn,47.106.133.5' (ECDSA) to the list of known hosts. Permission denied, please try again. Permission denied, please try again. great@proget.abcdefg.cn: Permission denied (publickey,password). Cleaning up project directory and file based variables 00:00 ERROR: Job failed: exit code 1
# 10、如果Gitlab的Runner不联络服务器,不领取工作
可以执行下面两个命令
root@dev-server:~# docker exec -it gr02 gitlab-runner verify Runtime platform arch=amd64 os=linux pid=7 revision=436955cb version=15.11.0 Running in system-mode. Verifying runner... is alive runner=YozfsKoh root@dev-server:~# docker exec -it gr02 gitlab-runner restart Runtime platform arch=amd64 os=linux pid=28 revision=436955cb version=15.11.0
# 11、登入被拒绝
查了很多文件,也没搞定。于是换了一台测试服务器。成功发布
Running with gitlab-runner 15.11.0 (436955cb) on gr05 YozfsKoh, system ID: r_QId06ioCL2oU Preparing the "docker" executor 00:01 Using Docker executor with image proget.abcdefg.cn/gitlab/runner:7.0 ... Authenticating with credentials from $DOCKER_AUTH_CONFIG Pulling docker image proget.abcdefg.cn/gitlab/runner:7.0 ... Using docker image sha256:79e3cb48a17b32ddebfbd69a5cee6f9f4cc0c9c3fb0dd669bd8bed8a6690de95 for proget.abcdefg.cn/gitlab/runner:7.0 with digest proget.abcdefg.cn/gitlab/runner@sha256:a467584163ae036b191065de98fde78f378ef84ef06feef5be66f272e0b7504b ... Preparing environment 00:00 Running on runner-yozfskoh-project-8-concurrent-0 via gr02... Getting source from Git repository 00:01 Fetching changes with git depth set to 20... Reinitialized existing Git repository in /builds/YozfsKoh/0/study/blazor-one/.git/ Checking out 832423e6 as detached HEAD (ref is main)... Skipping Git submodules setup Restoring cache 00:01 Checking cache for default-protected... No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. Successfully extracted cache Executing "step_script" stage of the job script 00:39 Using docker image sha256:79e3cb48a17b32ddebfbd69a5cee6f9f4cc0c9c3fb0dd669bd8bed8a6690de95 for proget.abcdefg.cn/gitlab/runner:7.0 with digest proget.abcdefg.cn/gitlab/runner@sha256:a467584163ae036b191065de98fde78f378ef84ef06feef5be66f272e0b7504b ... $ mkdir -p ~/.ssh $ chmod 700 ~/.ssh $ cd /root/.ssh $ cp /home/gitlab-runner/ssh/* . $ echo "部署到Brain测试站……" 部署到Brain测试站…… $ cd /home/gitlab-runner/scripts $ bash ssh-deploy.sh blazor_one_test 8606 80 $BLAZOR_DEV_REPO:$BLAZORONE_IMAGE_TAG AliyunTest $DOCKER_DEV_SERVER $DOCKER_DEV_USERNAME $DOCKER_DEV_PASSWORD $SSH_AUTO_LOGIN_USER $TEST_APP_SERVER docker容器实例名称: blazor_one_test 目标服务器对外端口号 8606 docker容器开放端口号 80 docker镜像URL proget.abcdefg.cn/study-images/blazor:22 容器启动配置环境 AliyunTest Docker服务器DNS名称 proget.abcdefg.cn 登入Docker服务器的用户名称 username@docker 登入Docker服务器的密码 MySecret123 SSH自动登入目标服务器使用的用户名 david SSH自动登入的目标服务器 172.16.0.199 在服务器上执行的命令是 docker run -d --privileged=true --restart=always -d --name blazor_one_test -v /mnt/data/yee-change:/var/config -e ASPNETCORE_ENVIRONMENT=AliyunTest -p 8606:80 proget.abcdefg.cn/study-images/blazor:22 Pseudo-terminal will not be allocated because stdin is not a terminal. Warning: Permanently added '172.16.0.199' (ECDSA) to the list of known hosts. Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-72-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Sun May 21 07:07:31 PM UTC 2023 System load: 1.8740234375 Usage of /: 43.6% of 97.87GB Memory usage: 21% Swap usage: 0% Temperature: 76.0 C Processes: 495 Users logged in: 1 IPv4 address for br-520215db1f30: 172.20.0.1 IPv4 address for br-5be0717938c9: 172.19.0.1 IPv4 address for br-76c941d48dc2: 10.10.3.1 IPv4 address for br-f98ed0d36211: 172.18.0.1 IPv4 address for docker0: 172.17.0.1 IPv4 address for enp86s0: 172.16.0.199 * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s just raised the bar for easy, resilient and secure K8s cluster deployment. https://ubuntu.com/engage/secure-kubernetes-at-the-edge Expanded Security Maintenance for Applications is not enabled. 1 update can be applied immediately. To see these additional updates run: apt list --upgradable Enable ESM Apps to receive additional future security updates. See https://ubuntu.com/esm or run: sudo pro status 4a109ae04f06 4a109ae04f06 Untagged: proget.abcdefg.cn/study-images/blazor:22 Untagged: proget.abcdefg.cn/study-images/blazor@sha256:44721bba14a6d98370582bb875eedb8a20809febe60e64169fee767b5edee0de Deleted: sha256:0979c4238750443e1e0174fb1dfae269fac53e701eea075ec09baa8e921ff258 Deleted: sha256:bc05348c1108ee9a0c7d92cbd13fab85cdec49a9e540b462e06298f1eb82b3fb Deleted: sha256:b6692a838b82591c27920dee0e947bb5b221843b983644e2b4555e5e0f37362b Deleted: sha256:5012a44cce34ce6e752a17db8d5c935e336e84f78239389e756d1163790c1fb5 Deleted: sha256:08c9e070d99c38128ba4615a7f30a31349a09f95323e075f1456fd97a9a3e8e5 Deleted: sha256:6a3a81deb5e13495f765faaccceab8a4f46a82caa7ae4968a7bc7fea973431dc Deleted: sha256:86de30b98c0d4a0999180ff2971a9a7269596d90d9484048f49757c1ac90ec35 Deleted: sha256:9221e97be3386aa9ad1d2c386919536261cb30ed0117bc300894b542f344cd9d WARNING! Using --password via the CLI is insecure. Use --password-stdin. WARNING! Your password will be stored unencrypted in /home/david/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded Unable to find image 'proget.abcdefg.cn/study-images/blazor:22' locally 22: Pulling from study-images/blazor 9e3ea8720c6d: Already exists 2436f232d040: Already exists 9a2730c0a140: Already exists 6bb6cfc88137: Already exists 8bc8046fd854: Already exists 5016cd0016e4: Already exists 59395839e470: Already exists 19dc23f69568: Already exists 71f1b4b01e35: Already exists 1868690bc889: Already exists 371a028335d5: Already exists c110905bfc27: Already exists 63d18f70c3d6: Already exists 424a907a98a6: Already exists a2552f8f5db0: Already exists cd1c5a79ba5c: Already exists aefe6775f233: Already exists 31a7c2980e89: Already exists df0689172fdf: Pulling fs layer 658b7d3a4525: Pulling fs layer df0689172fdf: Verifying Checksum df0689172fdf: Pull complete 658b7d3a4525: Verifying Checksum 658b7d3a4525: Download complete 658b7d3a4525: Pull complete Digest: sha256:44721bba14a6d98370582bb875eedb8a20809febe60e64169fee767b5edee0de Status: Downloaded newer image for proget.abcdefg.cn/study-images/blazor:22 bc571017f1006bdaed1c000110199d95d0d5c1a6cd7609bc9c26b7a938b9dd29 Saving cache for successful job 00:01 Creating cache default-protected... WARNING: node_modules/: no matching files. Ensure that the artifact path is relative to the working directory (/builds/YozfsKoh/0/study/blazor-one) Archive is up to date! Created cache Cleaning up project directory and file based variables 00:01 Job succeeded
12、在测试服务器上,运行docker logs blazor_one_test
发现不停的报如下错误:
[18:57:26 FTL] Host terminated unexpectedly! Volo.Abp.AbpInitializationException: An error occurred during ConfigureServicesAsync phase of the module Volo.Abp.OpenIddict.AbpOpenIddictAspNetCoreModule, Volo.Abp.OpenIddict.AspNetCore, Version=7.2.2.0, Culture=neutral, PublicKeyToken=null. See the inner exception for details. ---> System.IO.FileNotFoundException: Signing Certificate couldn't found: /app/authserver.pfx at Study.BlazorOne.Blazor.BlazorOneBlazorModule.GetSigningCertificate(IWebHostEnvironment hostingEnv, IConfiguration configuration) in /src/src/Study.BlazorOne.Blazor/BlazorOneBlazorModule.cs:line 357 at Study.BlazorOne.Blazor.BlazorOneBlazorModule.<>c__DisplayClass0_0.<PreConfigureServices>b__3(OpenIddictServerBuilder builder) in /src/src/Study.BlazorOne.Blazor/BlazorOneBlazorModule.cs:line 128 at Volo.Abp.Options.PreConfigureActionList`1.Configure(TOptions options) at Microsoft.Extensions.DependencyInjection.ServiceCollectionPreConfigureExtensions.ExecutePreConfiguredActions[TOptions](IServiceCollection services, TOptions options) at Volo.Abp.OpenIddict.AbpOpenIddictAspNetCoreModule.<>c__DisplayClass1_0.<AddOpenIddictServer>b__0(OpenIddictServerBuilder builder) at Microsoft.Extensions.DependencyInjection.OpenIddictServerExtensions.AddServer(OpenIddictBuilder builder, Action`1 configuration) at Volo.Abp.OpenIddict.AbpOpenIddictAspNetCoreModule.AddOpenIddictServer(IServiceCollection services) at Volo.Abp.OpenIddict.AbpOpenIddictAspNetCoreModule.ConfigureServices(ServiceConfigurationContext context) at Volo.Abp.Modularity.AbpModule.ConfigureServicesAsync(ServiceConfigurationContext context) at Volo.Abp.AbpApplicationBase.ConfigureServicesAsync() --- End of inner exception stack trace --- at Volo.Abp.AbpApplicationBase.ConfigureServicesAsync() at Volo.Abp.AbpApplicationFactory.CreateAsync[TStartupModule](IServiceCollection services, Action`1 optionsAction) at Microsoft.Extensions.DependencyInjection.ServiceCollectionApplicationExtensions.AddApplicationAsync[TStartupModule](IServiceCollection services, Action`1 optionsAction) at Microsoft.Extensions.DependencyInjection.WebApplicationBuilderExtensions.AddApplicationAsync[TStartupModule](WebApplicationBuilder builder, Action`1 optionsAction) at Study.BlazorOne.Blazor.Program.Main(String[] args) in /src/src/Study.BlazorOne.Blazor/Program.cs:line 36
未完待续。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)