Skip to content

Commit

Permalink
feat: Init from snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezzfelipe committed Nov 7, 2024
1 parent a01a05f commit b7b4fc4
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 58 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Docker
on:
workflow_dispatch: {}
push:
branches:
- "main"
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/hydra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ on:
paths:
- ".github/workflows/hydra.yml"
- "docker/dockerfile.hydra"
workflow_dispatch:
inputs:
mumak_version:
required: false
workflow_dispatch: {}

jobs:
build-images:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ on:
paths:
- ".github/workflows/init.yml"
- "docker/dockerfile.init"
workflow_dispatch:
inputs:
mumak_version:
required: false
workflow_dispatch: {}

jobs:
build-images:
Expand Down
36 changes: 0 additions & 36 deletions bootstrap/stage1/efs.tf

This file was deleted.

4 changes: 0 additions & 4 deletions bootstrap/stage1/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
variable "efs_fs_id" {
type = string
description = "ID of EFS resource to use as persistance."
}
20 changes: 20 additions & 0 deletions bootstrap/stage2/deployment.tf
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ resource "kubernetes_deployment_v1" "operator" {
value = var.dmtr_port_name
}

env {
name = "INIT_IMAGE"
value = var.init_image
}

env {
name = "BUCKET"
value = var.bucket
}

env {
name = "INIT_AWS_ACCESS_KEY_ID"
value = var.init_aws_access_key_id
}

env {
name = "INIT_AWS_SECRET_ACCESS_KEY"
value = var.init_aws_secret_access_key
}

resources {
limits = {
cpu = var.resources.limits.cpu
Expand Down
17 changes: 17 additions & 0 deletions bootstrap/stage2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ variable "dmtr_port_name" {
type = string
}

variable "init_image" {
type = string
}

variable "bucket" {
type = string
default = "hydradoomsnapshots"
}

variable "init_aws_access_key_id" {
type = string
}

variable "init_aws_secret_access_key" {
type = string
}

variable "tolerations" {
type = list(object({
effect = string
Expand Down
9 changes: 8 additions & 1 deletion docker/dockerfile.init
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
FROM amazon/aws-cli
RUN yum update -y && yum install -y tar gzip
RUN yum update -y && yum install -y tar gzip unzip curl

WORKDIR /var/hydra-node
RUN curl -L -O https://github.com/cardano-scaling/hydra/releases/download/0.19.0/hydra-x86_64-linux-0.19.0.zip
RUN unzip -d bin hydra-x86_64-linux-0.19.0.zip
RUN cp /var/hydra-node/bin/hydra-node /hydra-node
RUN chmod +x /hydra-node

COPY docker/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["sh", "/entrypoint.sh"]
12 changes: 10 additions & 2 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
aws s3 cp "s3://$BUCKET/$KEY" "$DATA_DIR"
tar -xzvf "$DATA_DIR/$KEY" -C "$DATA_DIR"
#!/bin/sh
if aws s3 ls "s3://$BUCKET/$KEY" > /dev/null 2>&1; then
echo "Snapshot exists, downloading..."
aws s3 cp "s3://$BUCKET/$KEY" "$DATA_DIR"
tar -xzvf "$DATA_DIR/$KEY" -C "$DATA_DIR"
else
echo "Snapshot does not exist, generating keys..."
mkdir "$DATA_DIR/keys"
/hydra-node gen-hydra-key --output-file "$DATA_DIR/keys/hydra"
fi
10 changes: 10 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn get_config() -> &'static Config {
#[derive(Debug, Clone)]
pub struct Config {
pub image: String,
pub init_image: String,
pub open_head_image: String,
pub sidecar_image: String,
pub configmap: String,
Expand All @@ -24,6 +25,9 @@ pub struct Config {
pub dmtr_project_id: String,
pub dmtr_api_key: String,
pub dmtr_port_name: String,
pub bucket: String,
pub init_aws_access_key_id: String,
pub init_aws_secret_access_key: String,
}

impl Config {
Expand All @@ -43,6 +47,12 @@ impl Config {
dmtr_project_id: env::var("DMTR_PROJECT_ID").expect("Missing DMTR_PROJECT_ID env var."),
dmtr_api_key: env::var("DMTR_API_KEY").expect("Missing DMTR_API_KEY env var."),
dmtr_port_name: env::var("DMTR_PORT_NAME").expect("Missing DMTR_PORT_NAME env var."),
init_image: env::var("INIT_IMAGE").expect("Missing INIT_IMAGE env var."),
bucket: env::var("BUCKET").expect("Missing BUCKET env var."),
init_aws_access_key_id: env::var("INIT_AWS_ACCESS_KEY_ID")
.expect("Missing INIT_AWS_ACCESS_KEY_ID env var."),
init_aws_secret_access_key: env::var("INIT_AWS_SECRET_ACCESS_KEY")
.expect("Missing INIT_AWS_SECRET_ACCESS_KEY env var."),
}
}
}
36 changes: 29 additions & 7 deletions src/custom_resource.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use k8s_openapi::api::{
apps::v1::{Deployment, DeploymentSpec},
core::v1::{
ConfigMap, ConfigMapVolumeSource, Container, ContainerPort, EmptyDirVolumeSource, PodSpec,
PodTemplateSpec, SecretVolumeSource, Service, ServicePort, ServiceSpec, Volume,
ConfigMap, ConfigMapVolumeSource, Container, ContainerPort, EmptyDirVolumeSource, EnvVar,
PodSpec, PodTemplateSpec, SecretVolumeSource, Service, ServicePort, ServiceSpec, Volume,
VolumeMount,
},
networking::v1::{
Expand Down Expand Up @@ -327,11 +327,33 @@ impl HydraDoomNode {
spec: Some(PodSpec {
init_containers: Some(vec![Container {
name: "init".to_string(),
image: Some(config.image.clone()),
args: Some(vec![
"gen-hydra-key".to_string(),
"--output-file".to_string(),
format!("{}/hydra", constants.data_dir),
image: Some(config.init_image.clone()),
env: Some(vec![
EnvVar {
name: "BUCKET".to_string(),
value: Some(config.bucket.clone()),
..Default::default()
},
EnvVar {
name: "KEY".to_string(),
value: Some(format!("{}.tar.gz", self.name_any())),
..Default::default()
},
EnvVar {
name: "DATA_DIR".to_string(),
value: Some(constants.data_dir.clone()),
..Default::default()
},
EnvVar {
name: "AWS_ACCESS_KEY_ID".to_string(),
value: Some(config.init_aws_access_key_id.clone()),
..Default::default()
},
EnvVar {
name: "AWS_SECRET_ACCESS_KEY".to_string(),
value: Some(config.init_aws_secret_access_key.clone()),
..Default::default()
},
]),
volume_mounts: Some(vec![VolumeMount {
name: "data".to_string(),
Expand Down

0 comments on commit b7b4fc4

Please sign in to comment.