Deploying a Static Web Site

You can quickly deploy a static web site (no backend dependencies) to Apcera using the built-in static-site staging pipeline. The static-site staging pipeline creates an application package containing your web site files and an NGINX package to serve the site files.

To create and deploy a static web site:

  1. Create a new project directory (mywebsite, for example).
  2. Create a file named index.html containing the following HTML and save it to the project directory.

     <!-- index.html -->
     <!DOCTYPE html>
     <html lang="en">
       <head>
         <meta charset="utf-8">
         <title>Hello, Apcera!</title>
       </head>
       <body>
         <h1>Hello, Apcera!</h1>
       </body>
     </html>
    
  3. Open a terminal and change to the mywebsite directory.

     cd ~/mywebsite
    
  4. Run the following command to create and start an application from your web site files:

     apc app create mywebsite --start
     Deploy path [/Users/admin/dev/mywebsite]:
     Instances [1]:
     Memory [256MB]:
     ╭─────────────────────────────────────────────────────╮
     │                Application Settings                 │
     ├───────────────────┬─────────────────────────────────┤
     │              FQN: │ job::/sandbox/admin::mywebsite  │
     │        Directory: │ /Users/admin/dev/mywebsite      │
     │        Instances: │ 1                               │
     │          Restart: │ always                          │
     │ Staging Pipeline: │ (will be auto-detected)         │
     │              CPU: │ 0ms/s (uncapped)                │
     │           Memory: │ 256MiB                          │
     │             Disk: │ 1GiB                            │
     │           NetMin: │ 5Mbps                           │
     │           Netmax: │ 0Mbps (uncapped)                │
     │         Route(s): │ auto                            │
     │  Startup Timeout: │ 30 (seconds)                    │
     │     Stop Timeout: │ 5 (seconds)                     │
     ╰───────────────────┴─────────────────────────────────╯
    

    APC prompts you to confirm information about the application to deploy, such as the directory that contains the app's source files, the number of application instances to create, and the amount of memory to allocate to each instance. Press Enter at each prompt to accept the defaults. A summary table displays the properties for the new application, a few of which are shown below. All of these properties can be set on the command line when calling apc app create or apc app update (see )

    • FQN – The application package's fully-qualified name.
    • Staging Pipeline – The staging pipeline to use to stage the application for deployment. In this case, because we did not specify a staging pipeline in the command string, APC will detect which staging pipeline to use based on the contents of our application directory.
    • Route – Indicates the URL where the web site will be accessible. In this case, we let the cluster generate a route for us that consists of the application name concatenated with six random characters. You can specify a specific route with the --routes command line parameter.
  5. Press the enter key or "Y" to confirm and start the staging process.

     Is this correct? [Y/n]:
     Packaging... done
     Creating package "mywebsite"... done
     Uploading package contents... done!
     [staging] Subscribing to the staging process...
     [staging] Beginning staging with 'stagpipe::/apcera::static-site' pipeline, 1 stager(s) defined.
     [staging] Launching instance of stager 'static-site'...
     [staging] Downloading package for processing...
     [staging] Validating an index.htm or index.html file exists
     [staging] Staging is complete.
     Creating app "mywebsite"... done
     Start Command: ./start_nginx
     Waiting for the application to start...
     App should be accessible at "http://mywebsite-k6b68x.tutorial.apcera-platform.io"
    

    Once the application has been deployed successfully, the output indicates the URL where you can view the web site ("App should be accessible at <URL>"). Open this URL in your browser to see the running web site.

Going Further: Inspecting the Application Package

When you deploy an application using apc app create a package is created with the same name. The package contains the actual binary and metadata about that package. To inspect the package you created when you deployed the web site, run the apc package show command, for example:

$ apc package show mywebsite
╭───────────────────┬─────────────────────────────────────────╮
│ Package:          │ mywebsite                               │
├───────────────────┼─────────────────────────────────────────┤
│ FQN:              │ package::/sandbox/admin::mywebsite      │
│ State:            │ ready                                   │
│                   │                                         │
│ Created by:       │ admin@apcera.me                         │
│ Created at:       │ 2016-04-08 22:23:21.672027498 +0000 UTC │
│ Updated by:       │ admin@apcera.me                         │
│ Updated at:       │ 2016-04-08 22:23:23.84183966 +0000 UTC  │
│                   │                                         │
│ Staging Pipeline: │ stagpipe::/apcera::static-site          │
│ Stagers:          │ job::/apcera/stagers::static-site       │
│ Dependencies:     │ package: nginx                          │
│ Environment:      │ START_COMMAND="./start_nginx"           │
│                   │ START_PATH="/app"                       │
╰───────────────────┴─────────────────────────────────────────╯

The output shows that Dependencies field indicates the application package has a dependency on NGINX, which is one of the default packages included in a typical Apcera Platform cluster (see Supported Environments and Software). Also note the START_COMMAND and START_PATH environment variables assigned to the package (see Special package environment variables).