在Jelastic上部署docker容器的示例代码

时间:2015-05-30 14:21:30

标签: jelastic

任何人都可以提供示例代码来在Jelastic上部署docker容器吗?我正在阅读Jelastic官方API文档,看起来这条信息缺失了。

非常感谢!

1 个答案:

答案 0 :(得分:0)

这是使用bash创建新环境的示例:

#!/bin/bash

hoster_api_url='app.cloudplatform.hk'
platform_app_id='77047754c838ee6badea32b5afab1882'
email=''
password=''
docker_image='tutum/wordpress'
docker_tag='latest'
env_name='testenv-'$(((RANDOM % 10000) + 1))

WORK_DIR=$(dirname $0)
LOG="$WORK_DIR/$hoster_api_url.log"

log() {
    echo -e "\n$@" >>"$LOG"
}

login() {
    SESSION=$(curl -s "http://$hoster_api_url/1.0/users/authentication/rest/signin?appid=$platform_app_id&login=$email&password=$password" | \
        sed -r 's/^.*"session":"([^"]+)".*$/\1/')
    [ -n "$SESSION" ] || {
        log "Failed to login with credentials supplied"
        exit 0
    }
}

create_environment() {
    log "=============================== START CREATING $env_name | $(date +%d.%m.%y_%H-%M-%S) ==============================="

        request='nodes=[{"nodeType":"docker","extip":false,"count":1,"fixedCloudlets":1,"flexibleCloudlets":16,"fakeId":-1,"dockerName":"'$docker_image'","dockerTag":"'$docker_tag'","displayName":"'$docker_image':'$docker_tag'","metadata":{"layer":"cp"}}]&env={"pricingType":"HYBRID","region":"default_region","shortdomain":"'$env_name'"}&actionkey=createenv;'$env_name'&appid='$platform_app_id'&session='$SESSION

        log "$request"

        curl -s -X POST --data $request "https://$hoster_api_url/1.0/environment/environment/rest/createenvironment" >> "$LOG"

    log "=============================== STOP CREATING $env_name | $(date +%d.%m.%y_%H-%M-%S) ==============================="
}


login
create_environment 

您还可以看到示例there