๋กœ์ผ“๐Ÿพ
article thumbnail

 

 

ํ˜„์žฌ ๊ธ€์€ ์ƒํŽธ์—์„œ ์ด์–ด์ง‘๋‹ˆ๋‹ค.
๋“ค์–ด๊ฐ€๊ธฐ ์•ž์„œ ํ•ด๋‹น ๊ธ€์—์„œ๋Š” C Compiler ์— ๋Œ€ํ•œ ์ง€์‹์„ ํ•„์š”๋กœ ํ•ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ „ C Compiler ์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์ง€ ๋ชปํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ‹€๋ฆฐ ๋ถ€๋ถ„์ด ์žˆ์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์–ธ์ œ๋“ ์ง€ ์ง€์ ๋ฐ”๋ž๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  Github Action ๊ณผ ๊ด€๋ จ๋œ ๊ฐœ๋… ๋ถ€๋ถ„์€ ๋”ฐ๋กœ ์„ค๋ช…ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

 

 

์‹œ๋‚˜๋ฆฌ์˜ค๋Š” ํฌ๊ฒŒ Local ์˜์—ญ๊ณผ Remote(Git Runner) ์˜์—ญ์œผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์‹œ๋‚˜๋ฆฌ์˜ค ๋„์‹ํ™”

 

 

Local


 

Local ์˜์—ญ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด๋ณด์ฃ . Local ์˜์—ญ์—์„  ๋ฏธ๋ฆฌ Python ์„ ๋นŒ๋“œ ํ•œ ํ›„์— Artifacts Repository ์— ์—…๋กœ๋“œ ํ•ฉ๋‹ˆ๋‹ค.

Official Setup Python ์•ก์…˜์„ ๋ณด๋ฉด versions-manifest.json ์— Python ์„ ๋‹ค์šด๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” URL ์ด ๋ช…์‹œ๋˜์–ด ์žˆ์ฃ .

 

์ œ Local ์€ MacOS ์ด๊ณ , ํ•„์š”ํ•œ ์šด์˜์ฒด์ œ๋Š” Linux ์ด๊ธฐ ๋•Œ๋ฌธ์— Docker Buildx ๋ฅผ ํ†ตํ•ด Python Build ๋ฅผ ์ง„ํ–‰ํ•  ๊ฒ๋‹ˆ๋‹ค.

 

์‚ฌ์šฉํ•  Dockerfile ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

FROM ubuntu:jammy

ENV VERSION="3.11.9"

RUN apt update -y \
      && apt install -y gcc pkg-config make unzip wget vim curl build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev

RUN useradd -m -s /bin/bash runner

USER runner

WORKDIR /home/runner

COPY ../make-python.sh make-python.sh

CMD ["bash", "make-python.sh"]

 

Python Build ๋ฅผ ์ง„ํ–‰ํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ apt ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ ํ•ฉ๋‹ˆ๋‹ค. ์ดํ›„ Python ์„ Runner ์—์„œ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— WORKDIR ์„  Runner ์˜ ํ™ˆ ๋””๋ ‰ํ„ฐ๋ฆฌ์ธ /home/runner ๋กœ ๋งž์ถ”์—ˆ์Šต๋‹ˆ๋‹ค.

configure ์ปค๋งจ๋“œ์˜ --prefix ์˜ต์…˜์„ ํ†ตํ•ด ๋นŒ๋“œ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ตณ์ด /home/runner ์„ ํ™ˆ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ ๋งž์ถœ ํ•„์š”๋Š” ์—†์ง€๋งŒ, ํŽธ์˜์ƒ ์ด๋Ÿฐ์‹์œผ๋กœ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

 

์ด๋ฒˆ์—” CMD ์— ์‚ฌ์šฉํ•  make-python.sh ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ช…๋ น์–ด๋“ค์„ ์ฐจ๋ก€๋Œ€๋กœ ์•Œ์•„๋ณด์ฃ .

 

๋จผ์ € Python ์„ ๋‹ค์šด๋กœ๋“œ ํ•ฉ๋‹ˆ๋‹ค. ์ € ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” 3.11 ์˜ latest ์ธ 3.11.9 ๋ฒ„์ „์œผ๋กœ ์ง„ํ–‰ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

https://www.python.org/downloads/release/python-3119/

$ wget https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tar.xz
$ tar xf Python-$PYTHON_VERSION.tar.xz

 

๋‹ค์šด ํ›„ ์••์ถ•๊นŒ์ง€ ํ’€์–ด์ค๋‹ˆ๋‹ค.

 

๋‹ค์Œ์€ make ๋ฅผ ํ†ตํ•ด์„œ python ์„ ๋นŒ๋“œํ•ฉ๋‹ˆ๋‹ค. ๋นŒ๋“œ ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹คํ–‰ํžˆ ๊ณต์‹ ๋ฌธ์„œ์— ์ž˜ ๋‚˜์™€์žˆ์Šต๋‹ˆ๋‹ค.

https://github.com/python/cpython?tab=readme-ov-file#build-instructions

 

๊ณต์‹ ๋ฌธ์„œ์—๋Š” ์œ„์ฒ˜๋Ÿผ ์•„์ฃผ ๊ธฐ๋ณธ์ ์ธ ๋ฐฉ๋ฒ•์ด ๋‚˜์™€์žˆ์ง€๋งŒ, ์ €๋Š” ์ตœ๋Œ€ํ•œ Official Setup Python ์™€ ๋น„์Šทํ•˜๊ฒŒ ๋งŒ๋“ค๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ์•„๋ž˜์ฒ˜๋Ÿผ ์‚ด์ง ๋ฐ”๊พธ์—ˆ์Šต๋‹ˆ๋‹ค. 

$ export RUNNER_HOME="/home/runner"
$ export PYTHON_VERSION="3.11.9"
$ export PREFIX="${RUNNER_HOME}/_work/_tool/Python-ARM64/${PYTHON_VERSION}/arm64"

$ LDFLAGS="-L${PREFIX}/lib -Wl,-rpath,${PREFIX}/lib" ./configure \
  	--prefix="${PREFIX}" \
  	--enable-shared --enable-optimizations

$ make -j$(nproc)
$ make install -j$(nproc)

 

Official Setup Python ์•ก์…˜์—์„œ ์ œ๊ณต๋˜๋Š” ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ๋ณด๋ฉด, ์•„๋ž˜์™€ ๊ฐ™์€๋ฐ

pythonLocation: /home/runner/_work/_tool/Python/3.11.9/x64
PKG_CONFIG_PATH: /home/runner/_work/_tool/Python/3.11.9/x64/lib/pkgconfig
Python_ROOT_DIR: /home/runner/_work/_tool/Python/3.11.9/x64
Python2_ROOT_DIR: /home/runner/_work/_tool/Python/3.11.9/x64
Python3_ROOT_DIR: /home/runner/_work/_tool/Python/3.11.9/x64
LD_LIBRARY_PATH: /home/runner/_work/_tool/Python/3.11.9/x64/lib

 

LD_LIBRARY_PATH ๊ฐ€ ์žˆ๋Š” ๊ฑธ ๋ณด๋‹ˆ ๋™์  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ ๊ฐ™์•„์„œ ./configure ์— --enable-shared ์˜ต์…˜์„ ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

Python_ROOT_DIR ์€ cmake ์˜ FindPython ์—์„œ Python ์„ ์ฐพ์„ ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์ž…๋‹ˆ๋‹ค.

 

--prefix ์˜ต์…˜์—๋Š” Runner ์˜ ํ™ˆ ๋””๋ ‰ํ„ฐ๋ฆฌ + Github Action Toolcached ๊ฒฝ๋กœ๋ฅผ ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค. ์ด ๋˜ํ•œ Official Setup Python ์•ก์…˜์ด ์ œ๊ณตํ•ด์ฃผ๋Š” ๊ฒฝ๋กœ์™€ ์ตœ๋Œ€ํ•œ ๋งž์ถ˜ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

๊ทธ๋ฆฌ๊ณ  LDFLAGS ๋ฅผ ์„ค์ •ํ•˜์—ฌ, C Compiler ์—๊ฒŒ ๋งํ‚น ์˜ต์…˜์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

LDFLAGS ๋ฅผ ์ฃผ์ง€ ์•Š์•„๋„, Python ์€ ์ž˜ ์‹คํ–‰๋˜๋‚˜, ๋งŒ์•ฝ ์ฃผ์ง€ ์•Š์„ ๊ฒฝ์šฐ setuptools ๋ฅผ ์‚ฌ์šฉํ•ด ํŒจํ‚ค์ง€๋ฅผ ๋งŒ๋“ค ๋•Œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

 

configure ๋ฅผ ํ†ตํ•ด Makefile ์„ ๋งŒ๋“ค๊ณ , make ์™€ make install ์„ ํ†ตํ•ด ๋นŒ๋“œ๋ฅผ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์ถ”๊ฐ€์ ์œผ๋กœ nproc ๋Š” ์ปดํŒŒ์ผ ์†๋„๋ฅผ ๋†’์ด๊ธฐ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” ์ปค๋งจ๋“œ์ž…๋‹ˆ๋‹ค.

 

make install ์„ ์ง„ํ–‰ํ•œ ํ›„ ์ถ”๊ฐ€๋กœ ํ•„์š”ํ•œ ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ ์†Œํ”„ํŠธ๋งํฌ๋ฅผ ํ†ตํ•ด ๋งŒ๋“ค์–ด ์ค๋‹ˆ๋‹ค.

$ export PYTHON_MINOR_VERSION="3.11"
$ export PREFIX="${RUNNER_HOME}/_work/_tool/Python-ARM64/${PYTHON_VERSION}/arm64"

$ cd "${PREFIX}/bin"

$ ln -s "python3.${PYTHON_MINOR_VERSION}" "python"
$ ln -s "pip3" "pip"
make install ํ›„ bin ํด๋”๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด python3, pip3 ๋งŒ ์žˆ๊ณ  python, pip ๋Š” ์—†์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ Official Setup Python ์•ก์…˜์€ ์ œ๊ณตํ•ด์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ์†Œํ”„ํŠธ๋งํฌ๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

 

๊ฑฐ์˜ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. Python ํด๋”๋ฅผ ์••์ถ•ํ•œ ํ›„ Artifacts Repository ์— ์—…๋กœ๋“œํ•˜๊ธฐ ์ „์— ๋จผ์ € ์ œ๋Œ€๋กœ ๋นŒ๋“œ๊ฐ€ ๋˜์—ˆ๋Š”์ง€ ๊ฐ„๋‹จํ•œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

$ export PREFIX="${RUNNER_HOME}/_work/_tool/Python-ARM64/${PYTHON_VERSION}/arm64"
$ export PATH="${PREFIX}/bin:${PATH}"
$ export LD_LIBRARY_PATH="${PREFIX}/lib"

$ python3 -c 'import math; print(math.factorial(5))' || echo "failed"
๋™์  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— LD_LIBRARY_PATH ๋ฅผ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋กœ ์ง€์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

๋ฌธ์ œ์—†์ด ์‹คํ–‰์ด ๋œ๋‹ค๋ฉด, ์ดํ›„ ์••์ถ•ํ•˜๊ณ  ์—…๋กœ๋“œ ํ•ด์ค๋‹ˆ๋‹ค.

 

์ง€๊ธˆ๊นŒ์ง€ ๊ณผ์ •์„ make-python.sh ์œผ๋กœ ๋ชจ์œผ๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์ฃ .

#!/bin/bash

set -eu

declare -r RUNNER_HOME="/home/runner"
declare -r PYTHON_VERSION=$VERSION #"$1" #-- from Dockerfile
IFS='.' read -ra parts <<< "$PYTHON_VERSION"

declare -r PYTHON_MINOR_VERSION="${parts[1]}"
declare -r OS_VERSION_ID=$(awk -F= '/VERSION_ID/ {gsub(/"/,"",$2); print $2}' /etc/os-release)
declare -r PREFIX="${RUNNER_HOME}/_work/_tool/Python-ARM64/${PYTHON_VERSION}/arm64"
export PATH="${PREFIX}/bin:${PATH}"

#-- clean old assets
rm -rf Python-ARM64

wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tar.xz
tar xf Python-$PYTHON_VERSION.tar.xz

#-- build python
pushd Python-$PYTHON_VERSION

LDFLAGS="-L${PREFIX}/lib -Wl,-rpath,${PREFIX}/lib" ./configure \
  --prefix="${PREFIX}" \
  --enable-shared --enable-optimizations

make -j$(nproc)
make install -j$(nproc)
popd #-- pushd Python-$PYTHON_VERSION

#-- soft link
pushd "${PREFIX}/bin"
ln -s "python3.${PYTHON_MINOR_VERSION}" "python"
ln -s "pip3" "pip"
popd #-- "${PREFIX}/bin"

#-- zip python binary
pushd "${RUNNER_HOME}/_work/_tool"
tar -czf python-$PYTHON_VERSION-linux-$OS_VERSION_ID-arm64.tar.gz Python-ARM64

curl \
    -F asset1=@"python-$PYTHON_VERSION-linux-$OS_VERSION_ID-arm64.tar.gz" \
    -F asset1.filename="python-$PYTHON_VERSION-linux-$OS_VERSION_ID-arm64.tar.gz" \
    -F directory="actions-assets/setup-python-arm64/releases/download/$PYTHON_VERSION" \
    "https://nexus.com/service/rest/v1/components?repository=raw-hosted"

#-- check binary
export PATH="${PREFIX}/bin:${PATH}"
export LD_LIBRARY_PATH="${PREFIX}/lib"

python3 -c 'import math; print(math.factorial(5))' || echo "failed"

#-- clean
rm -rf Python-$PYTHON_VERSION
rm -rf Python-$PYTHON_VERSION.tar.xz
rm -rf python-$PYTHON_VERSION-linux-$OS_VERSION_ID-arm64.tar.gz
popd #-- pushd ${RUNNER_HOME}/_work/_tool

 

๋” ๋‚˜์•„๊ฐ€์„œ ์•ž์œผ๋กœ ์—ฌ๋Ÿฌ Python ๋ฒ„์ „์„ ๋นŒ๋“œํ•ด์•ผ ํ•˜๋‹ˆ, ์ถ”๊ฐ€๋กœ loop.sh ์„ ํ†ตํ•ด ์ž๋™ํ™”ํ•ฉ๋‹ˆ๋‹ค.

#!/bin/bash

set -eu

versions=("3.12.3" "3.11.9" "3.10.14" "3.9.19" "3.8.19" "3.7.17")
os_version="jammy"

docker buildx build --platform=linux/arm64 --no-cache -t setup-python-arm64-$os_version .

for version in "${versions[@]}"
do
    docker run --rm --name $os_version -e VERSION="$version" setup-python-arm64-$os_version
done

 

loop.sh ์„ ์‹คํ–‰ํ•˜๋ฉด ์ด์ œ Docker Buildx ๋ฅผ ์ด์šฉํ•ด์„œ Python ์„ ๋นŒ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์œ„์—์„œ ์ œ๊ณตํ•˜๋Š” ์ž๋™ํ™” ๋ฐฉ๋ฒ•์€ ์ตœ์†Œํ•œ์˜ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

 

 

Remote (Runner)


 

Local ์—์„œ๋Š” Docker Buildx ์™€ Bash Script ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋‹ค์–‘ํ•œ OS ์—์„œ ๋‹ค์–‘ํ•œ ๋ฒ„์ „์˜ Python ์„ ๋นŒ๋“œํ•˜์—ฌ, Artifacts Repository ์— ์—…๋กœ๋“œํ•˜์˜€์Šต๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿผ ์ด์ œ Remote ๋กœ ๋„˜์–ด๊ฐ‘๋‹ˆ๋‹ค.

 

์ €๋Š” Composite Action ์„ ์ง์ ‘ ๋งŒ๋“ค์–ด์„œ Runner ์— Python ์„ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•  ๊ฒ๋‹ˆ๋‹ค.

 

๊ทธ ์ „์— ํ•œ๊ฐ€์ง€ ์งš๊ณ  ๋„˜์–ด๊ฐˆ ๊ฒƒ์ด ์žˆ๋Š”๋ฐ, Official Setup Python ์•ก์…˜์„ ๋ณด๋ฉด "3.11.9" ์ด๋Ÿฐ์‹์ด ์•„๋‹Œ "3.11" ์ฒ˜๋Ÿผ Minor ๋ฒ„์ „๊นŒ์ง€๋งŒ ์ž…๋ ฅํ•ด๋„ ์•Œ์•„์„œ ๊ฐ€์žฅ Latest ํ•œ Python ์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

https://github.com/marketplace/actions/setup-python

์œ„ ์•ก์…˜์—์„  '3.10' ๋งŒ ๋ช…์‹œํ–ˆ์ง€๋งŒ, ์„ค์น˜๋˜๋Š” ๊ฑด ๊ฐ€์žฅ latest ์ธ '3.10.14' ๋ฒ„์ „์ž…๋‹ˆ๋‹ค. (๊ธ€ ์ž‘์„ฑ ๊ธฐ์ค€)

 

์ด๋Ÿฐ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ์ €๋Š” versions-manifest.json ์„ ํ™œ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. versions-manifest.json ์€ ์ด๋ฏธ Official Setup Python ์—์„œ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ํŒŒ์ผ์ž…๋‹ˆ๋‹ค. key ๋Š” ๊ทธ๋Œ€๋กœ ๊ฐ€์ ธ์˜ค๊ณ  value ๋งŒ ๋ฐ”๊ฟ”์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

 

json ์œผ๋กœ ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— jq ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜๋ฉด ์–ด๋ ต์ง€ ์•Š๊ฒŒ ๊ฐ€์žฅ ์ตœ์‹  ๋ฒ„์ „์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์•„๋ž˜์ฒ˜๋Ÿผ versions-manifest.json ์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์ฃ .

[
    {
        "version": "3.11.9",
        "stable": true,
        "release_url": "https://nexus.com/repository/raw-hosted/actions-assets/setup-python-arm64/releases/download/3.11.9",
        "files": [
            {
                "filename": "python-3.11.9-linux-24.04-arm64.tar.gz",
                "arch": "arm64",
                "platform": "linux",
                "platform_version": "24.04",
                "download_url": "https://nexus.com/repository/raw-hosted/actions-assets/setup-python-arm64/releases/download/3.11.9/python-3.11.9-linux-24.04-arm64.tar.gz"
            },
            {
                "filename": "python-3.11.9-linux-22.04-arm64.tar.gz",
                "arch": "arm64",
                "platform": "linux",
                "platform_version": "22.04",
                "download_url": "https://nexus.com/repository/raw-hosted/actions-assets/setup-python-arm64/releases/download/3.11.9/python-3.11.9-linux-22.04-arm64.tar.gz"
            },
            {
                "filename": "python-3.11.9-linux-20.04-arm64.tar.gz",
                "arch": "arm64",
                "platform": "linux",
                "platform_version": "20.04",
                "download_url": "https://nexus.com/repository/raw-hosted/actions-assets/setup-python-arm64/releases/download/3.11.9/python-3.11.9-linux-20.04-arm64.tar.gz"
            }
        ]
    }
]

 

๊ทธ๋ฆฌ๊ณ  jq ๋ฅผ ํ™œ์šฉํ•ด์„œ ๊ฐ€์žฅ ์ตœ์‹  ๋ฒ„์ „์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. 

$ cat "versions-manifest.json" | jq -r --arg PYTHON_VERSION "3.11" '.[] | select(.version | startswith($PYTHON_VERSION)) | select(.stable == true) | .version' | sort -r | head -n 1

 

๋‹ค์‹œ ๋ณธ๋ก ์œผ๋กœ ๋Œ์•„์™€์„œ!

 

Composite Action ์— ์‚ฌ์šฉํ•  action.yaml ์€ ์•„๋ž˜์ฒ˜๋Ÿผ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.

name: 'SetUp Python Arm64'
author: kingbj0429@gmail.com
description: |
  SetUp Python Arm64

inputs:
  python-version:
    description: specify python version
    required: true

  username:
    description: username to access apt repo
    required: true

  password:
    description: password to access apt repo
    required: true

  nexus-host:
    description: nexus host
    required: false
    default: nexus.com

  nexus-repo:
    description: nexus repo
    required: false
    default: raw-hosted

runs:
  using: "composite"
  steps:
    - name: Preset
      shell: bash
      run: |
        echo "${{ github.action_path }}/shells" >> $GITHUB_PATH      

    - name: Set Python
      if: ${{ runner.arch == 'ARM64' }}
      shell: bash
      env:
        USERNAME: ${{ inputs.username }}
        PASSWORD: ${{ inputs.password }}
        NEXUS_HOST: ${{ inputs.nexus-host }}
        NEXUS_REPO: ${{ inputs.nexus-repo }}
        PYTHON_VERSION: ${{ inputs.python-version }}
      run: |
        bash setup-python.sh

    #-- Skip Action. If not arm64
    - name: Skip Setup Python
      if: ${{ runner.arch != 'ARM64' }}
      shell: bash
      run: |
        echo "::warning:: this runner arch is ${{ runner.arch}}, not ARM64. the action works only on ARM64"

 

๊ทธ๋ฆฌ๊ณ  setup-python.sh ์€ ์•„๋ž˜์ฒ˜๋Ÿผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์ฃ .

#!/bin/bash

set -eu

#-- convert to latest stable python version with versions-manifest.json
declare -r MANIFEST_PATH="${GITHUB_ACTION_PATH}/versions-manifest.json"
declare -r PYTHON_VERSION=$(cat "${MANIFEST_PATH}" | jq -r --arg PYTHON_VERSION "${PYTHON_VERSION}" '.[] | select(.version | startswith($PYTHON_VERSION)) | select(.stable == true) | .version' | sort -r | head -n 1)

#-- get python binary
pushd "${RUNNER_TOOL_CACHE}"
declare -r PYTHON_ASSET_NAME="python-${PYTHON_VERSION}-linux-$(awk -F= '/VERSION_ID/ {gsub(/"/,"",$2); print $2}' /etc/os-release)-arm64.tar.gz"
wget -q "https://${USERNAME}:${PASSWORD}@${NEXUS_HOST}/repository/${NEXUS_REPO}/actions-assets/setup-python-arm64/releases/download/${PYTHON_VERSION}/${PYTHON_ASSET_NAME}"
tar -zxf "${PYTHON_ASSET_NAME}" && rm "${PYTHON_ASSET_NAME}"
echo "https://${NEXUS_HOST}/repository/${NEXUS_REPO}/actions-assets/setup-python-arm64/releases/download/${PYTHON_VERSION}/${PYTHON_ASSET_NAME} downloading..."
popd

#-- add path
export PATH="${RUNNER_TOOL_CACHE}/Python-ARM64/${PYTHON_VERSION}/arm64/bin:${PATH}"
echo "${RUNNER_TOOL_CACHE}/Python-ARM64/${PYTHON_VERSION}/arm64/bin:${PATH}" >> "${GITHUB_PATH}"
export LD_LIBRARY_PATH="$(python3-config --prefix)/lib"

#-- extract envs
echo "pythonLocation=$(python3-config --prefix)" >> "${GITHUB_ENV}"
echo "Python_ROOT_DIR=$(python3-config --prefix)" >> "${GITHUB_ENV}"
echo "Python2_ROOT_DIR=$(python3-config --prefix)" >> "${GITHUB_ENV}"
echo "Python3_ROOT_DIR=$(python3-config --prefix)" >> "${GITHUB_ENV}"
echo "PKG_CONFIG_PATH=${LD_LIBRARY_PATH}/pkgconfig" >> "${GITHUB_ENV}"
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> "${GITHUB_ENV}"

#-- get version
echo "python version : $(python --version) ($(command -v python))"
echo "python3 version : $(python3 --version) ($(command -v python3))"
echo "pip version : $(python3 -m pip --version)"

#-- valid check
python -c 'import math; print(math.factorial(5))' || { echo "setup python failed"; exit 1; }
echo "python valid check passed"

 

์œ ์‹ฌํžˆ ๋ด์•ผํ•  ๋ถ€๋ถ„์€ add path ๋ถ€๋ถ„๊ณผ extract envs ์ž…๋‹ˆ๋‹ค.

 

add path ๋ถ€๋ถ„์—์„œ๋Š” Python ๋ฐ”์ด๋„ˆ๋ฆฌ ๊ฒฝ๋กœ๋ฅผ PATH ํ™˜๊ฒฝ๋ณ€์ˆ˜์— ์ „๋‹ฌํ•ด์ฃผ๊ณ , LD_LIBRARY_PATH ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ๋“ฑ๋กํ•ด์คŒ์œผ๋กœ์จ Python ๋Ÿฐํƒ€์ž„์— ์‚ฌ์šฉํ•  ๋™์  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ฒฝ๋กœ๋ฅผ ์•Œ๋ ค์ค๋‹ˆ๋‹ค.

 

extract envs ๋Š” Official Setup Python ์—์„œ ์ œ๊ณตํ•ด์ฃผ๋Š” ํ™˜๊ฒฝ๋ณ€์ˆ˜๊ฐ€ ๋˜‘๊ฐ™์€ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์ œ๊ณตํ•ด์ฃผ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

 

์ดํ›„ ๋งŒ๋“  Composite Action ์„ workflows ์—์„  ์•„๋ž˜์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

jobs:
  jammy-arm64:
    runs-on: [ jammy-arm64 ]
    steps:
      - name: SetUp Python
        uses: kingbj940429/git-actions/set-ups/setup-python-arm64@v1.0.0
        with:
          python-version: '3.11'
          username: ${{ secrets.USERNAME }}
          password: ${{ secrets.PASSWORD }}

 

์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฌธ์ œ์—†์ด Linux/Arm64 ํ™˜๊ฒฝ์— Python ์„ ์„ค์น˜ํ–ˆ์Šต๋‹ˆ๋‹ค!

์‹คํ–‰ ๊ฒฐ๊ณผ

 

์˜ค๋Š˜์€ Official Setup Python ์—์„œ ์ œ๊ณตํ•˜์ง€ ์•Š์•„ Linux/arm64 ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” Setup Python ์•ก์…˜์„ ์ง์ ‘ ๋งŒ๋“ค์–ด๋ดค์Šต๋‹ˆ๋‹ค.

C Compile ์— ๋Œ€ํ•ด ์ž˜ ๋ชฐ๋ผ์„œ ๊ฝค๋‚˜ ๊ณ ์ƒํ–ˆ์ง€๋งŒ, ์–ด์ฐŒ๋๋“  ์„ฑ๊ณต์ ์œผ๋กœ ์™„์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค!

 

๊ทธ๋Ÿผ ์˜ค๋Š˜์€ ์—ฌ๊ธฐ๊นŒ์ง€~

profile on loading

Loading...