Skip to content

Commit

Permalink
Pre-install python version for self-hosted (btungut#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
saisona committed Feb 13, 2024
1 parent 95f842a commit f53b1a0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN echo "APT::Get::Assume-Yes \"true\";" > /etc/apt/apt.conf.d/90assumeyes

# Default available python version to install
# This always downloads the latest available patch version
# Keep it empty for default behaviour
ARG PYTHON_AVAILABLE_VERSION_VERSIONS="3.10 3.11"

RUN apt-get update && apt-get install -y --no-install-recommends \
apt-transport-https \
apt-utils \
Expand All @@ -16,12 +21,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
jq \
lsb-release \
software-properties-common \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get -y upgrade

RUN curl -LsS https://aka.ms/InstallAzureCLIDeb | bash \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/*

RUN az extension add --name azure-devops

Expand All @@ -30,6 +35,11 @@ ENV TARGETARCH=linux-x64

WORKDIR /azp

COPY ./pre-install.sh .
RUN chmod +x pre-install.sh && \
./pre-install.sh && \
rm ./pre-install.sh

RUN apt-get update && apt-get install -y --no-install-recommends \
wget \
unzip \
Expand Down Expand Up @@ -58,8 +68,8 @@ RUN apt-get update \
#install docker cli
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
RUN echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
RUN apt-get update \
&& apt-get install -y docker-ce-cli

Expand All @@ -86,4 +96,4 @@ RUN sudo groupadd docker
RUN sudo usermod -aG docker azuredevops
RUN sudo newgrp docker

ENTRYPOINT ["./start.sh"]
ENTRYPOINT ["./start.sh"]
31 changes: 31 additions & 0 deletions src/pre-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -e

AGENT_TOOLSDIRECTORY="/azp/_work/_tool"

# Adding ppa to fetch old python versions
add-apt-repository ppa:deadsnakes/ppa

echo "Available python version to install: $PYTHON_AVAILABLE_VERSION_VERSIONS"
for py in $PYTHON_AVAILABLE_VERSION_VERSIONS
do
echo "--------------------------------------------------------"
apt install -qq -y python$py-dev python$py-venv

PYTHON_VERSION=$(python$py -V | cut -d " " -f2)
mkdir -p $AGENT_TOOLSDIRECTORY/Python/$PYTHON_VERSION
if [[ $? == 1 ]]; then echo "Failed created python $py version folder";exit 1;fi

cd $AGENT_TOOLSDIRECTORY/Python/$PYTHON_VERSION
python$py -m venv x64
touch x64.complete
cd x64
mkdir -p share
ln -s bin/python$py python
cd ..
cd ..

ln -s $PYTHON_VERSION $py
echo "Available versions:"
tree -L 1
done

0 comments on commit f53b1a0

Please sign in to comment.