Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #53 from rivet-gg/nathan/specify-image-directly
Browse files Browse the repository at this point in the history
Allow specifying prebuilt Docker image
  • Loading branch information
NathanFlurry authored Mar 8, 2023
2 parents 9df7eea + 14a8a13 commit af74e33
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 31 deletions.
3 changes: 2 additions & 1 deletion cli/src/commands/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rand::{thread_rng, Rng};
use serde::Serialize;
use std::sync::Arc;
use tokio::fs;
use uuid::Uuid;

use crate::util::{cmd, struct_fmt, term, upload};

Expand Down Expand Up @@ -42,7 +43,7 @@ impl SubCommand {

#[derive(Serialize)]
pub struct PushOutput {
pub image_id: String,
pub image_id: Uuid,
}

pub async fn push(ctx: &cli_core::Ctx, push_opts: &ImagePushOpts) -> Result<PushOutput> {
Expand Down
7 changes: 3 additions & 4 deletions cli/src/commands/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
Arc,
},
};
use uuid::Uuid;

use crate::util::{struct_fmt, term, upload};

Expand Down Expand Up @@ -46,7 +47,7 @@ impl SubCommand {

#[derive(Serialize)]
pub struct PushOutput {
pub site_id: String,
pub site_id: Uuid,
}

pub async fn push(ctx: &cli_core::Ctx, push_opts: &SitePushOpts) -> Result<PushOutput> {
Expand Down Expand Up @@ -163,7 +164,5 @@ pub async fn push(ctx: &cli_core::Ctx, push_opts: &SitePushOpts) -> Result<PushO
complete_res.context("cloud_uploads_complete_upload")?;
term::status::success("Site Upload Complete", "");

Ok(PushOutput {
site_id: site_id.to_string(),
})
Ok(PushOutput { site_id })
}
30 changes: 21 additions & 9 deletions cli/src/commands/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,21 @@ pub async fn read_config(
pub fn build_mock_config_dependencies(version: &mut models::CloudVersionConfig) -> Result<()> {
if let Some(matchmaker) = version.matchmaker.as_mut() {
if let Some(docker) = matchmaker.docker.as_mut() {
docker.image = Some(Uuid::nil());
docker.image_id = Some(Uuid::nil());
}

if let Some(game_modes) = matchmaker.game_modes.as_mut() {
for (_, game_mode) in game_modes.iter_mut() {
if let Some(docker) = game_mode.docker.as_mut() {
docker.image = Some(Uuid::nil());
docker.image_id = Some(Uuid::nil());
}
}
}
}

// Build CDN
if let Some(cdn) = version.cdn.as_mut() {
cdn.site = Some(Uuid::nil());
cdn.site_id = Some(Uuid::nil());
}

Ok(())
Expand Down Expand Up @@ -387,7 +387,7 @@ pub async fn build_image(
docker: &mut Box<models::CloudVersionMatchmakerGameModeRuntimeDocker>,
format: Option<&struct_fmt::Format>,
) -> Result<()> {
if docker.image.is_none() {
if docker.image_id.is_none() {
if let Some(dockerfile) = docker.dockerfile.as_ref() {
// Build image
eprintln!();
Expand All @@ -413,7 +413,19 @@ pub async fn build_image(
},
)
.await?;
docker.image = Some(Uuid::parse_str(&push_output.image_id)?);
docker.image_id = Some(push_output.image_id);
} else if let Some(docker_image) = docker.image.as_ref() {
// Upload build
let push_output = image::push(
ctx,
&image::ImagePushOpts {
tag: docker_image.clone(),
name: Some(gen::display_name_from_date()),
format: format.cloned(),
},
)
.await?;
docker.image_id = Some(push_output.image_id);
}
}

Expand All @@ -425,7 +437,7 @@ pub async fn build_site(
cdn: &mut Box<models::CloudVersionCdnConfig>,
format: Option<&struct_fmt::Format>,
) -> Result<()> {
if cdn.site.is_none() {
if cdn.site_id.is_none() {
if let Some(build_output) = cdn.build_output.as_ref() {
if let Some(build_command) = cdn.build_command.as_ref() {
eprintln!();
Expand Down Expand Up @@ -456,7 +468,7 @@ pub async fn build_site(
},
)
.await?;
cdn.site = Some(Uuid::parse_str(&push_output.site_id)?);
cdn.site_id = Some(push_output.site_id);
}
}

Expand Down Expand Up @@ -623,11 +635,11 @@ pub async fn build_and_push_compat(
};

if let Some(site_output) = site_output {
overrides.push(("cdn.site".into(), json!(site_output.site_id)));
overrides.push(("cdn.site_id".into(), json!(site_output.site_id)));
}
if let Some(build_output) = build_output {
overrides.push((
"matchmaker.docker.image".into(),
"matchmaker.docker.image_id".into(),
json!(build_output.image_id),
));
}
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ async fn basic() {
.unwrap();
let _user_config = rivet::commands::version::read_user_config(
vec![
("cdn.site".into(), json!("xxxx")),
("matchmaker.docker.image".into(), json!("xxxx")),
("cdn.site_id".into(), json!("xxxx")),
("matchmaker.docker.image_id".into(), json!("xxxx")),
],
Some("my-ns"),
)
Expand Down
2 changes: 1 addition & 1 deletion lib/rivet-api/docs/CloudGamesCreateGameBuildOutput.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**build_id** | **String** | A universally unique identifier. |
**build_id** | [**uuid::Uuid**](uuid::Uuid.md) | A universally unique identifier. |
**image_presigned_request** | [**crate::models::UploadPresignedRequest**](UploadPresignedRequest.md) | |
**upload_id** | **String** | A universally unique identifier. |

Expand Down
2 changes: 1 addition & 1 deletion lib/rivet-api/docs/CloudGamesCreateGameCdnSiteOutput.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**presigned_requests** | [**Vec<crate::models::UploadPresignedRequest>**](UploadPresignedRequest.md) | |
**site_id** | **String** | A universally unique identifier. |
**site_id** | [**uuid::Uuid**](uuid::Uuid.md) | A universally unique identifier. |
**upload_id** | **String** | A universally unique identifier. |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
3 changes: 1 addition & 2 deletions lib/rivet-api/docs/CloudVersionCdnConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ Name | Type | Description | Notes
**build_command** | Option<**String**> | Client-side configuration | [optional]
**build_output** | Option<**String**> | Client-side configuration | [optional]
**routes** | Option<[**Vec<crate::models::CloudVersionCdnRoute>**](CloudVersionCdnRoute.md)> | Multiple CDN version routes. | [optional]
**site** | Option<[**uuid::Uuid**](uuid::Uuid.md)> | A universally unique identifier. | [optional]
**site_id** | Option<**String**> | **Deprecated** | [optional]
**site_id** | Option<[**uuid::Uuid**](uuid::Uuid.md)> | A universally unique identifier. | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Name | Type | Description | Notes
**args** | Option<**Vec<String>**> | | [optional]
**dockerfile** | Option<**String**> | Client-side configuration | [optional]
**env** | Option<**::std::collections::HashMap<String, String>**> | | [optional]
**image** | Option<[**uuid::Uuid**](uuid::Uuid.md)> | | [optional]
**image** | Option<**String**> | Client-side configuration | [optional]
**image_id** | Option<[**uuid::Uuid**](uuid::Uuid.md)> | | [optional]
**network_mode** | Option<[**crate::models::CloudVersionMatchmakerNetworkMode**](CloudVersionMatchmakerNetworkMode.md)> | | [optional]
**ports** | Option<[**::std::collections::HashMap<String, crate::models::CloudVersionMatchmakerGameModeRuntimeDockerPort>**](CloudVersionMatchmakerGameModeRuntimeDockerPort.md)> | | [optional]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
pub struct CloudGamesCreateGameBuildOutput {
/// A universally unique identifier.
#[serde(rename = "build_id")]
pub build_id: String,
pub build_id: uuid::Uuid,
#[serde(rename = "image_presigned_request")]
pub image_presigned_request: Box<crate::models::UploadPresignedRequest>,
/// A universally unique identifier.
Expand All @@ -24,7 +24,7 @@ pub struct CloudGamesCreateGameBuildOutput {
}

impl CloudGamesCreateGameBuildOutput {
pub fn new(build_id: String, image_presigned_request: crate::models::UploadPresignedRequest, upload_id: String) -> CloudGamesCreateGameBuildOutput {
pub fn new(build_id: uuid::Uuid, image_presigned_request: crate::models::UploadPresignedRequest, upload_id: String) -> CloudGamesCreateGameBuildOutput {
CloudGamesCreateGameBuildOutput {
build_id,
image_presigned_request: Box::new(image_presigned_request),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ pub struct CloudGamesCreateGameCdnSiteOutput {
pub presigned_requests: Vec<crate::models::UploadPresignedRequest>,
/// A universally unique identifier.
#[serde(rename = "site_id")]
pub site_id: String,
pub site_id: uuid::Uuid,
/// A universally unique identifier.
#[serde(rename = "upload_id")]
pub upload_id: String,
}

impl CloudGamesCreateGameCdnSiteOutput {
pub fn new(presigned_requests: Vec<crate::models::UploadPresignedRequest>, site_id: String, upload_id: String) -> CloudGamesCreateGameCdnSiteOutput {
pub fn new(presigned_requests: Vec<crate::models::UploadPresignedRequest>, site_id: uuid::Uuid, upload_id: String) -> CloudGamesCreateGameCdnSiteOutput {
CloudGamesCreateGameCdnSiteOutput {
presigned_requests,
site_id,
Expand Down
6 changes: 1 addition & 5 deletions lib/rivet-api/src/models/cloud_version_cdn_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ pub struct CloudVersionCdnConfig {
#[serde(rename = "routes", skip_serializing_if = "Option::is_none")]
pub routes: Option<Vec<crate::models::CloudVersionCdnRoute>>,
/// A universally unique identifier.
#[serde(rename = "site", skip_serializing_if = "Option::is_none")]
pub site: Option<uuid::Uuid>,
/// **Deprecated**
#[serde(rename = "site_id", skip_serializing_if = "Option::is_none")]
pub site_id: Option<String>,
pub site_id: Option<uuid::Uuid>,
}

impl CloudVersionCdnConfig {
Expand All @@ -38,7 +35,6 @@ impl CloudVersionCdnConfig {
build_command: None,
build_output: None,
routes: None,
site: None,
site_id: None,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ pub struct CloudVersionMatchmakerGameModeRuntimeDocker {
pub dockerfile: Option<String>,
#[serde(rename = "env", skip_serializing_if = "Option::is_none")]
pub env: Option<::std::collections::HashMap<String, String>>,
/// Client-side configuration
#[serde(rename = "image", skip_serializing_if = "Option::is_none")]
pub image: Option<uuid::Uuid>,
pub image: Option<String>,
#[serde(rename = "image_id", skip_serializing_if = "Option::is_none")]
pub image_id: Option<uuid::Uuid>,
#[serde(rename = "network_mode", skip_serializing_if = "Option::is_none")]
pub network_mode: Option<crate::models::CloudVersionMatchmakerNetworkMode>,
#[serde(rename = "ports", skip_serializing_if = "Option::is_none")]
Expand All @@ -37,6 +40,7 @@ impl CloudVersionMatchmakerGameModeRuntimeDocker {
dockerfile: None,
env: None,
image: None,
image_id: None,
network_mode: None,
ports: None,
}
Expand Down

0 comments on commit af74e33

Please sign in to comment.