# 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. [email protected]: 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文件夹的密钥文件里,加入我们的公钥
标签:proget,abcdefg,cn,runner,Study,gitlab,BlazorOne,公网,docker From: https://www.cnblogs.com/amisoft/p/17417701.html