Skip to content

Commit

Permalink
deployer(MockedBuilder): push to container registry (#904)
Browse files Browse the repository at this point in the history
* wip

* deployer(oci): added support to push OCI tar images to a CR

* deployer: Mocked builder pushes tar images to CR

* deployer(builder): add support for pushing image against...

...a local container registry.

* deployer(oci): simplified the annotations module

* deployer(oci): update the docs

* deployer(oci): added unit tests and simplified module structure

* deployer: fix clippy

* deployer: fix clippy

* deployer: addressed P review

* deployer: address O feedback

* deployer: addressed P second review
  • Loading branch information
iulianbarbu authored May 21, 2023
1 parent aaeba25 commit 73f0a9f
Show file tree
Hide file tree
Showing 22 changed files with 1,320 additions and 46 deletions.
153 changes: 145 additions & 8 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 @@ -98,6 +98,7 @@ tracing-subscriber = { version = "0.3.16", default-features = false, features =
"std",
] }
ttl_cache = "0.5.1"
url = "2.3.1"
utoipa = { version = "3.2.1", features = [ "uuid", "chrono" ] }
utoipa-swagger-ui = { version = "3.1.3", features = ["axum"] }
ulid = "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion cargo-shuttle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tracing-subscriber = { workspace = true, features = [
"env-filter",
"fmt",
] }
url = "2.3.1"
url = { workspace = true }
uuid = { workspace = true, features = ["v4"] }
webbrowser = "0.8.2"
semver = "1.0.17"
Expand Down
12 changes: 12 additions & 0 deletions deployer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,32 @@ description = "Service to execute the deployment of projects on shuttle"

[dependencies]
anyhow = { workspace = true }
async-recursion = "1.0.4"
axum = { workspace = true, features = ["headers", "json", "query", "ws"] }
base16ct = { version = "0.1.1", features = ["alloc"] }
bytes = { workspace = true }
clap = { workspace = true }
dirs = { workspace = true }
flate2 = { workspace = true }
futures = { workspace = true }
http = { workspace = true }
hyper = { workspace = true, features = ["client", "http1", "http2", "tcp"] }
hyper-reverse-proxy = { git = "https://github.com/chesedo/hyper-reverse-proxy", branch = "master" }
oci-spec = "0.5.7"
once_cell = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sha2 = "0.10.2"
regex = "1.5.6"
reqwest = { workspace = true , features = ["json"]}
tokio-stream = "0.1.14"
tokio-tar = "0.3.0"
thiserror = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "fs"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
ureq = { version = "2.5.0", features = ["json"] }
url = { workspace = true }
utoipa = { workspace = true }
uuid = { workspace = true, features = ["v4"] }

Expand Down
4 changes: 2 additions & 2 deletions deployer/README
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ docker compose -f docker-compose.rendered.yml up auth

In another terminal create an admin user with the API key set to `test-key`:
```bash
AUTH_CONTAINER_ID=$(docker ps -aqf "name=shuttle-auth") \
AUTH_CONTAINER_ID=$(docker ps -aqf "name=shuttle-dev-auth"); \
docker exec $AUTH_CONTAINER_ID ./usr/local/bin/service \
--state=/var/lib/shuttle-auth \
init --name admin --key test-key
```

Start the deployer prepared for a local run:
```bash
RUST_LOG=DEBUG cargo run --manifest-path deployer/Cargo.toml --bin shuttle-deployer -- --api-address 0.0.0.0:8001 --local
RUST_LOG=DEBUG cargo run --manifest-path deployer/Cargo.toml --bin shuttle-deployer -- --api-address 0.0.0.0:8001 --local --image-archive-path shuttle-service.tar
```

In another terminal go to a shuttle project from the examples directory and run:
Expand Down
12 changes: 6 additions & 6 deletions deployer/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use shuttle_common::claims::Claim;
use std::collections::HashMap;
use tracing::{debug, error, instrument};
use utoipa::OpenApi;
use uuid::Uuid;

use crate::{builder::MockedBuilder, handlers::error::Result};

Expand Down Expand Up @@ -45,11 +46,10 @@ pub async fn deploy_project(
debug!("Received a total of {} bytes", data.len());

debug!("Sending project source code to the builder.");
let image_archive = mocked_builder.get_default_image_archive(&data).await;
debug!(
"Received an image archive of length: {}. I will deploy it next, but hang in a bit...",
image_archive.len()
);
let _build_id = mocked_builder.build_and_push_image(&data).await?;

Ok(Json(format!("Received a total of {} bytes", data.len())))
// TODO: fetch image from the container registry and deploy it on k8s.
// The deployment must be async and we should return a `deployment_id`,
// which can be used by `cargo-shuttle` to connect to the a ws logs endpoint.
Ok(Json(Uuid::new_v4().to_string()))
}
3 changes: 1 addition & 2 deletions deployer/src/builder/Containerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
FROM alpine:latest

COPY shuttle-service /usr/bin/
RUN chmod +x /usr/bin/shuttle-service
RUN apk update
Loading

0 comments on commit 73f0a9f

Please sign in to comment.