Skip to content

Commit

Permalink
Improve task setup phase (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Nov 13, 2023
1 parent 67b7cc7 commit b769923
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 39 deletions.
45 changes: 23 additions & 22 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
ALS
Anson
Containerfile
Dockal
FQCN
FQCNs
Florian
Launay
Maciążek
OSTYPE
Ondrej
PYTHONBREAKPOINT
PYTHONHOME
Pinkney
Pyenv
Sbarnea
Schwalm
Sorin
TLDR
Testenvs
Tomasz
Webviews
aarch
ajinkyau
akira
alefragnani
alphanums
ALS
Anson
autofix
autoupdate
backticks
Expand All @@ -18,18 +38,17 @@ codespell
codicon
codicons
commitlint
Containerfile
contentmatch
contentmatches
copyfiles
cygwin
cython
dbaeumer
dedupe
depcheck
deps
devel
direnv
Dockal
dpkg
eamodio
endgroup
Expand All @@ -39,9 +58,6 @@ eqeqeq
esbenp
extest
fgierlinger
Florian
FQCN
FQCNs
fredericgiquel
ganeshrn
githubcli
Expand All @@ -55,14 +71,12 @@ jeinwag
johndoe
keyfile
keyrings
Launay
lextudio
libyaml
lightspeed
liveserver
loglevel
lxml
Maciążek
markdownlint
maxlength
mochawesome
Expand All @@ -73,12 +87,9 @@ myuser
noheading
npmrc
nsible
Ondrej
OSTYPE
overridable
ovsx
parseable
Pinkney
piptools
pipx
precheck
Expand All @@ -87,35 +98,26 @@ preinstall
priyamsahoo
projectuser
prsahoo
Pyenv
pyparsing
PYTHONBREAKPOINT
PYTHONHOME
reindent
reindented
relogin
ritwickdey
rulebooks
Sbarnea
Schwalm
showformat
simplejson
Sorin
sourcemaps
ssbarnea
ssydoren
stopendy
suboptions
sysninja
taskfile
Testenvs
testenv
testhost
testorg
timonwong
TLDR
tomaciazek
Tomasz
towerhost
tsbuildinfo
tsdoc
Expand All @@ -130,7 +132,6 @@ vscoss
vsix
vyos
watsonx
Webviews
webknjaz
webpacked
whitespaces
Expand Down
1 change: 1 addition & 0 deletions .config/requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cython>=3.0.5; python_version >= "3.12"
ansible-core>=2.13.0
ansible-lint>=6.8.7
mypy # used by vscode
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ jobs:
~/.cache/yarn
key: ${{ runner.os }}-${{ matrix.task-name }}-${{ hashFiles('package.json', 'yarn.lock', '.config/requirements.txt', 'tools/*.*') }}

- name: Enable caching for podman-machine
if: "contains(matrix.os, 'macos')"
uses: actions/cache@v3
with:
path: |
~/.local/share/containers
~/.config/containers
key: ${{ runner.os }}-${{ matrix.task-name }}-${{ hashFiles('package.json', 'yarn.lock', '.config/requirements.txt', '**/Taskfile.yml', 'tools/*.*') }}
# - name: Enable caching for podman-machine
# if: "contains(matrix.os, 'macos')"
# uses: actions/cache@v3
# with:
# path: |
# ~/.local/share/containers
# ~/.config/containers
# key: ${{ runner.os }}-${{ matrix.task-name }}-${{ hashFiles('package.json', 'yarn.lock', '.config/requirements.txt', '**/Taskfile.yml', 'tools/*.*') }}

- name: Use NodeJS v18
uses: actions/setup-node@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ CHANGELOG.html
!.yarn/versions
.DS_Store
.direnv
.tool-versions
43 changes: 34 additions & 9 deletions tools/test-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ mkdir -p out/log
# we do not want pip logs from previous runs
: >"${PIP_LOG_FILE}"

timed() {
local start
start=$(date +%s)
local exit_code
exit_code=0
"$@" || exit_code=$?
echo >&2 "took ~$(($(date +%s)-start)) seconds. exited with ${exit_code}"
return $exit_code
}

# Function to retrieve the version number for a specific command. If a second
# argument is passed, it will be used as return value when tool is missing.
get_version() {
Expand Down Expand Up @@ -59,6 +69,16 @@ log() {
echo >&2 -e "${prefix}${2}${NC}"
}

is_podman_running() {
if [[ "$(podman machine ls --format '{{.Name}} {{.Running}}' --noheading 2>/dev/null)" == *"podman-machine-default* true"* ]]; then
log notice "Podman machine is running."
return 0
else
log error "Podman machine is not running."
return 1
fi
}

if [ ! -d "$HOME/.local/bin" ] ; then
log warning "Creating missing ~/.local/bin"
mkdir -p "$HOME/.local/bin"
Expand Down Expand Up @@ -321,16 +341,16 @@ log notice "Podman checks..."
if [[ "${OSTYPE:-}" == darwin* && "${SKIP_PODMAN:-}" != '1' ]]; then
command -v podman >/dev/null 2>&1 || {
log notice "Installing podman..."
HOMEBREW_NO_ENV_HINTS=1 time brew install podman
HOMEBREW_NO_ENV_HINTS=1 timed brew install podman
}
log notice "Configuring podman machine ($MACHTYPE)..."
podman machine ls --noheading | grep '\*' || {
podman machine ls --noheading | grep '\*' >/dev/null || {
log warning "Podman machine not found, creating and starting one ($MACHTYPE)..."
time podman machine init --now || log warning "Ignored init failure due to possible https://github.com/containers/podman/issues/13609 but we will check again later."
timed podman machine init --now || log warning "Ignored init failure due to possible https://github.com/containers/podman/issues/13609 but we will check again later."
}
podman machine ls --noheading
log notice "Checking status of podman machine ($MACHTYPE)..."
podman machine ls --format '{{.Name}} {{.Running}}' --noheading | grep podman-machine-default | grep true || {
is_podman_running || {
log warning "Podman machine not running, trying to start it..."
# do not use full path as it varies based on architecture
# https://github.com/containers/podman/issues/10824#issuecomment-1162392833
Expand All @@ -340,13 +360,16 @@ if [[ "${OSTYPE:-}" == darwin* && "${SKIP_PODMAN:-}" != '1' ]]; then
else
qemu-system-aarch64 -machine q35,accel=hvf:tcg -cpu host -display none INVALID_OPTION || true
fi
podman machine start
# Waiting for machine to become available
n=0
until [ "$n" -ge 5 ]; do
log warning "Trying to start podman machine again ($n)..."
time podman machine start && break # substitute your command here
until [ "$n" -ge 9 ]; do
log warning "Still waiting for podman machine to become available $((n * 15))s ..."
is_podman_running && break
n=$((n+1))
sleep 15
done
is_podman_running
}
# validation is done later
podman info
Expand All @@ -359,12 +382,14 @@ PODMAN_VERSION="$(get_version podman || echo null)"
if [[ "${PODMAN_VERSION}" != 'null' ]] && [[ "${SKIP_PODMAN:-}" != '1' ]]; then
log notice "Pull our test container image with podman."
podman pull --quiet "${IMAGE}" >/dev/null
# without running we will never be sure it works (no arm64 image yet)
# without running we will never be sure it works
log notice "Retrieving ansible version from ee"
EE_ANSIBLE_VERSION=$(get_version \
podman run "${IMAGE}" ansible --version)
log notice "Retrieving ansible-lint version from ee"
EE_ANSIBLE_LINT_VERSION=$(get_version \
podman run "${IMAGE}" ansible-lint --nocolor --version)
# Test podman ability to mount current folder with write access, default mount options
log notice "Test podman ability to mount current folder with write access, default mount options"
podman run -v "$PWD:$PWD" ghcr.io/ansible/creator-ee:latest \
bash -c "[ -w $PWD ] && echo 'Mounts working' || { echo 'Mounts not working. You might need to either disable or make selinux permissive.'; exit 1; }"
fi
Expand Down

0 comments on commit b769923

Please sign in to comment.