Remove explicit Docker container names to allow storing multiple in parallel.
This commit is contained in:
parent
0f1bd0ff1a
commit
9da3451ed9
3 changed files with 21 additions and 31 deletions
|
@ -2,6 +2,5 @@ version: '2.3'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
files:
|
files:
|
||||||
container_name: "themotte"
|
|
||||||
build:
|
build:
|
||||||
target: operation
|
target: operation
|
||||||
|
|
|
@ -2,7 +2,6 @@ version: '2.3'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
files:
|
files:
|
||||||
container_name: "themotte"
|
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
target: dev
|
target: dev
|
||||||
|
@ -23,13 +22,11 @@ services:
|
||||||
- postgres
|
- postgres
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
container_name: "themotte_redis"
|
|
||||||
image: redis
|
image: redis
|
||||||
ports:
|
ports:
|
||||||
- "6379:6379"
|
- "6379:6379"
|
||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
container_name: "themotte_postgres"
|
|
||||||
image: postgres:12.3
|
image: postgres:12.3
|
||||||
# command: ["postgres", "-c", "log_statement=all"]
|
# command: ["postgres", "-c", "log_statement=all"]
|
||||||
# uncomment this if u wanna output all SQL queries to the console
|
# uncomment this if u wanna output all SQL queries to the console
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
|
import functools
|
||||||
import pprint
|
import pprint
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
@ -57,28 +58,6 @@ def _docker(command, **kwargs):
|
||||||
] + command,
|
] + command,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
def _status_single(server):
|
|
||||||
command = ['docker', 'container', 'inspect', '-f', '{{.State.Status}}', server]
|
|
||||||
result = _execute(command, check=False).stdout.strip()
|
|
||||||
return result
|
|
||||||
|
|
||||||
# this should really be yanked out of the docker-compose somehow
|
|
||||||
_containers = ["themotte", "themotte_postgres", "themotte_redis"]
|
|
||||||
|
|
||||||
def _all_running():
|
|
||||||
for container in _containers:
|
|
||||||
if _status_single(container) != "running":
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _any_exited():
|
|
||||||
for container in _containers:
|
|
||||||
if _status_single(container) == "exited":
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
def _start():
|
def _start():
|
||||||
print("Starting containers in operation mode . . .")
|
print("Starting containers in operation mode . . .")
|
||||||
print(" If this takes a while, it's probably building the container.")
|
print(" If this takes a while, it's probably building the container.")
|
||||||
|
@ -92,10 +71,26 @@ def _start():
|
||||||
]
|
]
|
||||||
result = _execute(command)
|
result = _execute(command)
|
||||||
|
|
||||||
while not _all_running():
|
# alright this seems sketchy, bear with me
|
||||||
if _any_exited():
|
|
||||||
raise RuntimeError("Server exited prematurely")
|
# previous versions of this code used the '--wait' command-line flag
|
||||||
time.sleep(1)
|
# the problem with --wait is that it waits for the container to be healthy and working
|
||||||
|
# "but wait, isn't that what we want?"
|
||||||
|
# ah, but see, if the container will *never* be healthy and working - say, if there's a flaw causing it to fail on startup - it just waits forever
|
||||||
|
# so that's not actually useful
|
||||||
|
|
||||||
|
# previous versions of this code also had a check to see if the containers started up properly
|
||||||
|
# but this is surprisingly annoying to do if we don't know the containers' names
|
||||||
|
# docker-compose *can* do it, but you either have to use very new features that aren't supported on Ubuntu 22.04, or you have to go through a bunch of parsing pain
|
||||||
|
# and it kind of doesn't seem necessary
|
||||||
|
|
||||||
|
# see, docker-compose in this form *will* wait until it's *attempted* to start each container.
|
||||||
|
# so at this point in execution, either the containers are running, or they're crashed
|
||||||
|
# if they're running, hey, problem solved, we're good
|
||||||
|
# if they're crashed, y'know what, problem still solved! because our next command will fail
|
||||||
|
|
||||||
|
# maybe there's still a race condition? I dunno! Keep an eye on this.
|
||||||
|
# If there is a race condition then you're stuck doing something gnarly with `docker-compose ps`. Good luck!
|
||||||
|
|
||||||
print(" Containers started!")
|
print(" Containers started!")
|
||||||
|
|
||||||
|
@ -106,7 +101,6 @@ def _stop():
|
||||||
command = ['docker-compose','stop']
|
command = ['docker-compose','stop']
|
||||||
print("Stopping containers . . .")
|
print("Stopping containers . . .")
|
||||||
result = _execute(command)
|
result = _execute(command)
|
||||||
time.sleep(1)
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _operation(name, commands):
|
def _operation(name, commands):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue