Edit on GitHub
Report issue
Page history

Vapor on App Engine

Author(s): @asciimike ,   Published: 2017-03-21

Contributed by the Google Cloud community. Not official Google documentation.

This tutorial shows a sample Swift app built with Vapor deployed to App Engine.

Vapor is "a web framework and server for Swift that works on macOS and Ubuntu." It is open source on GitHub.

This tutorial assumes basic familiarity with Swift programming.


  • Create a Swift "Hello, world" app that uses the Vapor framework.
  • Deploy the app to the App Engine flexible environment.


This tutorial uses billable components of Google Cloud, including App Engine flexible environment.

Use the Pricing Calculator to generate a cost estimate based on your projected usage.

Before you begin

  1. Create a project in the Cloud Console.
  2. Enable billing for your project.
  3. Install the Cloud SDK.

Handling dependencies

We'll use the Swift Package Manager to manage our app's dependencies.

  1. Create a Package.swift file with the following contents:

    import PackageDescription
    let package = Package(
        name: "VaporGAE",
        targets: [
            Target(name: "VaporGAE", dependencies: [])
        dependencies: [
            .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1, minor: 1)

Writing the server

  1. Create a main.swift with the following contents:

    import Foundation
    import Vapor
    let drop = Droplet()
    // Respond to App Engine health check requests
    // TODO: see #2
    // Basic GET request
    // TODO: see #3
    // Start server on 8080 (default)
  2. Create a route to handle App Engine health-check requests (per the custom runtime docs):

    // Respond to App Engine health check requests
    drop.get("/_ah/health") { request in
        print("ALL - /_ah/health route handler...")
        return "OK"
  3. Create a route to handle GET requests to /hello:

    // Basic GET request
    drop.get("/hello") { request in
        print("GET - /hello route handler...")
        return "Hello from Vapor on App Engine flexible environment!"

Creating the Dockerfile

Since Swift doesn't have an officially supported App Engine runtime, we'll create our own.

  1. Create a Dockerfile with the following contents:

    FROM ibmcom/swift-ubuntu:latest
    LABEL Description="Docker image for Swift + Vapor on App Engine flexible environment."
    # Expose default port for App Engine
    EXPOSE 8080
    # Add app source
    ADD . /app
    WORKDIR /app
    # Build release
    RUN swift build --configuration release
    # Run the app
    ENTRYPOINT [".build/release/VaporGAE"]

Deploying the app

  1. Create an app.yaml file with the following contents:

    runtime: custom
    env: flex
  2. Run the following command to deploy your app (make take several minutes):

    gcloud app deploy
  3. Run the following command to view your app, then append /hello to the URL:

    gcloud app browse

If all goes well, you should see "Hello from Swift on App Engine flexible environment!".

Submit a tutorial

Share step-by-step guides

Submit a tutorial

Request a tutorial

Ask for community help

Submit a request

View tutorials

Search Google Cloud tutorials

View tutorials

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see our Site Policies. Java is a registered trademark of Oracle and/or its affiliates.