Skip to content

Commit

Permalink
Support environment variables (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
namse authored Jan 18, 2024
1 parent 2bd26d3 commit e5013bb
Show file tree
Hide file tree
Showing 13 changed files with 640 additions and 3,656 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/oioi-agent-image-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,16 @@ jobs:
echo response = $response
if [ $response -eq 200 ]; then
echo "HTTP Endpoint check successful."
SUCCESS=true
break
text=$(curl -s http://$DNS_NAME)
expected="Hello, oioi!"
if [ "$text" = "$expected" ]; then
echo "HTTP Endpoint check successful."
SUCCESS=true
break
else
echo "Expected $expected, but got $text. Check environment variables."
exit 1
fi
else
echo "Retrying in $RETRY_INTERVAL seconds..."
sleep $RETRY_INTERVAL
Expand Down
59 changes: 57 additions & 2 deletions oioi/agent/Cargo.lock

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

2 changes: 1 addition & 1 deletion oioi/agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ futures-util = "0.3.29"
lazy_static = "1.4.0"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
tokio = { version = "1.34.0", features = ["rt", "macros"] }
tokio = { version = "1.35.1", features = ["full"] }
2 changes: 2 additions & 0 deletions oioi/agent/src/container_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub(crate) struct ContainerConfig {
pub docker_login_script: String,
#[serde(rename = "updatedAt")]
pub updated_at: DateTime<chrono::offset::Utc>,
#[serde(rename = "env")]
pub env: std::collections::HashMap<String, String>,
}

#[derive(Debug, serde::Deserialize, PartialEq)]
Expand Down
3 changes: 3 additions & 0 deletions oioi/agent/src/docker_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl DockerEngine {
OioiContainer {
image_uri,
port_mappings,
env,
}: OioiContainer,
) -> Result<()> {
// pull image to get most recent remote image digest
Expand Down Expand Up @@ -154,6 +155,7 @@ impl DockerEngine {
)),
..Default::default()
}),
env: Some(env.into_iter().map(|(k, v)| format!("{k}={v}")).collect()),
..Default::default()
},
)
Expand Down Expand Up @@ -195,6 +197,7 @@ impl DockerEngine {
pub(crate) struct OioiContainer {
pub(crate) image_uri: String,
pub(crate) port_mappings: Vec<PortMapping>,
pub(crate) env: std::collections::HashMap<String, String>,
}

#[derive(Debug, PartialEq)]
Expand Down
2 changes: 2 additions & 0 deletions oioi/agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async fn real_main() -> Result<()> {
port_mappings,
docker_login_script,
updated_at,
env,
}) = container_config::get_container_config().await?
else {
println!("No container config found for group {}.", *GROUP_NAME);
Expand All @@ -49,6 +50,7 @@ async fn real_main() -> Result<()> {
.update_container(OioiContainer {
image_uri,
port_mappings,
env,
})
.await?;

Expand Down
8 changes: 6 additions & 2 deletions oioi/cdk/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface OioiProps {
* @default cdk.aws_logs.RetentionDays.ONE_WEEK
* */
logRetention?: cdk.aws_logs.RetentionDays;
env?: Record<string, string>;
}

export class Oioi extends Construct {
Expand Down Expand Up @@ -47,8 +48,10 @@ export class Oioi extends Construct {
},
);

const logRemovalPolicy = props.logRemovalPolicy ?? cdk.RemovalPolicy.DESTROY;
const logRetention = props.logRetention ?? cdk.aws_logs.RetentionDays.ONE_WEEK;
const logRemovalPolicy =
props.logRemovalPolicy ?? cdk.RemovalPolicy.DESTROY;
const logRetention =
props.logRetention ?? cdk.aws_logs.RetentionDays.ONE_WEEK;

const systemMessagesLogGroup = new cdk.aws_logs.LogGroup(
this,
Expand Down Expand Up @@ -97,6 +100,7 @@ export class Oioi extends Construct {
portMappings: props.portMappings,
dockerLoginScript,
updatedAt: new Date().toISOString(),
env: props.env,
}),
},
);
Expand Down
Loading

0 comments on commit e5013bb

Please sign in to comment.