0

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!

J John
  • 5,591
  • 3
  • 11
  • 9
  • Hello John, please, could you clarify about what official API document you are saying about? – leo May 31 '15 at 01:46
  • 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 May 31 '15 at 06:30
  • 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 May 31 '15 at 12:13
  • @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 Jun 01 '15 at 12:21

1 Answers1

0

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

Aless
  • 289
  • 1
  • 9
  • Thank you very much, I will give a try in my lab. – J John Jun 02 '15 at 12:28
  • Hi @Aless, may I know the document you are referring to? How did you know what parameter we can use in the request? – J John Jun 02 '15 at 13:31
  • Hello @J John! I have changed the script and now you can use dockers from the private registry. Pay your attention that some variables will be changed in the feature Jelastic releases. New script you can find [there](http://pastebin.com/3ATu5BgP). – Aless Jun 02 '15 at 22:59
  • Thanks @Aless, this is really helpful, I also need to write code to delete container and so many other tasks, I don't expect that you guys can write all the sample code for me, but can you at least send me more references so I can do it myself? Tahnks again. – J John Jun 04 '15 at 08:40
  • Hi @Aless, I am looking at the java sample code, looks like environmentService() is the one that I should be using if I want to deploy a docker container in my existing environment, can you show me how to use that? – J John Jun 05 '15 at 13:49
  • I would appreciate if I can get further information, apparently lack of documentation is prevent me from migrating to Jelastic. – J John Jun 06 '15 at 12:31
  • John, have you solved the issue? Looks like missed this thread. – Ruslan Jul 03 '15 at 09:27