Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/stakwork/sphinx-swarm
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Oct 23, 2024
2 parents 405f9a4 + 3b721e3 commit 629e6bf
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 19 deletions.
4 changes: 2 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
reverse-proxy:
image: traefik:v2.2.1
container_name: traefik.sphinx
restart: on-failure
restart: unless-stopped
networks:
- sphinx-swarm
command:
Expand Down Expand Up @@ -61,7 +61,7 @@ services:
- "traefik.http.routers.elements.tls=true"
- "traefik.http.routers.elements.tls.certresolver=myresolver"
- "traefik.http.routers.elements.entrypoints=websecure"
restart: on-failure
restart: unless-stopped
environment:
- HOST=$HOST # subdomain e.g. swarmx.sphinx.chat
- DOCKER_RUN=true # client use sphinx-swarm network
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
load_balancer:
image: traefik:v2.2.1
container_name: load_balancer
restart: on-failure
restart: unless-stopped
networks:
- sphinx-swarm
command:
Expand Down Expand Up @@ -59,7 +59,7 @@ services:
- "traefik.http.routers.elements.tls=true"
- "traefik.http.routers.elements.tls.certresolver=myresolver"
- "traefik.http.routers.elements.entrypoints=websecure"
restart: on-failure
restart: unless-stopped
deploy:
resources:
limits:
Expand Down
4 changes: 2 additions & 2 deletions second-brain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
load_balancer:
image: traefik:v2.2.1
container_name: load_balancer
restart: on-failure
restart: unless-stopped
networks:
- sphinx-swarm
command:
Expand Down Expand Up @@ -63,7 +63,7 @@ services:
- "traefik.http.routers.elements.tls=true"
- "traefik.http.routers.elements.tls.certresolver=myresolver"
- "traefik.http.routers.elements.entrypoints=websecure"
restart: on-failure
restart: unless-stopped
environment:
- HOST=$HOST # subdomain e.g. swarmx.sphinx.chat
- DOCKER_RUN=true # client use sphinx-swarm network
Expand Down
4 changes: 2 additions & 2 deletions sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
reverse-proxy:
image: traefik:v2.2.1
container_name: traefik.sphinx
restart: on-failure
restart: unless-stopped
networks:
- sphinx-swarm
command:
Expand Down Expand Up @@ -63,7 +63,7 @@ services:
- "traefik.http.routers.elements.tls=true"
- "traefik.http.routers.elements.tls.certresolver=myresolver"
- "traefik.http.routers.elements.entrypoints=websecure"
restart: on-failure
restart: unless-stopped
environment:
- HOST=$HOST # subdomain e.g. swarmx.sphinx.chat
- DOCKER_RUN=true # client use sphinx-swarm network
Expand Down
4 changes: 2 additions & 2 deletions sphinxv2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
reverse-proxy:
image: traefik:v2.2.1
container_name: traefik.sphinx
restart: on-failure
restart: unless-stopped
networks:
- sphinx-swarm
command:
Expand Down Expand Up @@ -63,7 +63,7 @@ services:
- "traefik.http.routers.elements.tls=true"
- "traefik.http.routers.elements.tls.certresolver=myresolver"
- "traefik.http.routers.elements.entrypoints=websecure"
restart: on-failure
restart: unless-stopped
environment:
- HOST=$HOST # subdomain e.g. swarmx.sphinx.chat
- DOCKER_RUN=true # client use sphinx-swarm network
Expand Down
2 changes: 1 addition & 1 deletion src/bin/btc_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version: "3"
services:
bitcoind:
image: lncm/bitcoind:v23.0
restart: on-failure
restart: unless-stopped
container_name: bitcoind.test
volumes:
- bitcoind.test:/data/.bitcoin
Expand Down
2 changes: 1 addition & 1 deletion src/bin/super/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct RemoteStack {
pub ec2_instance_id: String,
}

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Default)]
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Default, Clone)]
pub struct AwsInstanceType {
pub name: String,
pub value: String,
Expand Down
7 changes: 6 additions & 1 deletion src/bin/super/superapp/src/Remotes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,15 @@
async function handleSubmitCreateEc2() {
isSubmitting = true;
if (vanity_address) {
`${vanity_address}${domain}`;
}
try {
const data = {
name: `${name}${swarm_name_suffix}`,
vanity_address: `${vanity_address}${domain}`,
vanity_address,
instance_type: selected_instance,
};
Expand Down
2 changes: 1 addition & 1 deletion src/bin/super/superapp/src/ViewNodes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
async function get_current_service_details() {
for (let i = 0; i < $remotes.length; i++) {
const remote = $remotes[i];
if (remote.host === remote.host) {
if (remote.host === $selectedNode) {
node = { ...remote };
try {
const response = await get_swarm_instance_type({
Expand Down
31 changes: 29 additions & 2 deletions src/bin/super/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,21 +577,35 @@ pub async fn create_swarm_ec2(
info: &CreateEc2InstanceInfo,
state: &mut Super,
) -> Result<(), Error> {
let mut actual_vanity_address: Option<String> = None;

let instance_type = get_instance(&info.instance_type);

if instance_type.is_none() {
return Err(anyhow!("Invalid instance type"));
}

if let Some(vanity_address) = &info.vanity_address {
if !vanity_address.is_empty() {
if let Some(subdomain) = vanity_address.strip_suffix(".sphinx.chat") {
if subdomain.is_empty() {
return Err(anyhow!("Provide a valid vanity address"));
}

let domain_status = is_valid_domain(subdomain.to_string());
if !domain_status.is_empty() {
return Err(anyhow!(domain_status));
}
actual_vanity_address = Some(vanity_address.to_string());
} else {
return Err(anyhow!("Vanity Address doesn't match the expected format."));
}
}
}

let ec2_intance = create_ec2_instance(
info.name.clone(),
info.vanity_address.clone(),
actual_vanity_address.clone(),
info.instance_type.clone(),
)
.await?;
Expand All @@ -606,7 +620,7 @@ pub async fn create_swarm_ec2(

let mut host = default_host.clone();

if let Some(custom_domain) = &info.vanity_address {
if let Some(custom_domain) = &actual_vanity_address {
log::info!("vanity address is being set");
if !custom_domain.is_empty() {
host = custom_domain.clone();
Expand Down Expand Up @@ -832,3 +846,16 @@ pub fn get_swarm_instance_type(
data: Some(value),
});
}

fn get_instance(instance_type: &str) -> Option<AwsInstanceType> {
let instance_types = instance_types();
let postion = instance_types
.iter()
.position(|instance| instance.value == instance_type);

if let None = postion {
return None;
}

return Some(instance_types[postion.unwrap()].clone());
}
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn host_config(
extra_hosts: extra_hosts(),
network_mode: Some(dock::DEFAULT_NETWORK.to_string()),
restart_policy: Some(RestartPolicy {
name: Some(RestartPolicyNameEnum::ON_FAILURE),
name: Some(RestartPolicyNameEnum::UNLESS_STOPPED),
maximum_retry_count: None,
}),
log_config: local_log_config(),
Expand Down
4 changes: 2 additions & 2 deletions superadmin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
load_balancer:
image: traefik:v2.2.1
container_name: load_balancer
restart: on-failure
restart: unless-stopped
networks:
- sphinx-swarm
command:
Expand Down Expand Up @@ -61,7 +61,7 @@ services:
- "traefik.http.routers.elements.tls=true"
- "traefik.http.routers.elements.tls.certresolver=myresolver"
- "traefik.http.routers.elements.entrypoints=websecure"
restart: on-failure
restart: unless-stopped
environment:
- DOCKER_RUN=true
- ROCKET_ADDRESS=0.0.0.0
Expand Down

0 comments on commit 629e6bf

Please sign in to comment.