Commit 2cc23006 authored by Fabian Peter's avatar Fabian Peter
Browse files

fix: m

parent f0df0307
Pipeline #201314458 passed with stages
in 6 minutes and 2 seconds
......@@ -28,7 +28,7 @@ RUN mkdir -p /shipmate $SHIPMATE_CARGO_DIR /root/.ssh
COPY requirements.txt .
RUN apt-get update \
&& apt-get install -y --no-install-recommends software-properties-common git \
&& apt-get install -y --no-install-recommends ssh software-properties-common git \
&& curl -sL https://deb.nodesource.com/setup_14.x | bash - \
#&& curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - \
#&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" \
......
......@@ -15,7 +15,7 @@ endif
export DOCKER_BUILDKIT=1
DOCKER_BASE_IMAGE ?= registry.gitlab.com/peter.saarland/ansible-boilerplate:latest
export DOCKER_IMAGE ?= shipmate
DOCKER_SHELLFLAGS ?= run --privileged --rm -it -v ${PWD}:/shipmate -v /var/run/docker.sock:/var/run/docker.sock ${DOCKER_IMAGE}
DOCKER_SHELLFLAGS ?= run --privileged --rm -it -v ${PWD}:/shipmate -v /var/run/docker.sock:/var/run/docker.sock -v ${HOME}/.gitconfig:/root/.gitconfig -v ${HOME}/.ssh:/root/.ssh ${DOCKER_IMAGE}
export GL_TOKEN ?=
ANSIBLE_V ?=
......
......@@ -32,7 +32,10 @@ providers:
path:
name:
base_image: shipmate
host: unix:///var/run/docker.sock
host: unix://var/run/docker.sock
config: Dockerfile
mkdocs:
config: mkdocs.yml
tag:
build_dir:
provider:
......@@ -44,9 +47,22 @@ ci:
stages:
tag:
build:
providers:
docker:
enabled: false
docs:
enabled: false
test:
ship:
docker:
enabled: false
docs:
enabled: false
deploy:
docker:
enabled: false
docs:
enabled: false
destroy:
version_file:
......
......@@ -3,4 +3,5 @@ jmespath
typer[all]
anyconfig
docker
pyyaml
\ No newline at end of file
pyyaml
mkdocs
\ No newline at end of file
......@@ -15,6 +15,19 @@ src = {"cargo_dir": ""}
shipfile = {}
def printDebug(message: str):
if src["debug"]:
typer.secho(
f"{message}", err=False, fg=typer.colors.BRIGHT_BLACK,
)
def printError(message: str):
typer.secho(
f"{message}", err=True, fg=typer.colors.RED,
)
def loadConfig():
shipfile = validateShipfile()
......@@ -49,12 +62,42 @@ def discover():
# Docker Host
docker_host = os.environ.get("DOCKER_HOST")
if docker_host != "":
if docker_host:
discovered["providers"]["docker"]["host"] = docker_host
return discovered
def compileTag():
shipment = loadShipment()
# Initial version is always the commit id
version = shipment["repository"]["commit"]["id"]
try:
with open("VERSION.txt") as f:
version = f.read()
except Exception as e:
if src["debug"]:
typer.secho(
f"{e}", err=False, bold=False, fg=typer.colors.BRIGHT_BLACK,
)
tag = f'{shipment["project"]["name"]}/{shipment["repository"]["branch"]}:{version}'
if src["debug"]:
typer.secho(
f"compiled tag: {tag}", err=False, bold=False, fg=typer.colors.BRIGHT_BLACK,
)
return tag
@app.command()
def tag(provider: str = "git"):
print(compileTag())
def loadShipment():
# 1 load defaults
# 2 enrich with discovery
......@@ -67,12 +110,8 @@ def loadShipment():
)
if shipfile:
print(shipfile)
print(shipment)
anyconfig.merge(shipment, shipfile, ignore_missing=True)
print(shipment)
return shipment
except Exception as e:
typer.secho(
......@@ -167,20 +206,88 @@ def push():
return push
def dockerClient(shipment: dict):
if src["debug"]:
typer.secho(
f"connecting to docker on {shipment['providers']['docker']['host']}",
err=False,
fg=typer.colors.BRIGHT_BLACK,
)
client = docker.APIClient(
base_url=shipment["providers"]["docker"]["host"],
timeout=5,
user_agent="shipmate",
)
if client.ping():
printDebug(f"successfully connected to docker: {client.version()}")
return client
else:
printError(f"error connecting to docker")
return False
def buildDocker(shipment: dict, tag: str):
client = dockerClient(shipment)
build = [
line
for line in client.build(
path=src["cargo_dir"],
tag=tag,
rm=True,
timeout=5,
pull=True,
forcerm=True,
dockerfile="Dockerfile",
buildargs={},
labels={},
cache_from=[],
)
]
build
# build = client.images.build(
# path=".",
# tag=tag,
# rm=True,
# timeout=5,
# pull=True,
# forcerm=True,
# dockerfile="Dockerfile",
# buildargs={},
# labels={},
# cache_from=[],
# )
# return build
@app.command()
def build(
provider: str = typer.Option(
os.environ.get("SHIPMATE_PROVIDER"),
"--provider",
"-p",
help="The build provider",
provider: str = typer.Argument(
os.environ.get("SHIPMATE_PROVIDER", "all"), help="The build provider",
)
):
"""
Build
"""
if not provider:
if src["debug"]:
typer.secho(
f"provider: {provider}", err=False, fg=typer.colors.BRIGHT_BLACK
)
typer.secho(f"no provider given", err=True, fg=typer.colors.RED)
raise typer.Exit(code=1)
tag = compileTag()
shipment = loadShipment()
if provider == "docker":
build = buildDocker(shipment, tag)
@app.command()
def version():
......@@ -530,6 +637,11 @@ def init():
raise typer.Exit(code=1)
@app.command()
def mkdocs(**kwargs):
print("Run mkdocs util")
@app.callback()
def callback(
verbosity: int = typer.Option(0, "--verbosity", "-v", help="Verbosity"),
......@@ -544,6 +656,10 @@ def callback(
src["cargo_dir"] = cargo_dir
src["verbosity"] = verbosity
src["debug"] = debug
os.environ["DOCKER_CLIENT_TIMEOUT"] = "120"
os.environ["COMPOSE_HTTP_TIMEOUT"] = "120"
if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment