Skip to content

Commit

Permalink
Merge pull request #28 from Chaste/slim_docker
Browse files Browse the repository at this point in the history
Slimmer docker image
  • Loading branch information
kwabenantim authored Aug 23, 2022
2 parents ef32fd6 + 755d082 commit 43c131d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 50 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ RUN useradd -r -m -d ${DEFAULT_HOME} -s /bin/bash ${DEFAULT_USER} && \
. /etc/os-release && \
os_num="$(echo ${VERSION_ID} | sed 's/\.//')" && \
setup_ubuntu${os_num}.sh && \
runner_install.sh --install_dir="${RUNNER_DIR}" && \
chown -R ${DEFAULT_USER}:${DEFAULT_USER} ${RUNNER_DIR} && \
runner_install.sh --install_dir="/tmp/tmp-runner" && \
/tmp/tmp-runner/bin/installdependencies.sh && \
mkdir -p ${MODULES_DIR}/src && \
mkdir -p ${MODULES_DIR}/opt && \
mkdir -p ${MODULES_DIR}/modulefiles && \
echo "module use ${MODULES_DIR}/modulefiles" >> ${DEFAULT_HOME}/.bashrc && \
chown -R ${DEFAULT_USER}:${DEFAULT_USER} ${MODULES_DIR} && \
Expand Down
10 changes: 8 additions & 2 deletions scripts/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#!/bin/bash -e

if [ -n "${RUNNER_REMOVE}" ]; then
echo "Removing runner ..."
runner_config.sh
unset RUNNER_PA_TOKEN
exit 0
fi

if [ ! -f "${RUNNER_DIR}/config.sh" ]; then
echo "Installing runner ..."
runner_install.sh --install_dir="${RUNNER_DIR}"
while read -t 1; do :; done # skip inputs while installing
fi

if [ ! -f "${RUNNER_DIR}/.runner" ]; then
echo "Configuring runner ..."
runner_config.sh
fi
unset RUNNER_PA_TOKEN

if [ ! -f "${RUNNER_DIR}/.runner" ]; then
echo "Runner has not been configured"
Expand Down
70 changes: 26 additions & 44 deletions scripts/runner_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,22 @@ throw_error()
exit 1
}

# Get unattended
unattended="${RUNNER_UNATTENDED:-}"

if [ -z "${unattended}" ]; then
unattended=
elif [ "${unattended}" -eq 0 ]; then
unattended=
else
unattended="--unattended"
fi

# Get runner_dir
runner_dir="${RUNNER_DIR:-}"

if [[ (-z "${runner_dir}") && (-z "${unattended}") ]]; then
if [ ! -d "${runner_dir}" ]; then
echo -n "Enter path to actions-runner: "
read runner_dir
fi

if [ -z "${runner_dir}" ]; then
if [ ! -d "${runner_dir}" ]; then
throw_error "RUNNER_DIR not specified"
fi

# Get personal access token
pa_token="${RUNNER_PA_TOKEN-}"
unset RUNNER_PA_TOKEN

if [[ (-z "${pa_token}") && (-z "${unattended}") ]]; then
echo -n "Enter access token: "
read -s pa_token
echo
fi

if [ -z "${pa_token}" ]; then
throw_error "RUNNER_PA_TOKEN not provided"
fi

# Get scope
scope="${RUNNER_SCOPE:-}"

if [[ (-z "${scope}") && (-z "${unattended}") ]]; then
if [ -z "${scope}" ]; then
echo -n "Enter the runner scope (org or repo): [press Enter for org] "
read scope
fi
Expand All @@ -61,7 +36,7 @@ fi
# Get org
org="${RUNNER_ORG:-}"

if [[ (-z "${org}") && (-z "${unattended}") ]]; then
if [ -z "${org}" ]; then
echo -n "Enter the org/owner name: "
read org
fi
Expand All @@ -74,7 +49,7 @@ fi
repo="${RUNNER_REPO:-}"

if [ "${scope}" = "repo" ]; then
if [[ (-z "${repo}") && (-z "${unattended}") ]]; then
if [ -z "${repo}" ]; then
echo -n "Enter the repo name: "
read repo
fi
Expand All @@ -84,6 +59,16 @@ if [ "${scope}" = "repo" ]; then
fi
fi

# Get personal access token
pa_token=
echo -n "Enter access token: "
read -s pa_token
echo

if [ -z "${pa_token}" ]; then
throw_error "Access token not provided"
fi

# Runner removal
remove="${RUNNER_REMOVE:-}"

Expand Down Expand Up @@ -125,19 +110,16 @@ reg_token="$(curl -X POST -fsS -H "Accept: application/vnd.github+json" -H "Auth
reg_token="$(echo ${reg_token} | jq -r .token)"
unset pa_token

# Get name, labels, group
name="${RUNNER_NAME:-}"
labels="${RUNNER_LABELS:-}"
group="${RUNNER_GROUP:-}"

# Set unattended defaults
if [ -n "${unattended}" ]; then
os_id="$(cat /etc/os-release | grep ^ID= | cut -d= -f2)"
os_ver="$(cat /etc/os-release | grep ^VERSION_CODENAME= | cut -d= -f2)"
name="${name:-$(openssl rand -hex 6)}"
labels="${labels:-self-hosted,${os_id}-${os_ver}}"
group="${group:-Default}"
fi
# Get name
name="${RUNNER_NAME:-$(openssl rand -hex 6)}"

# Get group
group="${RUNNER_GROUP:-Default}"

# Get labels
os_id="$(cat /etc/os-release | grep ^ID= | cut -d= -f2)"
os_ver="$(cat /etc/os-release | grep ^VERSION_CODENAME= | cut -d= -f2)"
labels="${RUNNER_LABELS:-self-hosted,${os_id}-${os_ver}}"

# Get work_dir
work_dir="${RUNNER_WORK_DIR:-${HOME}/_work}"
Expand All @@ -152,6 +134,6 @@ ${runner_dir}/config.sh \
--runnergroup "${group}" \
--labels "${labels}" \
--work "${work_dir}" \
--replace ${unattended}
--replace

unset reg_token
2 changes: 0 additions & 2 deletions scripts/runner_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,3 @@ curl -fsS \
tar -xzf /tmp/actions-runner.tar.gz -C ${install_dir}
rm -f /tmp/actions-runner.tar.gz

# Install dependencies
${install_dir}/bin/installdependencies.sh

0 comments on commit 43c131d

Please sign in to comment.