Versions Compared

Key

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

...

  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 using the 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
    collapsetrue
    #!/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>

...