0
votes

Can anyone provide sample code to deploy docker container on Jelastic? I was reading Jelastic official API document, it looks like this piece of information is missing.

Many thanks!

1
Hello John, please, could you clarify about what official API document you are saying about? - leo
John, can you describe your use case in details? Docker part is still not covered very well in documentation, but I believe we can help. - Ruslan
Dear leo and @Ruslan, this is what I want to do: 1. in Jelastic admin panel, click on "Change Environment Topology" 2. Click on "Docker" Tab 3. Add a docker container 4. Go to "Custom" tab and use image in my private repository. How can do it programmatically? Where I can find sample code? - J John
@ruslan, I just sent an email to Jelastic and I had to I am shocked when I know who you are :) , basically we want to automatically deploy our docker container using our custom image on Jelastic, if you can provide us some sample code or guidance it will be highly appreciated! - J John

1 Answers

0
votes

This is a sample of the creating new environment using 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 

Also you can see Samples there