mirror of
https://github.com/flatcar/scripts.git
synced 2025-12-07 18:31:54 +01:00
ci-automation: Run functions in subshells
The functions are sourcing other files that define global variables, so they will spill into the callers shell unnecessarily. We will also add some functionality that uses traps in follow-up commits, so it's good to limit the scope of traps too.
This commit is contained in:
parent
698d0de129
commit
090d7ec176
@ -24,9 +24,18 @@
|
||||
# in the scripts repo. The newest 50 builds will be retained,
|
||||
# all older builds will be purged (50 is the default, see OPTIONAL INPUT above).
|
||||
|
||||
set -eu
|
||||
|
||||
function garbage_collect() {
|
||||
# Run a subshell, so the traps, environment changes and global
|
||||
# variables are not spilled into the caller.
|
||||
(
|
||||
set -euo pipefail
|
||||
|
||||
_garbage_collect_impl "${@}"
|
||||
)
|
||||
}
|
||||
# --
|
||||
|
||||
function _garbage_collect_impl() {
|
||||
local keep="${1:-50}"
|
||||
local dry_run="${DRY_RUN:-}"
|
||||
local purge_versions="${PURGE_VERSIONS:-}"
|
||||
@ -144,3 +153,4 @@ function garbage_collect() {
|
||||
--env VMWARE_ESX_CREDS \
|
||||
-w /work -v "$PWD":/work "${mantle_ref}" /work/ci-automation/garbage_collect_cloud.sh
|
||||
}
|
||||
# --
|
||||
|
||||
@ -32,9 +32,18 @@
|
||||
# 2. "./ci-cleanup.sh" with commands to clean up temporary build resources,
|
||||
# to be run after this step finishes / when this step is aborted.
|
||||
|
||||
set -eu
|
||||
|
||||
function image_build() {
|
||||
# Run a subshell, so the traps, environment changes and global
|
||||
# variables are not spilled into the caller.
|
||||
(
|
||||
set -euo pipefail
|
||||
|
||||
_image_build_impl "${@}"
|
||||
)
|
||||
}
|
||||
# --
|
||||
|
||||
function _image_build_impl() {
|
||||
local arch="$1"
|
||||
|
||||
source sdk_lib/sdk_container_common.sh
|
||||
|
||||
@ -56,10 +56,18 @@
|
||||
# 3. "./ci-cleanup.sh" with commands to clean up temporary build resources,
|
||||
# to be run after this step finishes / when this step is aborted.
|
||||
|
||||
|
||||
set -eu
|
||||
|
||||
function packages_build() {
|
||||
# Run a subshell, so the traps, environment changes and global
|
||||
# variables are not spilled into the caller.
|
||||
(
|
||||
set -euo pipefail
|
||||
|
||||
_packages_build_impl "${@}"
|
||||
)
|
||||
}
|
||||
# --
|
||||
|
||||
function _packages_build_impl() {
|
||||
local version="$1"
|
||||
local arch="$2"
|
||||
local coreos_git="${3:-}"
|
||||
|
||||
@ -31,8 +31,6 @@
|
||||
# 2. "./ci-cleanup.sh" with commands to clean up temporary build resources,
|
||||
# to be run after this step finishes / when this step is aborted.
|
||||
|
||||
set -eu
|
||||
|
||||
# This function is run _inside_ the SDK container
|
||||
function image_build__copy_to_bincache() {
|
||||
local arch="$1"
|
||||
@ -46,6 +44,17 @@ function image_build__copy_to_bincache() {
|
||||
# --
|
||||
|
||||
function push_packages() {
|
||||
# Run a subshell, so the traps, environment changes and global
|
||||
# variables are not spilled into the caller.
|
||||
(
|
||||
set -euo pipefail
|
||||
|
||||
_push_packages_impl "${@}"
|
||||
)
|
||||
}
|
||||
# --
|
||||
|
||||
function _push_packages_impl() {
|
||||
local arch="$1"
|
||||
|
||||
source ci-automation/ci_automation_common.sh
|
||||
|
||||
@ -48,9 +48,18 @@
|
||||
# 3. "./ci-cleanup.sh" with commands to clean up temporary build resources,
|
||||
# to be run after this step finishes / when this step is aborted.
|
||||
|
||||
set -eu
|
||||
|
||||
function sdk_bootstrap() {
|
||||
# Run a subshell, so the traps, environment changes and global
|
||||
# variables are not spilled into the caller.
|
||||
(
|
||||
set -euo pipefail
|
||||
|
||||
_sdk_bootstrap_impl "${@}"
|
||||
)
|
||||
}
|
||||
# --
|
||||
|
||||
function _sdk_bootstrap_impl() {
|
||||
local seed_version="$1"
|
||||
local version="$2"
|
||||
local coreos_git="${3-}"
|
||||
|
||||
@ -29,9 +29,18 @@
|
||||
# 2. "./ci-cleanup.sh" with commands to clean up temporary build resources,
|
||||
# to be run after this step finishes / when this step is aborted.
|
||||
|
||||
set -eu
|
||||
|
||||
function sdk_container_build() {
|
||||
# Run a subshell, so the traps, environment changes and global
|
||||
# variables are not spilled into the caller.
|
||||
(
|
||||
set -euo pipefail
|
||||
|
||||
_sdk_container_build_impl "${@}"
|
||||
)
|
||||
}
|
||||
# --
|
||||
|
||||
function _sdk_container_build_impl() {
|
||||
: ${ARCH:="amd64"}
|
||||
|
||||
source ci-automation/ci_automation_common.sh
|
||||
|
||||
@ -74,8 +74,6 @@
|
||||
# script would need to make anyway. For more information, please refer
|
||||
# to the vendor_test.sh file.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Download torcx package and manifest, add build cache URL to manifest
|
||||
# so the docker.torcx-manifest-pkgs test can use it.
|
||||
function __prepare_torcx() {
|
||||
@ -102,6 +100,17 @@ function __prepare_torcx() {
|
||||
# --
|
||||
|
||||
function test_run() {
|
||||
# Run a subshell, so the traps, environment changes and global
|
||||
# variables are not spilled into the caller.
|
||||
(
|
||||
set -euo pipefail
|
||||
|
||||
_test_run_impl "${@}"
|
||||
)
|
||||
}
|
||||
# --
|
||||
|
||||
function _test_run_impl() {
|
||||
local arch="$1" ; shift
|
||||
local image="$1"; shift
|
||||
|
||||
|
||||
@ -31,9 +31,18 @@
|
||||
# 2. "./ci-cleanup.sh" with commands to clean up temporary build resources,
|
||||
# to be run after this step finishes / when this step is aborted.
|
||||
|
||||
set -eu
|
||||
|
||||
function vm_build() {
|
||||
# Run a subshell, so the traps, environment changes and global
|
||||
# variables are not spilled into the caller.
|
||||
(
|
||||
set -euo pipefail
|
||||
|
||||
_vm_build_impl "${@}"
|
||||
)
|
||||
}
|
||||
# --
|
||||
|
||||
function _vm_build_impl() {
|
||||
local arch="$1"
|
||||
shift
|
||||
# $@ now contains image formats to build
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user