Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove beta Salesforce Functions support #83

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Removed

- Removed support for Salesforce Functions. ([#83](https://github.com/heroku/buildpacks-python/pull/83))

## [0.5.0] - 2023-07-24

Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ libcnb = "0.13"
libherokubuildpack = { version = "0.13", default-features = false, features = ["log"] }
serde = "1"
tar = { version = "0.4", default-features = false }
toml = "0.7"
ureq = { version = "2", default-features = false, features = ["tls"] }

[dev-dependencies]
Expand Down
58 changes: 0 additions & 58 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::layers::pip_dependencies::PipDependenciesLayerError;
use crate::layers::python::PythonLayerError;
use crate::package_manager::DeterminePackageManagerError;
use crate::project_descriptor::ProjectDescriptorError;
use crate::python_version::{PythonVersion, PythonVersionError, DEFAULT_PYTHON_VERSION};
use crate::runtime_txt::{ParseRuntimeTxtError, RuntimeTxtError};
use crate::salesforce_functions::{CheckSalesforceFunctionError, FUNCTION_RUNTIME_PROGRAM_NAME};
use crate::utils::{CommandError, DownloadUnpackArchiveError};
use crate::BuildpackError;
use indoc::{formatdoc, indoc};
Expand Down Expand Up @@ -42,38 +40,18 @@ pub(crate) fn on_error(error: libcnb::Error<BuildpackError>) {

fn on_buildpack_error(error: BuildpackError) {
match error {
BuildpackError::CheckSalesforceFunction(error) => on_check_salesforce_function_error(error),
BuildpackError::DetectIo(io_error) => log_io_error(
"Unable to complete buildpack detection",
"determining if the Python buildpack should be run for this application",
&io_error,
),
BuildpackError::DeterminePackageManager(error) => on_determine_package_manager_error(error),
BuildpackError::PipDependenciesLayer(error) => on_pip_dependencies_layer_error(error),
BuildpackError::ProjectDescriptor(error) => on_project_descriptor_error(error),
BuildpackError::PythonLayer(error) => on_python_layer_error(error),
BuildpackError::PythonVersion(error) => on_python_version_error(error),
};
}

fn on_project_descriptor_error(error: ProjectDescriptorError) {
match error {
ProjectDescriptorError::Io(io_error) => log_io_error(
"Unable to read project.toml",
"reading the (optional) project.toml file",
&io_error,
),
ProjectDescriptorError::Parse(toml_error) => log_error(
"Invalid project.toml",
formatdoc! {"
A parsing/validation error error occurred whilst loading the project.toml file.

Details: {toml_error}
"},
),
};
}

fn on_determine_package_manager_error(error: DeterminePackageManagerError) {
match error {
DeterminePackageManagerError::Io(io_error) => log_io_error(
Expand Down Expand Up @@ -239,42 +217,6 @@ fn on_pip_dependencies_layer_error(error: PipDependenciesLayerError) {
};
}

fn on_check_salesforce_function_error(error: CheckSalesforceFunctionError) {
match error {
CheckSalesforceFunctionError::Io(io_error) => log_io_error(
"Unable to run the Salesforce Functions self-check command",
&format!("running the '{FUNCTION_RUNTIME_PROGRAM_NAME} check' command"),
&io_error,
),
CheckSalesforceFunctionError::NonZeroExitStatus(output) => log_error(
"The Salesforce Functions self-check failed",
formatdoc! {"
The '{FUNCTION_RUNTIME_PROGRAM_NAME} check' command failed ({exit_status}), indicating
there is a problem with the Python Salesforce Function in this project.

Details:
{stderr}
",
exit_status = output.status,
stderr = String::from_utf8_lossy(&output.stderr),
},
),
CheckSalesforceFunctionError::ProgramNotFound => log_error(
"The Salesforce Functions package is not installed",
formatdoc! {"
The '{FUNCTION_RUNTIME_PROGRAM_NAME}' program that is required for Python Salesforce
Functions could not be found.

Check that the 'salesforce-functions' Python package is listed as a
dependency in 'requirements.txt'.

If this project is not intended to be a Salesforce Function, remove the
'type = \"function\"' declaration from 'project.toml' to skip this check.
"},
),
};
}

fn log_io_error(header: &str, occurred_whilst: &str, io_error: &io::Error) {
// We don't suggest opening a support ticket, since a subset of I/O errors can be caused
// by issues in the application. In the future, perhaps we should try and split these out?
Expand Down
26 changes: 2 additions & 24 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@ mod errors;
mod layers;
mod package_manager;
mod packaging_tool_versions;
mod project_descriptor;
mod python_version;
mod runtime_txt;
mod salesforce_functions;
mod utils;

use crate::layers::pip_cache::PipCacheLayer;
use crate::layers::pip_dependencies::{PipDependenciesLayer, PipDependenciesLayerError};
use crate::layers::python::{PythonLayer, PythonLayerError};
use crate::package_manager::{DeterminePackageManagerError, PackageManager};
use crate::packaging_tool_versions::PackagingToolVersions;
use crate::project_descriptor::ProjectDescriptorError;
use crate::python_version::PythonVersionError;
use crate::salesforce_functions::CheckSalesforceFunctionError;
use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder};
use libcnb::data::layer_name;
use libcnb::detect::{DetectContext, DetectResult, DetectResultBuilder};
Expand Down Expand Up @@ -55,8 +51,6 @@ impl Buildpack for PythonBuildpack {
fn build(&self, context: BuildContext<Self>) -> libcnb::Result<BuildResult, Self::Error> {
// We perform all project analysis up front, so the build can fail early if the config is invalid.
// TODO: Add a "Build config" header and list all config in one place?
let is_function = salesforce_functions::is_function_project(&context.app_dir)
.map_err(BuildpackError::ProjectDescriptor)?;
let package_manager = package_manager::determine_package_manager(&context.app_dir)
.map_err(BuildpackError::DeterminePackageManager)?;

Expand Down Expand Up @@ -86,7 +80,7 @@ impl Buildpack for PythonBuildpack {

// Create the layers for the application dependencies and package manager cache.
// In the future support will be added for package managers other than pip.
let dependencies_layer_env = match package_manager {
match package_manager {
PackageManager::Pip => {
log_header("Installing dependencies using Pip");
let pip_cache_layer = context.handle_layer(
Expand All @@ -106,20 +100,8 @@ impl Buildpack for PythonBuildpack {
pip_layer.env
}
};
command_env = dependencies_layer_env.apply(Scope::Build, &command_env);

if is_function {
log_header("Validating Salesforce Function");
salesforce_functions::check_function(&command_env)
.map_err(BuildpackError::CheckSalesforceFunction)?;
log_info("Function passed validation.");

BuildResultBuilder::new()
.launch(salesforce_functions::launch_config())
.build()
} else {
BuildResultBuilder::new().build()
}
BuildResultBuilder::new().build()
}

fn on_error(&self, error: libcnb::Error<Self::Error>) {
Expand All @@ -129,16 +111,12 @@ impl Buildpack for PythonBuildpack {

#[derive(Debug)]
pub(crate) enum BuildpackError {
/// Errors running the `sf-functions-python check` command.
CheckSalesforceFunction(CheckSalesforceFunctionError),
/// IO errors when performing buildpack detection.
DetectIo(io::Error),
/// Errors determining which Python package manager to use for a project.
DeterminePackageManager(DeterminePackageManagerError),
/// Errors installing the project's dependencies into a layer using Pip.
PipDependenciesLayer(PipDependenciesLayerError),
/// Errors reading and parsing a `project.toml` file.
ProjectDescriptor(ProjectDescriptorError),
/// Errors installing Python and required packaging tools into a layer.
PythonLayer(PythonLayerError),
/// Errors determining which Python version to use for a project.
Expand Down
Loading