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

fetch publisher data from crates.io, start build artifact caching #2079

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c559add
fetch publisher data from crates.io, start build artifact caching
syphar Mar 9, 2023
fa1981f
update docker-compose config so rustwide & prefix are on the same fil…
syphar Mar 10, 2023
ef74011
always move the cache / targets, no copy needed
syphar Mar 10, 2023
3fdf1fd
also clean doc-output for proc macro crates
syphar Mar 10, 2023
a82e6dc
adapt comment
syphar Mar 10, 2023
bf8440b
add freeing disk space functionliaty
syphar Mar 11, 2023
4e67646
update log messages
syphar Mar 11, 2023
b0126a4
extend tests for crate-publisher fetching
syphar Mar 11, 2023
a15fc75
extend tests for crate-release info fetchign
syphar Mar 11, 2023
09588f1
ensure if target directory exists
syphar Jun 2, 2023
5e7d6c7
Merge branch 'master' into get-publisher
syphar Jun 2, 2023
2bc2cab
add more logging context, try cleaning up target on restore
syphar Jun 2, 2023
c48e0f4
don't try to create target directory when it already exists
syphar Jun 4, 2023
ce2bedc
purge artifact cache for tests
syphar Jun 4, 2023
3758e0d
start adding cache test
syphar Jun 18, 2023
c3f4901
add global config to enable artifact cache, debug logging for test
syphar Jun 18, 2023
231de62
try other publisher id for the test
syphar Jun 18, 2023
bb96f3b
remove debug-output from tests
syphar Jun 18, 2023
ce370b1
start adding caching tests
syphar Jun 18, 2023
a11b75b
fix cache dir cleanup for free disk space, add test
syphar Jun 18, 2023
184a00d
start freeing disk-space
syphar Jun 19, 2023
70771d5
add config var for free disk space goal
syphar Jun 19, 2023
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
24 changes: 24 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ bzip2 = "0.4.4"
serde_cbor = "0.11.1"
getrandom = "0.2.1"
itertools = { version = "0.10.5", optional = true}
sysinfo = { version = "0.28.2", default-features = false }
rusqlite = { version = "0.29.0", features = ["bundled"] }
moka = { version ="0.11.0", default-features = false, features = ["sync"]}

Expand Down
14 changes: 10 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ services:
expose: ["3000"]
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- ".rustwide-docker:/opt/docsrs/rustwide"
- "cratesio-index:/opt/docsrs/prefix/crates.io-index"
# we only need one of the two mappings here.
# this will link to your local filesystem, which makes build debugging
# easier
- "./ignored/opt-docsrs:/opt/docsrs_ext/"
# this uses a docker volume and will be faster, but you need to
# log into the container to debug its contents
# - "prefix-ext:/opt/docsrs_ext/"
environment:
DOCSRS_RUSTWIDE_WORKSPACE: /opt/docsrs/rustwide
DOCSRS_RUSTWIDE_WORKSPACE: /opt/docsrs_ext/rustwide
DOCSRS_PREFIX: /opt/docsrs_ext/prefix
DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@db
DOCSRS_STORAGE_BACKEND: s3
S3_ENDPOINT: http://s3:9000
Expand Down Expand Up @@ -93,4 +99,4 @@ services:
volumes:
postgres-data: {}
minio-data: {}
cratesio-index: {}
prefix-ext: {}
2 changes: 1 addition & 1 deletion dockerfiles/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -euv

export DOCSRS_PREFIX=/opt/docsrs/prefix
export DOCSRS_PREFIX=${DOCSRS_PREFIX:-"/opt/docsrs/prefix"}
export DOCSRS_DOCKER=true
export DOCSRS_LOG=${DOCSRS_LOG-"docs-rs,rustwide=info"}
export PATH="$PATH:/build/target/release"
Expand Down
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ pub struct Config {
/// same for the `static.docs.rs` distribution
pub cloudfront_distribution_id_static: Option<String>,

// some caches do automatic cleanup based on this free disk space goal.
// Value shoudl be between 0 and 1.
pub(crate) free_disk_space_goal: f32,

// Build params
pub(crate) build_attempts: u16,
pub(crate) use_build_artifact_cache: bool,
pub(crate) rustwide_workspace: PathBuf,
pub(crate) inside_docker: bool,
pub(crate) docker_image: Option<String>,
Expand Down Expand Up @@ -129,7 +134,10 @@ impl Config {
let prefix: PathBuf = require_env("DOCSRS_PREFIX")?;

Ok(Self {
free_disk_space_goal: env("DOCSRS_FREE_DISK_SPACE_GOAL", 0.2)?,

build_attempts: env("DOCSRS_BUILD_ATTEMPTS", 5)?,
use_build_artifact_cache: env("DOCSRS_USE_BUILD_ARTIFACT_CACHE", true)?,

crates_io_api_call_retries: env("DOCSRS_CRATESIO_API_CALL_RETRIES", 3)?,

Expand Down
21 changes: 13 additions & 8 deletions src/db/add_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
db::types::Feature,
docbuilder::{BuildResult, DocCoverage},
error::Result,
index::api::{CrateData, CrateOwner, ReleaseData},
index::api::{CrateData, GithubUser, ReleaseData},
storage::CompressionAlgorithm,
utils::MetadataPackage,
web::crate_details::CrateDetails,
Expand Down Expand Up @@ -371,7 +371,7 @@ pub fn update_crate_data_in_database(
/// Adds owners into database
fn update_owners_in_database(
conn: &mut Client,
owners: &[CrateOwner],
owners: &[GithubUser],
crate_id: i32,
) -> Result<()> {
// Update any existing owner data since it is mutable and could have changed since last
Expand Down Expand Up @@ -562,9 +562,10 @@ mod test {
},
)?;

let owner1 = CrateOwner {
let owner1 = GithubUser {
avatar: "avatar".into(),
login: "login".into(),
..Default::default()
};

update_owners_in_database(&mut conn, &[owner1.clone()], crate_id)?;
Expand Down Expand Up @@ -600,16 +601,18 @@ mod test {
// set initial owner details
update_owners_in_database(
&mut conn,
&[CrateOwner {
&[GithubUser {
login: "login".into(),
avatar: "avatar".into(),
..Default::default()
}],
crate_id,
)?;

let updated_owner = CrateOwner {
let updated_owner = GithubUser {
login: "login".into(),
avatar: "avatar2".into(),
..Default::default()
};
update_owners_in_database(&mut conn, &[updated_owner.clone()], crate_id)?;

Expand Down Expand Up @@ -645,17 +648,19 @@ mod test {
// set initial owner details
update_owners_in_database(
&mut conn,
&[CrateOwner {
&[GithubUser {
login: "login".into(),
avatar: "avatar".into(),
..Default::default()
}],
crate_id,
)?;

let new_owners: Vec<CrateOwner> = (1..5)
.map(|i| CrateOwner {
let new_owners: Vec<GithubUser> = (1..5)
.map(|i| GithubUser {
login: format!("login{i}"),
avatar: format!("avatar{i}"),
..Default::default()
})
.collect();

Expand Down
8 changes: 5 additions & 3 deletions src/db/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn delete_crate_from_database(conn: &mut Client, name: &str, crate_id: i32) -> R
#[cfg(test)]
mod tests {
use super::*;
use crate::index::api::CrateOwner;
use crate::index::api::GithubUser;
use crate::test::{assert_success, wrapper};
use postgres::Client;
use test_case::test_case;
Expand Down Expand Up @@ -313,9 +313,10 @@ mod tests {
.name("a")
.version("1.0.0")
.archive_storage(archive_storage)
.add_owner(CrateOwner {
.add_owner(GithubUser {
login: "malicious actor".into(),
avatar: "https://example.org/malicious".into(),
..Default::default()
})
.create()?;
assert!(release_exists(&mut db.conn(), v1)?);
Expand All @@ -342,9 +343,10 @@ mod tests {
.name("a")
.version("2.0.0")
.archive_storage(archive_storage)
.add_owner(CrateOwner {
.add_owner(GithubUser {
login: "Peter Rabbit".into(),
avatar: "https://example.org/peter".into(),
..Default::default()
})
.create()?;
assert!(release_exists(&mut db.conn(), v2)?);
Expand Down
Loading