본문 바로가기
DevOps/컨테이너

(Jenkins) Dockerfile 을 통한 python 이 설치된 Jenkins Agent 도커 컨테이너 이미지 만들기

by 정보봇따리 2022. 3. 7.
728x90
반응형
SMALL

1. dockerfile 을 만든다

https://www.gyanblog.com/python/how-install-python-windows-command-line-Dockerfile/

 

How to Install Python from command line and Docker on Windows

How to install Python from command line using pyenv, and we will also create a Dockerfile for Windows

www.gyanblog.com

 

*활용하는 이미지는 도커 jenkins agent 임

*도커 jenkins agent 는 windowsservercore-1809 의 확장이며, git 이 설치되어 있음 !!!!  일 하나 줄었음 ㅎ_ㅎ 

FROM jenkins/inbound-agent:windowsservercore-1809

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN New-Item C:/temp -ItemType Directory; \
  New-Item C:/data -ItemType Directory;
WORKDIR C:/temp

ENV PYTHON_VERSION 3.9.1
ENV PYTHON_RELEASE 3.9.1

RUN $url = ('https://www.python.org/ftp/python/{0}/python-{1}-amd64.exe' -f $env:PYTHON_RELEASE, $env:PYTHON_VERSION); \
	Write-Host ('Downloading {0} ...' -f $url); \
	[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
	Invoke-WebRequest -Uri $url -OutFile 'python.exe'; \
	\
	Write-Host 'Installing ...'; \
# https://docs.python.org/3.7/using/windows.html#installing-without-ui
	Start-Process python.exe -Wait \
		-ArgumentList @( \
			'/quiet', \
			'InstallAllUsers=1', \
			'TargetDir=C:\Python39', \
			'PrependPath=1', \
			'Shortcuts=0', \
			'Include_doc=0', \
			'Include_pip=0', \
			'Include_test=0' \
		); \
	\
#the installer updated PATH, so we should refresh our local value
	$env:PATH = [Environment]::GetEnvironmentVariable('PATH', [EnvironmentVariableTarget]::Machine); \
	\
	Write-Host 'Verifying install ...'; \
	Write-Host '  python --version'; python --version; \
	\
	Write-Host 'Removing ...'; \
	Remove-Item python.exe -Force; \
	\
	Write-Host 'Complete.'

# https://github.com/pypa/get-pip
ENV PYTHON_GET_PIP_URL https://github.com/pypa/get-pip/raw/d59197a3c169cef378a22428a3fa99d33e080a5d/get-pip.py
ENV PYTHON_GET_PIP_SHA256 421ac1d44c0cf9730a088e337867d974b91bdce4ea2636099275071878cc189e

RUN Write-Host ('Downloading get-pip.py ({0}) ...' -f $env:PYTHON_GET_PIP_URL); \
	[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
	Invoke-WebRequest -Uri $env:PYTHON_GET_PIP_URL -OutFile 'get-pip.py'; \
	Write-Host ('Verifying sha256 ({0}) ...' -f $env:PYTHON_GET_PIP_SHA256); \
	if ((Get-FileHash 'get-pip.py' -Algorithm sha256).Hash -ne $env:PYTHON_GET_PIP_SHA256) { \
		Write-Host 'FAILED!'; \
		exit 1; \
	}; \
	\
	Write-Host ('Installing pip ...'); \
	python get-pip.py \
		--disable-pip-version-check \
		--no-cache-dir \
	; \
	Remove-Item get-pip.py -Force; \
	\
	Write-Host 'Verifying pip install ...'; \
	pip --version; \
	\
	Write-Host 'Complete.'

 

2. 이미지를 빌드한다

-편의상 Dockerfile 이 있는 디렉토리에서 실행했음

docker build --tag jenkinsagentpython39 ./

도커파일에 작성한 내용들을 한 줄 씩 수행 중임

3. Docker Desktop 에 이미지 추가 된 것 확인

 

 

4. Docker Run

 

docker run jenkinsagentpython39 -Url http://Jenkins:8080 -WorkDir "C:/Users/jenkins/Agent" -Secret [***] -Name docker-py-1

 

4-1. 기능 확인 

agent 연결 됨
파이썬 정상 설치

728x90
반응형
LIST