Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Merge branch 'cloudflare' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
caass committed Oct 1, 2020
2 parents 9da3a2e + d6068cc commit 409063e
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 51 deletions.
87 changes: 79 additions & 8 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ flate2 = "1.0.17"
fs2 = "0.4.3"
futures-util = "0.3"
http = "0.2.1"
hyper = "0.13.7"
hyper = "0.13.8"
hyper-rustls = "0.21.0"
ignore = "0.4.16"
indicatif = "0.15.0"
Expand All @@ -47,7 +47,7 @@ rand = "0.7.3"
regex = "1"
reqwest = { version = "0.10.8", features = ["blocking", "json"] }
rustls = "0.18.1"
semver = "0.10.0"
semver = "0.11.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.57"
serde_with = "1.4.0"
Expand Down
4 changes: 2 additions & 2 deletions src/build/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::settings::toml::{Target, TargetType};
use crate::terminal::message::{Message, StdOut};
use crate::terminal::message::{Message, StdErr};
use crate::terminal::styles;
use crate::wranglerjs;
use crate::{commands, install};
Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn build_target(target: &Target) -> Result<String, failure::Error> {
}

pub fn command(args: &[&str], binary_path: &PathBuf) -> Command {
StdOut::working("Compiling your project to WebAssembly...");
StdErr::working("Compiling your project to WebAssembly...");

let mut c = if cfg!(target_os = "windows") {
let mut c = Command::new("cmd");
Expand Down
6 changes: 3 additions & 3 deletions src/commands/kv/bulk/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::kv::bulk::put;
use crate::kv::bulk::BATCH_KEY_MAX;
use crate::settings::global_user::GlobalUser;
use crate::settings::toml::Target;
use crate::terminal::message::{Message, StdOut};
use crate::terminal::message::{Message, StdErr};
pub fn run(
target: &Target,
user: &GlobalUser,
Expand All @@ -40,7 +40,7 @@ pub fn run(

let len = pairs.len();

StdOut::working(&format!("uploading {} key value pairs", len));
StdErr::working(&format!("uploading {} key value pairs", len));
let progress_bar = if len > BATCH_KEY_MAX {
let pb = ProgressBar::new(len as u64);
pb.set_style(ProgressStyle::default_bar().template("{wide_bar} {pos}/{len}\n{msg}"));
Expand All @@ -55,6 +55,6 @@ pub fn run(
pb.finish_with_message(&format!("uploaded {} key value pairs", len));
}

StdOut::success("Success");
StdErr::success("Success");
Ok(())
}
70 changes: 61 additions & 9 deletions src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::env;
use std::path::{Path, PathBuf};

use indicatif::{ProgressBar, ProgressStyle};
use serde::{Deserialize, Serialize};

use crate::build::build_target;
use crate::deploy;
Expand All @@ -11,19 +12,33 @@ use crate::settings::global_user::GlobalUser;
use crate::settings::toml::{DeployConfig, Target};
use crate::sites;
use crate::terminal::emoji;
use crate::terminal::message::{Message, StdOut};
use crate::terminal::message::{Message, Output, StdErr, StdOut};
use crate::upload;

#[derive(Serialize, Deserialize, Default)]
pub struct PublishOutput {
pub success: bool,
pub name: String,
pub urls: Vec<String>,
}

pub fn publish(
user: &GlobalUser,
target: &mut Target,
deploy_config: DeployConfig,
out: Output,
) -> Result<(), failure::Error> {
validate_target_required_fields_present(target)?;

// Build the script before uploading.
build_target(&target)?;

// Build the script before uploading and log build result
let build_result = build_target(&target);
match build_result {
Ok(msg) => {
StdErr::success(&msg);
Ok(())
}
Err(e) => Err(e),
}?;
if let Some(site_config) = &target.site {
let path = &site_config.bucket.clone();
validate_bucket_location(path)?;
Expand All @@ -35,7 +50,7 @@ pub fn publish(
sites::sync(target, user, &site_namespace.id, &path)?;

// First, upload all existing files in bucket directory
StdOut::working("Uploading site files");
StdErr::working("Uploading site files");
let upload_progress_bar = if to_upload.len() > bulk::BATCH_KEY_MAX {
let upload_progress_bar = ProgressBar::new(to_upload.len() as u64);
upload_progress_bar
Expand All @@ -62,11 +77,30 @@ pub fn publish(
// Next, upload and deploy the worker with the updated asset_manifest
upload::script(&upload_client, &target, Some(asset_manifest))?;

deploy::worker(&user, &deploy_config)?;
match deploy::worker(&user, &deploy_config) {
Ok(urls) => {
let result_msg = format!("Successfully published your script to {}", urls[0]);
match out {
Output::Json => {
let mut jsonout = PublishOutput::default();
jsonout.success = true;
jsonout.name = target.name.clone();
jsonout.urls = urls;
StdErr::success(&result_msg);
StdOut::as_json(&jsonout);
}
Output::PlainText => {
StdOut::success(&result_msg);
}
}
Ok(())
}
Err(e) => Err(e),
}?;

// Finally, remove any stale files
if !to_delete.is_empty() {
StdOut::info("Deleting stale files...");
StdErr::info("Deleting stale files...");

let delete_progress_bar = if to_delete.len() > bulk::BATCH_KEY_MAX {
let delete_progress_bar = ProgressBar::new(to_delete.len() as u64);
Expand Down Expand Up @@ -94,8 +128,26 @@ pub fn publish(
let upload_client = http::legacy_auth_client(user);

upload::script(&upload_client, &target, None)?;

deploy::worker(&user, &deploy_config)?;
match deploy::worker(&user, &deploy_config) {
Ok(urls) => {
let result_msg = format!("Successfully published your script to {}", urls[0]);
match out {
Output::Json => {
let mut jsonout = PublishOutput::default();
jsonout.success = true;
jsonout.name = target.name.clone();
jsonout.urls = urls;
StdErr::success(&result_msg);
StdOut::as_json(&jsonout);
}
Output::PlainText => {
StdOut::success(&result_msg);
}
}
Ok(())
}
Err(e) => Err(e),
}?;
}

Ok(())
Expand Down
25 changes: 9 additions & 16 deletions src/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,29 @@ use crate::commands::subdomain::Subdomain;
use crate::http;
use crate::settings::global_user::GlobalUser;
use crate::settings::toml::{DeployConfig, Zoneless};
use crate::terminal::message::{Message, StdOut};
pub fn worker(user: &GlobalUser, deploy_config: &DeployConfig) -> Result<(), failure::Error> {

pub fn worker(
user: &GlobalUser,
deploy_config: &DeployConfig,
) -> Result<Vec<String>, failure::Error> {
match deploy_config {
DeployConfig::Zoneless(zoneless_config) => {
// this is a zoneless deploy
log::info!("publishing to workers.dev subdomain");
let deploy_address = publish_zoneless(user, zoneless_config)?;

StdOut::success(&format!(
"Successfully published your script to {}",
deploy_address
));

Ok(())
let addresses = vec![deploy_address];
Ok(addresses)
}
DeployConfig::Zoned(zoned_config) => {
// this is a zoned deploy
log::info!("publishing to zone {}", zoned_config.zone_id);

let published_routes = publish_routes(&user, zoned_config)?;

let display_results: Vec<String> =
let addresses: Vec<String> =
published_routes.iter().map(|r| format!("{}", r)).collect();

StdOut::success(&format!(
"Deployed to the following routes:\n{}",
display_results.join("\n")
));

Ok(())
Ok(addresses)
}
}
}
Expand Down
Loading

0 comments on commit 409063e

Please sign in to comment.