Skip to content

Commit

Permalink
Add ability to specify image disk size
Browse files Browse the repository at this point in the history
  • Loading branch information
superseed committed Apr 25, 2018
1 parent ac0f499 commit 5a5f77a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
18 changes: 12 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def images = []
def image_versions = [:]
def image_version = [:]
def removable_tags = []

pipeline {
Expand Down Expand Up @@ -48,9 +48,15 @@ pipeline {
script {
manifest = readFile("${env.IMAGE_DIR_BASE}/manifest.json")
manifest_data = new groovy.json.JsonSlurperClassic().parseText(manifest)
image_versions = manifest_data['images']
env.IMAGE_DIR = env.IMAGE_DIR_BASE + '/' + image_versions[env.IMAGE_VERSION]['directory']
env.MARKETPLACE_IMAGE_NAME = image_versions[env.IMAGE_VERSION]['marketplace-name']
image_version = manifest_data['images'][env.IMAGE_VERSION]
env.IMAGE_DIR = env.IMAGE_DIR_BASE + '/' + image_version['directory']
env.MARKETPLACE_IMAGE_NAME = image_version['marketplace-name']
env.IMAGE_DISK_SIZE = "50G"
if (image_version.containsKey('options')) {
if (image_version['options'].containsKey('disk-size')) {
env.IMAGE_DISK_SIZE = image_version['options']['disk-size']
}
}
env.BUILD_OPTS = "--pull"
env.LOG_LEVEL = params.logLevel
}
Expand All @@ -66,7 +72,7 @@ pipeline {
stage("Create image on Scaleway") {
steps {
script {
for (String arch in image_versions[env.IMAGE_VERSION]['architectures']) {
for (String arch in image_version['architectures']) {
echo "Creating image for $arch"
sh "make ARCH=$arch IMAGE_DIR=${env.IMAGE_DIR} EXPORT_DIR=${env.EXPORT_DIR_BASE}/$arch BUILD_OPTS='${env.BUILD_OPTS}' scaleway_image"
script {
Expand Down Expand Up @@ -127,7 +133,7 @@ pipeline {
message = groovy.json.JsonOutput.toJson([
type: "image",
data: [
marketplace_id: image_versions[env.IMAGE_VERSION]['marketplace-id'],
marketplace_id: image_version['marketplace-id'],
versions: images
]
])
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ ifdef IMAGE_BOOTSCRIPT_$(TARGET_SCW_ARCH)
IMAGE_BOOTSCRIPT = $(IMAGE_BOOTSCRIPT_$(TARGET_SCW_ARCH))
endif

IMAGE_DISK_SIZE ?= 50G

ifeq ($(shell which scw-metadata >/dev/null 2>&1; echo $$?), 0)
IS_SCW_HOST := y
LOCAL_SCW_REGION := $(shell scw-metadata --cached LOCATION_ZONE_ID)
Expand Down Expand Up @@ -156,7 +158,7 @@ from-rootfs-common: rootfs.tar
ifeq ($(SERVE_ASSETS), y)
scripts/assets_server.sh start $(SERVE_PORT) $(ASSETS_DIR)
endif
scripts/create_image_live_from_rootfs.sh "$(ROOTFS_URL)" "$(IMAGE_TITLE)" "$(TARGET_SCW_ARCH)" "$(IMAGE_BOOTSCRIPT)" "$(BUILD_METHOD)"
scripts/create_image_live_from_rootfs.sh "$(ROOTFS_URL)" "$(IMAGE_TITLE)" "$(TARGET_SCW_ARCH)" "$(IMAGE_DISK_SIZE)" "$(IMAGE_BOOTSCRIPT)" "$(BUILD_METHOD)"
ifeq ($(SERVE_ASSETS), y)
scripts/assets_server.sh stop $(SERVE_PORT)
endif
Expand Down
11 changes: 8 additions & 3 deletions scripts/create_image_live_from_rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ fi
rootfs_url=$1
image_name=$2
arch=$3
image_bootscript=$4
build_method=$5
image_disk_size=$4
image_bootscript=$5
build_method=$6

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

Expand All @@ -22,20 +23,24 @@ if [ "$arch" = "arm" ]; then
build_method="unpartitioned-from-rootfs"
bootscript_id=$(grep -E "$REGION\|x86_64\>" bootscript_ids | cut -d'|' -f3)
server_type="VC1M"
minimum_total_volume_size=100
server_creation_opts=""
elif [ "$arch" = "x86_64" ]; then
server_type="VC1M"
minimum_total_volume_size=100
server_creation_opts=""
elif [ "$arch" = "arm64" ]; then
server_type="ARM64-4GB"
minimum_total_volume_size=100
server_creation_opts=""
fi
server_creation_opts="$server_creation_opts --volume='$(( $minimum_total_volume_size - ${image_disk_size%?} - 50 ))G'"

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

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

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
Expand Down

0 comments on commit 5a5f77a

Please sign in to comment.