Skip to content

Commit

Permalink
feat: gitops better networks handling, deployment id in label, remove…
Browse files Browse the repository at this point in the history
… orphans
  • Loading branch information
lukasvecerka23 committed Apr 5, 2024
1 parent 8760249 commit 8ecda41
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions pre/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"metadata": {},
"outputs": [],
"source": [
"sample_events([{'action': 'deploy-git', \"bitswan_dir\":\"/Users/lukasvecerka/Work/BitSwan/Development/repo/datamachines\"}])"
"sample_events([{'action': 'deploy-git', \"bitswan_dir\":\"/Users/lukasvecerka/Work/BitSwan/Development/repo/datamachines/local\", \"host_base_path\":\"/opt/bitswan-pipelines\"}])"
]
},
{
Expand Down Expand Up @@ -383,13 +383,22 @@
" deployment = deployment_info[deployment_id]\n",
" entry[\"environment\"] = {\"DEPLOYMENT_ID\": deployment_id}\n",
" entry[\"container_name\"] = deployment_id\n",
" entry[\"labels\"] = {\"built.from\": deployment[\"build_commit\"]}\n",
" entry[\"labels\"] = {\n",
" \"built.from\": deployment[\"build_commit\"],\n",
" \"gitops.deployment_id\": deployment_id,\n",
" }\n",
" if \"env-dir\" in bitswan_yaml:\n",
" env_file = os.path.join(bitswan_yaml[\"env-dir\"], deployment_id)\n",
" if os.path.exists(env_file):\n",
" entry[\"env_file\"] = [env_file]\n",
" if \"default-networks\" in bitswan_yaml:\n",
" entry[\"networks\"] = bitswan_yaml[\"default-networks\"].copy()\n",
"\n",
" if \"network_mode\" in conf:\n",
" entry[\"network_mode\"] = conf[\"network_mode\"]\n",
" elif \"networks\" in conf:\n",
" entry[\"networks\"] = conf[\"networks\"].copy()\n",
" elif \"default-networks\" in bitswan_yaml:\n",
" entry[\"networks\"] = bitswan_yaml['default-networks'].copy()\n",
"\n",
" source = conf.get(\"source\", deployment_id)\n",
" data_machine_dir = os.path.join(bitswan_dir, source)\n",
" dockerfile_path = \"Dockerfile\"\n",
Expand All @@ -400,7 +409,7 @@
" \"DATA_MACHINE_SOURCE_PATH\": data_machine_dir.replace(git_repo_root, \".\"),\n",
" }\n",
" }\n",
" passthroughs = [\"volumes\", \"network_mode\", \"ports\", \"restart\", \"devices\", \"container_name\", ]\n",
" passthroughs = [\"volumes\", \"ports\", \"restart\", \"devices\", \"container_name\", ]\n",
" for passthrough in passthroughs:\n",
" if passthrough in conf:\n",
" entry[passthrough] = conf[passthrough]\n",
Expand All @@ -412,7 +421,10 @@
" ide_entry[\"entrypoint\"] = \"/start-ide.sh\"\n",
" ide_entry[\"image\"] = \"dev_\" + deployment_id\n",
" ide_entry[\"volumes\"] = entry.get(\"volumes\", [])\n",
" ide_entry[\"networks\"] = entry[\"networks\"]\n",
" if \"network_mode\" in entry:\n",
" ide_entry[\"network_mode\"] = entry[\"network_mode\"]\n",
" else:\n",
" ide_entry[\"networks\"] = entry[\"networks\"].copy()\n",
" ide_entry[\"volumes\"] += [\n",
" os.path.join(event[\"host_base_path\"],\"dev/\")+\":/mnt\",\n",
" ]\n",
Expand Down Expand Up @@ -465,7 +477,7 @@
" \"returncode\": proc.returncode,\n",
" }\n",
" \n",
" cmd = [\"docker-compose\", \"-f\", \"/dev/stdin\", \"up\", \"-d\"]\n",
" cmd = [\"docker-compose\", \"-f\", \"/dev/stdin\", \"up\", \"-d\", \"--remove-orphans\"]\n",
" cmd.extend(services_to_recreate)\n",
"\n",
" # Create a subprocess with stdin pipe\n",
Expand Down

0 comments on commit 8ecda41

Please sign in to comment.