Compare commits
4 commits
main
...
verbose-er
Author | SHA1 | Date | |
---|---|---|---|
c182505b76 | |||
07cf60ba59 | |||
8cb17dea54 | |||
0a9efe85d2 |
3 changed files with 35 additions and 69 deletions
|
@ -9,44 +9,9 @@ before_script:
|
|||
- export IMAGE_DOCKERHUB_PASSWORD=$DOCKERHUB_PASSWORD
|
||||
|
||||
stages:
|
||||
- lint&test
|
||||
- upload
|
||||
- image
|
||||
|
||||
lint:
|
||||
stage: lint&test
|
||||
script:
|
||||
- pyb lint
|
||||
|
||||
pytest:
|
||||
stage: lint&test
|
||||
script:
|
||||
- pip install -r dev_requirements.txt
|
||||
- pyb test
|
||||
|
||||
pypi-stable:
|
||||
stage: upload
|
||||
rules:
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||
when: never
|
||||
- if: '$CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+\.[0-9]+$/'
|
||||
script:
|
||||
- pyb -P version=$CI_COMMIT_TAG publish upload
|
||||
|
||||
clojure-image-test-publish:
|
||||
stage: image
|
||||
rules:
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||
when: never
|
||||
- if: '$CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+\.[0-9]+$/'
|
||||
script:
|
||||
- cd infrastructure/clojure && pyb image test publish
|
||||
|
||||
devops-build-image-test-publish:
|
||||
stage: image
|
||||
rules:
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||
when: never
|
||||
- if: '$CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+\.[0-9]+$/'
|
||||
script:
|
||||
- cd infrastructure/devops-build && pyb image test publish
|
||||
- cd infrastructure/devops-build && pyb image
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from subprocess import Popen, PIPE, run
|
||||
from subprocess import Popen, PIPE, run, CalledProcessError
|
||||
from pathlib import Path
|
||||
from sys import stdout
|
||||
from os import chmod, environ
|
||||
|
@ -49,55 +49,42 @@ class FileApi:
|
|||
|
||||
|
||||
class ImageApi:
|
||||
def __init__(self):
|
||||
self.execution_api = ExecutionApi()
|
||||
|
||||
def image(self, name: str, path: Path):
|
||||
run(
|
||||
f"docker build -t {name} --file {path}/image/Dockerfile {path}/image",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker build -t {name} --file {path}/image/Dockerfile {path}/image"
|
||||
)
|
||||
|
||||
def drun(self, name: str):
|
||||
run(
|
||||
f'docker run -it --entrypoint="" {name} /bin/bash',
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f'docker run -it --entrypoint="" {name} /bin/bash'
|
||||
)
|
||||
|
||||
def dockerhub_login(self, username: str, password: str):
|
||||
run(
|
||||
f"docker login --username {username} --password {password}",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker login --username {username} --password {password}"
|
||||
)
|
||||
|
||||
def dockerhub_publish(self, name: str, username: str, tag=None):
|
||||
if tag is not None:
|
||||
run(
|
||||
f"docker tag {name} {username}/{name}:{tag}",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker tag {name} {username}/{name}:{tag}"
|
||||
)
|
||||
run(
|
||||
f"docker push {username}/{name}:{tag}",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker push {username}/{name}:{tag}"
|
||||
)
|
||||
run(
|
||||
f"docker tag {name} {username}/{name}:latest",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker tag {name} {username}/{name}:latest"
|
||||
)
|
||||
run(
|
||||
f"docker push {username}/{name}:latest",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker push {username}/{name}:latest"
|
||||
)
|
||||
|
||||
def test(self, name: str, path: Path):
|
||||
run(
|
||||
f"docker build -t {name} -test --file {path}/test/Dockerfile {path}/test",
|
||||
shell=True,
|
||||
check=True,
|
||||
self.execution_api.run_handled(
|
||||
f"docker build -t {name} -test --file {path}/test/Dockerfile {path}/test"
|
||||
)
|
||||
|
||||
|
||||
|
@ -123,6 +110,18 @@ class ExecutionApi:
|
|||
print(line.decode("utf-8"), end="")
|
||||
process.stdout.close()
|
||||
process.wait()
|
||||
|
||||
def run_handled(self, command: str, shell=True, check=True):
|
||||
try:
|
||||
run(
|
||||
command,
|
||||
shell=shell,
|
||||
check=check,
|
||||
capture_output=True,
|
||||
text=True)
|
||||
except CalledProcessError as exc:
|
||||
print("Command failed with code: ", exc.returncode, " and message:", exc.stderr)
|
||||
|
||||
|
||||
|
||||
class EnvironmentApi:
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
from pybuilder.core import Project
|
||||
import logging
|
||||
from subprocess import Popen, PIPE, run
|
||||
from pathlib import Path
|
||||
from src.main.python.ddadevops.domain import (
|
||||
BuildType,
|
||||
|
|
Loading…
Reference in a new issue