Skip to content

Commit 5a5f77a

Browse files
committed
Add ability to specify image disk size
1 parent ac0f499 commit 5a5f77a

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

Jenkinsfile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def images = []
2-
def image_versions = [:]
2+
def image_version = [:]
33
def removable_tags = []
44

55
pipeline {
@@ -48,9 +48,15 @@ pipeline {
4848
script {
4949
manifest = readFile("${env.IMAGE_DIR_BASE}/manifest.json")
5050
manifest_data = new groovy.json.JsonSlurperClassic().parseText(manifest)
51-
image_versions = manifest_data['images']
52-
env.IMAGE_DIR = env.IMAGE_DIR_BASE + '/' + image_versions[env.IMAGE_VERSION]['directory']
53-
env.MARKETPLACE_IMAGE_NAME = image_versions[env.IMAGE_VERSION]['marketplace-name']
51+
image_version = manifest_data['images'][env.IMAGE_VERSION]
52+
env.IMAGE_DIR = env.IMAGE_DIR_BASE + '/' + image_version['directory']
53+
env.MARKETPLACE_IMAGE_NAME = image_version['marketplace-name']
54+
env.IMAGE_DISK_SIZE = "50G"
55+
if (image_version.containsKey('options')) {
56+
if (image_version['options'].containsKey('disk-size')) {
57+
env.IMAGE_DISK_SIZE = image_version['options']['disk-size']
58+
}
59+
}
5460
env.BUILD_OPTS = "--pull"
5561
env.LOG_LEVEL = params.logLevel
5662
}
@@ -66,7 +72,7 @@ pipeline {
6672
stage("Create image on Scaleway") {
6773
steps {
6874
script {
69-
for (String arch in image_versions[env.IMAGE_VERSION]['architectures']) {
75+
for (String arch in image_version['architectures']) {
7076
echo "Creating image for $arch"
7177
sh "make ARCH=$arch IMAGE_DIR=${env.IMAGE_DIR} EXPORT_DIR=${env.EXPORT_DIR_BASE}/$arch BUILD_OPTS='${env.BUILD_OPTS}' scaleway_image"
7278
script {
@@ -127,7 +133,7 @@ pipeline {
127133
message = groovy.json.JsonOutput.toJson([
128134
type: "image",
129135
data: [
130-
marketplace_id: image_versions[env.IMAGE_VERSION]['marketplace-id'],
136+
marketplace_id: image_version['marketplace-id'],
131137
versions: images
132138
]
133139
])

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ ifdef IMAGE_BOOTSCRIPT_$(TARGET_SCW_ARCH)
6262
IMAGE_BOOTSCRIPT = $(IMAGE_BOOTSCRIPT_$(TARGET_SCW_ARCH))
6363
endif
6464

65+
IMAGE_DISK_SIZE ?= 50G
66+
6567
ifeq ($(shell which scw-metadata >/dev/null 2>&1; echo $$?), 0)
6668
IS_SCW_HOST := y
6769
LOCAL_SCW_REGION := $(shell scw-metadata --cached LOCATION_ZONE_ID)
@@ -156,7 +158,7 @@ from-rootfs-common: rootfs.tar
156158
ifeq ($(SERVE_ASSETS), y)
157159
scripts/assets_server.sh start $(SERVE_PORT) $(ASSETS_DIR)
158160
endif
159-
scripts/create_image_live_from_rootfs.sh "$(ROOTFS_URL)" "$(IMAGE_TITLE)" "$(TARGET_SCW_ARCH)" "$(IMAGE_BOOTSCRIPT)" "$(BUILD_METHOD)"
161+
scripts/create_image_live_from_rootfs.sh "$(ROOTFS_URL)" "$(IMAGE_TITLE)" "$(TARGET_SCW_ARCH)" "$(IMAGE_DISK_SIZE)" "$(IMAGE_BOOTSCRIPT)" "$(BUILD_METHOD)"
160162
ifeq ($(SERVE_ASSETS), y)
161163
scripts/assets_server.sh stop $(SERVE_PORT)
162164
endif

scripts/create_image_live_from_rootfs.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ fi
1111
rootfs_url=$1
1212
image_name=$2
1313
arch=$3
14-
image_bootscript=$4
15-
build_method=$5
14+
image_disk_size=$4
15+
image_bootscript=$5
16+
build_method=$6
1617

1718
key=$(cat ${SSH_KEY_FILE}.pub | cut -d' ' -f1,2 | tr ' ' '_')
1819

@@ -22,20 +23,24 @@ if [ "$arch" = "arm" ]; then
2223
build_method="unpartitioned-from-rootfs"
2324
bootscript_id=$(grep -E "$REGION\|x86_64\>" bootscript_ids | cut -d'|' -f3)
2425
server_type="VC1M"
26+
minimum_total_volume_size=100
2527
server_creation_opts=""
2628
elif [ "$arch" = "x86_64" ]; then
2729
server_type="VC1M"
30+
minimum_total_volume_size=100
2831
server_creation_opts=""
2932
elif [ "$arch" = "arm64" ]; then
3033
server_type="ARM64-4GB"
34+
minimum_total_volume_size=100
3135
server_creation_opts=""
3236
fi
37+
server_creation_opts="$server_creation_opts --volume='$(( $minimum_total_volume_size - ${image_disk_size%?} - 50 ))G'"
3338

3439
server_name="image-writer-$(date +%Y-%m-%d_%H:%M)"
3540
signal_port=$(shuf -i 10000-60000 -n 1)
3641
server_env="build_method=$build_method rootfs_url=$rootfs_url signal_build_done_port=$signal_port AUTHORIZED_KEY=$key $SERVER_ENV"
3742

38-
server_id=$(create_server "$server_type" "$server_creation_opts" "$server_name" 50G "$server_env" "$bootscript_id")
43+
server_id=$(create_server "$server_type" "$server_creation_opts" "$server_name" "$image_disk_size" "$server_env" "$bootscript_id")
3944
[ $? -eq 0 ] || exiterr
4045

4146
curl --fail -s -X PATCH -H "X-Auth-Token: ${SCW_TOKEN}" -H "Content-type: application/json" -d '{"boot_type":"bootscript"}' "https://cp-${REGION}.scaleway.com/servers/${server_id}" >/dev/null || exiterr

0 commit comments

Comments
 (0)