Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note

The use of small containers should be avoided when publishing API Builder applications using the Appcelerator CLI commands. For optimum memory performance, use medium or larger size containers.

...

  1. Create a new API Builder app:

    Code Block
    languagebash
    $ appc new -t arrow
    Appcelerator Command-Line Interface, version 7.0.0
    Copyright (c) 2014-2017, Appcelerator, Inc.  All Rights Reserved.
     
    ? What's the project name? appctest
    *** new completed. ***
  2. Update appc.json environment to add extra_hosts if you haven't setup set up a DNS yet. If your cluster uses appctest.com as a domain name, then you need to add NODE_ENV as well:

    Code Block
    languagebash
    $ cd appctest
    $ vi appc.json
    {
    ...
      "cloud": {
        ...
        // Change your container size here
        "container": "Medium",
        // Number of containers for your app
        "minimum": 3,
        // Maximum number of containers for you app when autoscalling kicks in
        "maximum": 5,
        // NODE_ENV is only needed if
        // a. You are running in an alternately-named environment (like staging)
        // b. You are running on a domain with appctest in the name
        "environment": {"NODE_ENV":"PRODUCTION","extra_hosts":"54.212.208.81 api.cloudapp-1.appctest.com"},
        ...
       }
    }
  3. Execute appc install (required prior to the release of version 6.2.0).
  4. Then publish the app normally by executing this command: appc publish

...

  1. Create a new API Builder app:

    Code Block
    languagebash
    $ appc new -t arrow
    Appcelerator Command-Line Interface, version 7.0.0
    Copyright (c) 2014-2017, Appcelerator, Inc.  All Rights Reserved.
     
    ? What's the project name? appctest
    *** new completed. ***
  2. Prepare a Dockerfile by creating a Dockerfile under your project directory and use the start_app script. Use of start_app is required if you want to able to retrieve access and console logs of your app with using the user of  appc cloud logcat and appc cloud accesslog commands. The following is a sample Dockerfile for an API Builder app:

    Code Block
    languagebash
    FROM mhart/alpine-node:5.12.0
    # Install curl command for app health check
    RUN apk add --no-cache curl
    
    # This is the script to start app
    COPY start_app /usr/local/bin/
    RUN chmod 755 /usr/local/bin/start_app
    
    RUN mkdir -p /opt/app
    WORKDIR /opt/app
    
    COPY package.json /opt/app
    COPY app.js /opt/app
    COPY README.md /opt/app
    
    RUN npm install
    
    
    ENTRYPOINT ["/usr/local/bin/start_app"]
  3. The start_app script should look something like this and be placed under the project directory with the Dockerfile:

    Code Block
    linenumberstrue
    languagebash
    #!/bin/sh
    
    APP_DIR="/opt/app"
    
    # command to retrieve the containerId inside docker container
    CONTAINID=$(cat /proc/1/cgroup | grep 'docker/' | tail -1 | sed 's/^.*\///' | cut -c 1-12)
    
    # replace the fake "serverId" with the real container id
    if [ ! -z $CONTAINID ]; then
    	ARROWCLOUD_APP_LOG_DIR=$(echo ${ARROWCLOUD_APP_LOG_DIR} | sed "s/serverId/${CONTAINID}/")
    	export serverId=${CONTAINID}
    fi	
    
    APP_LOG_DIR="/ctdebuglog/${ARROWCLOUD_APP_LOG_DIR}"
    APP_DEBUG_LOG_DIR="${APP_LOG_DIR}/debug"
    APP_REQUESTS_LOG_DIR="${APP_LOG_DIR}/requests"
    
    mkdir -p "${APP_DEBUG_LOG_DIR}"
    if [ $? -ne 0 ]; then
    	echo "Failed to create ${APP_DEBUG_LOG_DIR}"
    	exit 1
    fi	
    
    mkdir -p "${APP_REQUESTS_LOG_DIR}"
    if [ $? -ne 0 ]; then
    	echo "Failed to create ${APP_REQUESTS_LOG_DIR}"
    	exit 1
    fi	
    
    # make a symbolic link from ${APP_REQUESTS_LOG_DIR} to /ctlog to satisfy appc-logger
    ln -s ${APP_REQUESTS_LOG_DIR} /ctlog
    if [ $? -ne 0 ]; then
    	echo "Failed to create link from ${APP_REQUESTS_LOG_DIR} to /ctlog"
    	exit 1
    fi	
    
    STDOUT_LOG_FILE="${APP_DEBUG_LOG_DIR}/stdout.log"
    STDERR_LOG_FILE="${APP_DEBUG_LOG_DIR}/stderr.log"
    
    # curl is used for health-check when creating docker service for an app.
    curl >/dev/null 2>&1
    if [ $? -eq 127 ]; then
    	echo "curl not found! App image must include curl for health-check purpose." >> ${STDOUT_LOG_FILE} 2>>${STDERR_LOG_FILE}
    	exit 1
    fi	
    
    cd $APP_DIR
    echo "[app_launcher] starting application via \"$DAEMON $DAEMON_ARGS\"" >> ${STDOUT_LOG_FILE} 2>>${STDERR_LOG_FILE}
    # start the app in the same process which is the main process(pid 1), so that the app can get signals
    exec node app.js >> ${STDOUT_LOG_FILE} 2>>${STDERR_LOG_FILE}
    RETVAL=$?
    if [ $RETVAL -ne 0 ]; then
    	echo "[app_launcher] application is over with status code $RETVAL." >> ${STDOUT_LOG_FILE} 2>>${STDERR_LOG_FILE}
    else
    	echo "[app_launcher] application is over." >> ${STDOUT_LOG_FILE} 2>>${STDERR_LOG_FILE}
    fi
    exit $RETVAL
  4. Execute appc publish. You will need to provide the app version using the --app-version flag. You should always provide the app name since Appcelerator CLI will not scan package.json as it would normally with source code publishing that does obtain the app name. Using appc publish will build the Docker image by using the provided Dockerfile and push the image to API Runtime Services directly:

    Code Block
    languagebash
    $ cd appctest
    $ appc publish --app-version 1.0.0 appctest
  5. If you need to scale up the number of servers, execute these commands:

    Code Block
    languagebash
    # Set maximum number of containers allowed for appctest
    $ appc cloud config appctest --maxsize <size>
    # Set current number of containers for appctest as long as the cluster has enough resource)
    $ appc cloud config appcteest --minsize <size>

...

Alternatively, after preparing your Dockerfile and start_app script describe above, you can build the Docker image yourself and publish the image to API Runtime Services: 

  1. Build Docker image:

    Code Block
    languagebash
    $ cd appctest
    $ docker build -t appctestimage .
    # Double check the image presents locally
    $ docker images |grep appctestimage
    appctestimage               latest              869918dab71b        43 minutes ago      277 MB
  2. Next, publish the image directly. Ensure that you provide the app version and name and image name by using the --app-versionappname, and --image flags:

    Code Block
    languagebash
    $ cd appctest
    $ appc publish --app-version 1.0.0 --image appctestimage appctest
  3. If you need to scale up the number of servers, execute these commands:

    Code Block
    languagebash
    # Set maximum number of containers allowed for appctest
    $ appc cloud config appctest --maxsize <size>
    # Set current number of containers for appctest as long as the cluster has enough resource)
    $ appc cloud config appcteest --minsize <size>

Note: If you haven't setup set up your DNS yet, your app publish may fail with the following error:

...