Skip to content

Commit

Permalink
Replace release-microk8s job from groovy to shell script (#1499)
Browse files Browse the repository at this point in the history
* Replace release-microk8s job from groovy to shell script

* After a bit of fudging with jjb to test the job

* Push into lxc with same modes and file permissions

* refine to job definitions

* adjust no-reporting path

* Update Parameter description
  • Loading branch information
addyess committed Apr 1, 2024
1 parent 7689c8d commit db9b547
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 203 deletions.
19 changes: 14 additions & 5 deletions ci.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function compile::env
: "${JUJU_DEPLOY_CHANNEL:?Must have a channel defined}"
: "${JUJU_MODEL:?Must have a model defined}"
: "${JUJU_UPDATE_STATUS_INTERVAL:=150s}"
: "${JOB_STAGE:-}"
: "${JOB_REPORTING:-yes}"
: "${SERIES:?Must have a release series defined}"
: "${SNAP_VERSION:?Must have a snap version defined}"
: "${JOB_NAME_CUSTOM:?Must have a job name defined}"
Expand Down Expand Up @@ -48,6 +50,7 @@ function compile::env
kv::set "job_id" "$JOB_ID"
kv::set "job_name" "$JOB_NAME_CUSTOM"
kv::set "job_name_custom" "$JOB_NAME_CUSTOM"
kv::set "job_stage" "$JOB_STAGE"
kv::set "series" "$SERIES"
kv::set "arch" "$ARCH"
kv::set "snap_version" "$SNAP_VERSION"
Expand Down Expand Up @@ -164,14 +167,22 @@ function test::execute
function test::report
{
result=$1

kv::set "result" "$result"
touch "meta/result-$result"
python bin/s3 cp "meta/result-$result" "meta/result-$result"
if [ "${JOB_REPORTING}" == "no" ]; then
echo "Job reporting disabled"
else
python bin/s3 cp "meta/result-$result" "meta/result-$result"
fi
}

function test::capture
{
if [ "${JOB_REPORTING}" == "no" ]; then
echo "Job reporting disabled"
return 0
fi

if which juju-crashdump; then
# -s small crashdump by skipping /var/lib/juju
# -a debug-layer included debug-layer addon
Expand Down Expand Up @@ -272,9 +283,7 @@ function ci::cleanup
ci::cleanup::before || true
test::capture || true

if ! timeout 2m juju destroy-controller --no-prompt --destroy-all-models --destroy-storage "$JUJU_CONTROLLER"; then
timeout 10m juju kill-controller -t 2m0s --no-prompt "$JUJU_CONTROLLER" || true
fi
juju::destroy
ci::cleanup::after || true
} 2>&1 | sed -u -e "s/^/[$log_name_custom] /" | tee -a "ci.log"
}
Expand Down
9 changes: 8 additions & 1 deletion cilib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ ci_lxc_push()
local lxc_container=$1
local source=$2
local dest=$3
sudo lxc file push ${source} ${lxc_container}/${dest}
local args=(-p --mode "$(stat -c '0%a' $source)")
if [ "$(stat -c '%U' $source)" == "$(whoami)" ]; then
args+=(--uid 1000)
fi
if [ "$(stat -c '%G' $source)" == "$(whoami)" ]; then
args+=(--gid 1000)
fi
sudo lxc file push "${args[@]}" ${source} ${lxc_container}/${dest}
}


Expand Down
130 changes: 130 additions & 0 deletions jobs/microk8s/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash
# shellcheck disable=SC2034,SC1090

set -x

###############################################################################
# INITIALIZE
###############################################################################
: "${WORKSPACE:=$(pwd)}"

. "$WORKSPACE/ci.bash"
. "$WORKSPACE/juju.bash"

###############################################################################
# FUNCTION OVERRIDES
###############################################################################

###############################################################################
# ENV
###############################################################################
export ARCH=${ARCH:-amd64}
export TRACKS=${TRACKS:-}
export DRY_RUN=${DRY_RUN:-yes}
export ALWAYS_RELEASE=${ALWAYS_RELEASE:-no}
export TESTS_BRANCH=${TESTS_BRANCH:-}
export PROXY=${PROXY:-}
export RELEASE_CHANNEL=${RELEASE_CHANNEL:-all}


SERIES=focal
JUJU_DEPLOY_BUNDLE="${WORKSPACE}/ubuntu.yaml"
JUJU_DEPLOY_CHANNEL=stable
JUJU_CLOUD=aws/us-east-1
JUJU_CONTROLLER=release-$(identifier::short)
JUJU_VERSION=$(juju --version | cut -f-2 -d.)
CUSTOM_CLOUD=$(echo "$JUJU_CLOUD" | cut -f1 -d/)
JOB_NAME_CUSTOM="release-microk8s-$ARCH"
SNAP_VERSION=stable
JOB_ID=$(identifier)
JOB_REPORTING=no

function snapcraft::login
{
snapcraft login --with "${SNAPCRAFTCREDS}"
}

function gather::channels
{
if [[ ${RELEASE_CHANNEL} == "all" ]]; then
CHANNELS=("beta" "stable" "pre-release")
else
CHANNELS=($RELEASE_CHANNEL)
fi
echo "Running for channels ${ARCH}/${CHANNELS}"
}

function juju::deploy::overlay
{
local constraints
constraints="cores=8 mem=16G root-disk=80G arch=${ARCH}"
if [ "${ARCH}" == "amd64" ] && [ "${CHANNEL}" == "stable" ]; then
constraints+=" instance-type=g3s.xlarge"
fi

cat << EOF > $JUJU_DEPLOY_BUNDLE
series: $SERIES
applications:
ubuntu:
charm: ubuntu
channel: latest/stable
constraints: $constraints
num_units: 1
EOF
}

function juju::deploy
{
juju deploy -m "$JUJU_CONTROLLER:$JUJU_MODEL" "$JUJU_DEPLOY_BUNDLE"
juju::deploy-report $? "model-deploy"
}

function test::execute
{
local juju_full_model="$JUJU_CONTROLLER:$JUJU_MODEL"
export JUJU_UNIT=ubuntu/0
juju ssh -m "${juju_full_model}" --pty=true $JUJU_UNIT -- 'sudo snap install lxd'
juju ssh -m "${juju_full_model}" --pty=true $JUJU_UNIT -- 'sudo lxd.migrate -yes' || true
juju ssh -m "${juju_full_model}" --pty=true $JUJU_UNIT -- 'sudo lxd init --auto'
if [ "${CHANNEL}" == "pre-release" ]; then
juju ssh -m "${juju_full_model}" --pty=true $JUJU_UNIT -- 'sudo snap install snapcraft --classic'
fi

case $CHANNEL in
beta)
SCRIPT_NAME="release-to-beta.py"
;;
stable)
SCRIPT_NAME="release-to-stable.py"
;;
pre-release)
SCRIPT_NAME="release-pre-release.py"
;;
esac

declare -n is_pass=$1
timeout 6h python jobs/microk8s/${SCRIPT_NAME}
ret=$?
is_pass="True"
if (( ret == 124 )); then
is_pass="Timeout"
elif (( ret > 0 )); then
is_pass="False"
fi
}

###############################################################################
# START
###############################################################################

snapcraft::login
gather::channels
for CHANNEL in "${CHANNELS[@]}"; do
export "CHANNEL"
timeout 6h python jobs/microk8s/release-needed.py
if (( $? == 0 )); then
JOB_STAGE="${CHANNEL}-${ARCH}"
JUJU_MODEL="release-microk8s-${JOB_STAGE}-model"
ci::run
fi
done
66 changes: 48 additions & 18 deletions jobs/release-microk8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,61 @@

- job-template:
name: 'release-microk8s-arch-{arch}'
axes:
- axis:
type: slave # wokeignore:rule=slave
name: node
values:
- runner-cloud
description: |
Tests and releases microk8s. Affects all tracks on {arch}.
project-type: pipeline
pipeline-scm:
scm:
- k8s-jenkins-jenkaas
script-path: jobs/release-microk8s/release-microk8s.groovy
project-type: matrix
scm:
- k8s-jenkins-jenkaas
wrappers:
- default-job-wrapper
- ci-creds
properties:
- block-on-infra
- build-discarder:
num-to-keep: 10
triggers:
- timed: "@daily"
parameters:
- juju-lts
- choice:
name: LXC_APT_LIST
description: |-
comma-separated list of apt packages to install into the container
choices:
- pip,python3-venv,python3-dev,libffi-dev
- choice:
name: LXC_SNAP_LIST
description: |-
comma-separated list of snaps to install into the container
if the snap requires multiple arguments
choices:
- snapcraft --channel=6.x/stable,juju-wait,juju-crashdump,juju --channel=$juju_channel
- choice:
name: LXC_PUSH_LIST
description: |-
comma-separated list of paths to push into the container
choices:
- $SNAPCRAFTCREDS
- choice:
name: LXC_MOUNT_LIST
description: |-
comma-separated list of paths to mount in the container from $HOME to $LXC_HOME
choices:
- .local,.ssh,.aws,snap
- choice:
name: ARCH
description: |
Architecture associated with this job
choices:
- "{arch}"
- choice:
name: CHANNEL
name: RELEASE_CHANNEL
description: |
Choose a specific release channel
choices:
Expand All @@ -32,8 +68,8 @@
name: TRACKS
default: ""
description: |
The tracks you want to test and release. For example latest 1.10
1.11 1.12. Leave empty to iterate over all tracks.
Space separated list of tracks you want to test and release.
For example "latest 1.10 1.11 1.12". Leave empty to iterate over all tracks.
- choice:
name: DRY_RUN
description: |
Expand All @@ -59,16 +95,10 @@
default: ""
description: |
Proxy endpoint
triggers:
- timed: "@daily"
properties:
- build-discarder:
num-to-keep: 10
- build-blocker:
use-build-blocker: true
blocking-jobs:
- "infra.*"
block-level: 'NODE'
builders:
- run-lxc:
COMMAND: |
bash jobs/microk8s/release.sh
- project:
name: release-microk8s-arch
Expand Down
Loading

0 comments on commit db9b547

Please sign in to comment.