在docker图像里面的gitlab-runner

时间:2018-05-18 10:12:34

标签: windows docker gitlab gitlab-ci-runner

我设置了一个Windows docker镜像并在我的Windows 10机器上启动它。 在运行的docker镜像中,在我的gitlab服务器上注册了gitlab runner。 问题是gitlab服务器看到了主机Windows机器的IP地址,结果就是它在线。

无论如何在交互式docker镜像中运行构建运行器吗?

这是我的dockerfile

# escape=`

FROM microsoft/windowsservercore

RUN @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

# wait for vs_installer.exe, vs_installerservice.exe
# or vs_installershell.exe because choco doesn't
RUN powershell -NoProfile -InputFormat None -Command `
    choco install git 7zip -y; `
    choco install visualcpp-build-tools `
            -y; `
    Write-Host 'Waiting for Visual C++ Build Tools to finish'; `
    Wait-Process -Name vs_installer

#WORKDIR C:\build
#CMD powershell -ExecutionPolicy Bypass -Command .\release.ps1

COPY entrypoint.bat entrypoint.bat

# Install Chocolatey
#RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET #"PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"    

# Register the GitLab Runner
COPY gitlab-runner-windows-amd64.exe /gitlab/gitlab-runner.exe
RUN /gitlab/gitlab-runner.exe install

SHELL ["cmd.exe", "/s", "/c", "C:\\entrypoint.bat"]

WORKDIR /code

ENTRYPOINT ["C:\\entrypoint.bat"]
CMD ["cmd"]

EXPOSE 443

和我的entrypoint.bat文件

@echo off
pushd C:
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat"
REM call "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
popd
%*

以下是我如何构建它

docker build -t windows .

以下是我如何运行它

docker run -it windows cmd

以下是我如何注册gitlab runner

C:\gitlab>gitlab-runner register --non-interactive --name "Windows docker builder" --url "https://gitlabserver/" --registration-token TOKEN --tag-list windows --executor shell
Registering runner... succeeded                     runner=XXX
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

在GitLab服务器上,我可以看到它是寄存器,但它显示的是Windows 10主机的IP地址,而不是docker里面的ip地址。 enter image description here

0 个答案:

没有答案