def _set_current_port(app_definition, service_port):
    """Set the service port on the provided app definition.

    This works for both Dockerised and non-Dockerised applications.
    """
    try:
        port_mappings = app_definition['container']['docker']['portMappings']
        port_mappings[0]['servicePort'] = service_port
    except (KeyError, IndexError):
        app_definition['ports'][0] = service_port

    return app_definition